the type of input elements the provided parsers consume (When consuming invidual characters, a parser is typically
called a scanner, which produces
tokens that are consumed by what is normally called a
parser.
Nonetheless, the same principles apply, regardless of the input type.)
The fatal failure case of ParseResult: contains an error-message and the remaining input.
The failure case of ParseResult: contains an error-message and the remaining input.
The parser input is an abstract reader of input elements, i.
A common super-class for unsuccessful parse results
A parser whose ~ combinator disallows back-tracking.
A base class for parser results.
The root class of parsers.
The success case of ParseResult: contains the result and the remaining input.
An extractor so NoSuccess(msg, next) can be used in matches.
The parser that matches an element in the domain of the partial function f'
If
f' is defined on the first element in the input, f' is applied to it to produce
this parser's result.
Example: The parser <code>accept("name", {case Identifier(n) => Name(n)})</code>
accepts an <code>Identifier(n)</code> and returns a <code>Name(n)</code>.
A parser that matches only the given list of element es'
accept(es) succeeds if the input subsequently provides the elements in the list
es'.
A parser that matches only the given element e'
The method is implicit so that elements can automatically be lifted to their parsers.
For example, when parsing
Token's, Identifier("new") (which is a Token') can be used directly,
instead of first creating a
Parser' using accept(Identifier("new")).
A parser generator that, roughly, generalises the rep1sep generator so that q', which parses the separator,
produces a left-associative function that combines the elements it separates.
A parser generator that, roughly, generalises the rep1sep generator so that q', which parses the separator,
produces a left-associative function that combines the elements it separates.
From: J. Fokker. Functional parsers. In J. Jeuring and E. Meijer, editors, Advanced Functional Programming, volume 925 of Lecture Notes in Computer Science, pages 1--23. Springer, 1995.
A parser generator that generalises the rep1sep generator so that q', which parses the separator,
produces a right-associative function that combines the elements it separates. Additionally,
The right-most (last) element and the left-most combining function have to be supplied.
rep1sep(p: Parser[T], q) corresponds to chainr1(p, q ^^ cons, cons, Nil) (where val cons = (x: T, y: List[T]) => x :: y)
Wrap a parser so that its failures become errors (the | combinator will give up as soon as it encounters an error, on failure it simply tries the next alternative)
A parser that matches only the given element e'
elem(e) succeeds if the input starts with an element
e'
A parser matching input elements that satisfy a given predicate
A parser that results in an error
A parser that always fails
A parser generator for guard expressions.
Wrap a parser so that its failures&errors become success and vice versa -- it never consumes any input
A parser generator for optional sub-phrases.
A parser generator delimiting whole phrases (i.
positioned' decorates a parser's result with the start position of the input it consumed.
A parser generator for repetitions.
A parser generator for non-empty repetitions.
A parser generator for non-empty repetitions.
A parser generator for non-empty repetitions.
A parser generator for a specified number of repetitions.
A parser generator for interleaved repetitions.
A parser that always succeeds
Parsers
is a component that provides generic parser combinators.It requires the type of the elements these parsers should parse (each parser is polymorphic in the type of result it produces).
There are two aspects to the result of a parser: (1) success or failure, and (2) the result. A
Parser[T]
provides both kinds of information.The term
parser combinator refers to the fact that these parsers are constructed from primitive parsers and composition operators, such as sequencing, alternation, optionality, repetition, lifting, and so on.
A
primitive parser is a parser that accepts or rejects a single piece of input, based on a certain criterion, such as whether the input...
Even more primitive parsers always produce the same result, irrespective of the input.
authors:
Martin Odersky, Iulian Dragos, Adriaan Moors