Rerouted (retagged, needs approval). The tag now points at a different commit than when this version was published. The Lamdera package server serves a copy recovered from https://github.com/YuyaAizawa/peg.
What we checked: Tag 1.0.1 is still on github.com/YuyaAizawa/peg; its commit 46ef22be5906 is from 2020-01-15 01:54 UTC, before the version was published (2020-01-19 11:54 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.
We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:
lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.Details · package.elm-lang.org's zip: https://github.com/YuyaAizawa/peg/zipball/1.0.1/
A parser combinator implementation for Parsing Expression Grammer (PEG).
Parse the given string and return the result. It returns Just value when
the string is accepted, Nothing otherwise.
parse "abc" (match "abc") == Just "abc"
parse "xyz" (match "abc") == NothingThis Parser alway succeeds on parse and results in the given argument
without consumption.
Generate the parser accepts the specified string. The parser returns the same string when accepts.
parse "abc" (match "abc") == Just "abc"
parse "xyz" (match "abc") == NothingGenerate the parser accepts characters satisfied with the specified predicator. The parser returns the specified character when accepted.
char Char.isUpper |> parse "A" == Just 'A'
char Char.isUpper |> parse "a" == NothingGenerate the parser accepts consecutive characters satisfied with the specified predicator. The parser returns the string when accepted.
char Char.isUpper |> parse "AAA" == Just "AAA"
char Char.isUpper |> parse "aaa" == NothingConcatenate two specified parsers, in other words, generate new parser accepts the sequence. The result is also merged according to the 3rd parameter.
seq2 (match "con") (match "cat") (++) |> parse "concat" == Just "concat"Generate new parser from specified parsers. result parser accepts all inputs specified parsers accept. This combinator is ordered, in other words, if the first parser accepts input, the second parser is ignored. These parsers needs to be '() -> Parser' form. (It is useful for avoiding infinite reference.)
p =
choice
[ () -> match "foo"
, () -> match "bar"
]
p |> parse "foo" == Just "foo"
p |> parse "bar" == Just "bar"Generate optional parser. It accepts whatever string and consumes only if
specified parser accepts. The parse result is Maybe value.
option (match "foo") |> parse "bar" == Just NothingGenerate zero-or-more parser. It accept zero or more consecutive repetitions of string specified parser accepts. it always behaves greedily, consuming as much input as possible.
p = zeroOrMore (match "a")
p |> parse "aaa" == Just ["a", "a", "a"]
p |> parse "" == Just []Generate one-or-more parser. It accept one or more consecutive repetitions of string specified parser accepts. it always behaves greedily, consuming as much input as possible.
p = oneOrMore (match "a")
p |> parse "aaa" == Just ["a", "a", "a"]
p |> parse "" == NothingGenerate and-predicate parser. The parse succeeds if the specified parser accepts the input and fails if the specified parser rejects, but in either case, never consumes any input.
word = chars (always True)
p = seq2 (andPredicate (match "A")) word (\_ i -> String.toInt i)
p |> parse "Apple" == Just "Apple"
p |> parse "Banana" == NothingGenerate not-predicate parser. The parse succeeds if the specified parser rejects the input and fails if the specified parser accepts, but in either case, never consumes any input.
nums = chars Char.isNum
p = seq2 (notPredicate (match "0")) nums (\_ i -> String.toInt i)
p |> parse "1234" == Just 1234
p |> parse "0123" == NothingGenerate new parser return mapped result by specifying mapper.
Incorporate specified parser to the parser. It re-parse the input using specified parser with the original result when the original parser success parse, otherwise the parse failed. Using it can set more stringent conditions for parse success.
intParser =
chars Char.isDigit
|> flatMap (\str ->
case String.toInt str of
Just i -> return i
Nothing -> fail)Concatenate two parsers with a specified parser in between.
ws = match " " |> oneOrMore
varTy = choise [ () -> match "int", () -> match "char" ]
varName = char Char.alpha |> oneOrMore
varDecl =
intersperseSeq2
ws varTy varName -- matches like "int x" or "char foo"
(\ty name -> ( ty, name )) -- result like ("int", "x") or ("char", "foo")
A value decides wether the given input string should be accepted or not and converts it into Elm object when accepted.