Pars::Parser(T)
Inherits Struct / Value / Object
Constructors
Class methods
Creates a Parser that consumes the parse head, or fails if the end of
input has been reached.
Creates a Parser that consumes the parse head, or fails if the end of
input has been reached.
Creates a Parser that consumes the parse head, or fails if the end of
input has been reached.
Instance methods
Given A & B, creates a parser that succeeds when both A and B succeed
for the same input, returning the results as a Tuple.
Sequences self with other, providing a new Parser that returns the
results as a Tuple.
If multiple parsers are chained, the results are flattened.
Creates a new parser that repeats self continuously up to range.end
times. If range is not bounded it will continue to repeat until failing.
Sequences self with other, providing a new Parser that returns the
results as an Array.
This may be preferred in place of Parser(T)#.&+ when building parsers
that enumerate or reduce over a structure of unknown size, such as when
working within an Iterator.
If multiple parsers are chained, the results are flattened.
Sequences the current parser with another parser, and disregards the other parser's result, but ensures the two succeed.
Sequences the current parser with another parser, and disregards the original parser's result, but ensures the two succeed.
Given A ^ B, creates a parser that succeeds if A or B succeed
exclusively for the same input.
If both succeed, the parser will fail.
Given A | B, creates a new parser that succeeds when A succeeds or B
succeeds. Checks A first, doesn't check B if A succeeds. Ignores type
differences, gives union type.
Creates a new Parser(T) that fails with message if self is
unsuccessful.
This can be used to provide a custom error message when chaining parsers.
Sequences self with another parser.
Expects a block that receives the result of the current parser and returns a new parser of any type.
Transforms the result of the parser such that, when the parser runs, the output value becomes a different value.
For example, if you took a Parser(Char) and wanted to transform it to a
Parser(String) by Char#to_s, then you could use
char_parser.transform &.to_s.
Parses the input string input given the parser's logic provided by its
block at definition.