Scala parser combinator libraries collection.
This repository contains the following libraries:
parsers-common
: Common utilities for parser combinator.parsers-contparse
: A parser combinator library with continuation passing style.parsers-funcparse
: A basic functional parser combinator library.parsers-inlineparse
: A faster parser combinator library with mutable state & inline expansion.parsers-stackparse
: A stackless parser combinator library.
P[T]
is parser type, Parsed[T]
is result type, and the following method is parser executor:
def parse[T](input: String, p: P[T]): Parsed[T] = ...
You can create P[T]
by the following primitives, and combinate parsers by the following combinators.
"literal"
: just matches"literal"
.CharIn("abc")
: matches a character contained in"abc"
.CharPred(isXXX)
: matches a character with whichisXXX
returnstrue
.CharsWhileIn("abc")
matches seqence of characters contained in"abc"
.CharsWhile(isXXX)
matches sequence of characters with whichisXXX
returnstrue
.AnyChar
: matches an any character.Start
: only matches at start position.End
: only matches at end position.p.!
: captures a string onp
matching.
P(p)
: same asp
, but it is lazy evaluated (for recursive parsers).Pass
: succeeds with()
value.Pass(v)
: succeeds withv
.Fail
: fails matching.Fail(msg)
: fails matching withmsg
.&?(p)
: matches whenp
is matched, but is does not consume any characters (positive look-ahead).&!(p)
: matches whenp
is not matched, but is does not consume any characters (negative look-ahead).p1 ~ p2
: matchesp1
and then matchesp2
sequentially.p1 ~/ p2
: matchesp1
, cuts backtrack, and then matchesp2
sequentially.p./
: matchesp
and then cuts backtrack.p1 | p2
: matchesp1
, or matchesp2
.p.rep
: repeatsp
matching many times.p.rep(min)
: repeatsp
matchingn
times (min <= n
).p.rep(min, max)
: repeatsp
matchingn
times (min <= n <= max
).p.count(n)
: repeatsp
matchingn
times.p.?
: matchesp
, or succeeds without consuming any characters.p.named(name)
: namesp
for better error message.p.map(f), p.flatMap(f), p.filter(f)
: usual operators.
MIT License.
2020 (C) TSUYUSATO "MakeNowJust" Kitsune