A parser combinator implementation for Parsing Expression Grammar (PEG).
- Make base parser.
- Combine parsers.
- Use
parse
function to get result.
-- 1. Make base parser.
numbers =
chars Char.isDigit
minus =
match "-"
|> option
|> map (Maybe.withDefault "")
-- 2. Combine parsers.
intParser =
seq2
minus numbers
(\minusStr numberStr -> minusStr ++ numberStr)
|> flatMap (\str ->
case String.toInt str of
Just i -> return i
Nothing -> fail)
-- 3. Use `parse` function to get result.
result =
intParser |> parse "42" -- Just 42
This is Json parser example imlpemented with reference to json.org.
We will present mini-C parser example. COMING SOON!
BSD-3-Clause. see LISENCE file.