install.packages('Ramble')
identifier
creates an identifieralt
combinator is similar to alternation in BNF. the parser
(alt(p1, p2))
recognises anything that p1
or p2
would.
The approach taken in this parser follows (Fairbairn86), in which either is
interpretted in a sequential (or exclusive) manner, returning the result of
the first parser to succeed, and failure if neither does.%using%
is the infix operator for using%thentree%
is the infix operator for the then combinator, and it is
the preferred way to use the thentree
operator.ident
is a parser which matches zero or more alphanumeric
characters.%alt%
is the infix notation for the alt
function.%then%
is the infix operator for the then combinator.satisfy
is a function which allows us to make parsers that recognise single symbols.natural
creates a token parser for natural numberssome
matches 1 or more of pattern p
. in BNF notation, repetition occurs often enough to merit its own abbreviation. When zero or
more repetitions of a phrase p
are admissible, we simply write
p+
. The some
combinator corresponds directly to this operator,
and is defined in much the same way.maybe
matches 0 or 1 of pattern p
. In EBNF notation, this
corresponds to a question mark ('?').many
matches 0 or more of pattern p
. In BNF notation,
repetition occurs often enough to merit its own abbreviation. When zero or
more repetitions of a phrase p
are admissible, we simply write
p*
. The many
combinator corresponds directly to this operator,
and is defined in much the same way.nat
is a parser which matches one or more numeric characters.item
is a parser that consumes the first character of the string and
returns the rest. If it cannot consume a single character from the string, it
will emit the empty list, indicating the parser has failed.literal
is a parser for single symbols. It will attempt to match the
single symbol with the first character in the string.succeed
is based on the empty string symbol in the BNF notation The
succeed
parser always succeeds, without actually consuming any input
string. Since the outcome of succeed does not depend on its input, its result
value must be pre-detemined, so it is included as an extra parameter.String
is a combinator which allows us to build parsers which
recognise strings of symbols, rather than just single symbolssymbol
creates a token for a symbolspace
matches zero or more space characters.then
combinator corresponds to sequencing in BNF. The parser
(then(p1, p2))
recognises anything that p1
and p2
would
if placed in succession.thentree
keeps the full tree representation of the results of parsing.
Otherwise, it is identical to then
.token
is a new primitive that ignores any space before and after
applying a parser to a token.using
combinator allows us to manipulate results from a parser, for
example building a parse tree. The parser (p %using% f)
has the same
behaviour as the parser p
, except that the function f
is
applied to each of its result values.