class Pars::Parser(T)
- Pars::Parser(T)
- Reference
- Object
Defined in:
pars/parser.crConstructors
Class Method Summary
-
.byte
Creates a
Parserthat consumes the parse head, or fails if the end of input has been reached. -
.char
Creates a
Parserthat consumes the parse head, or fails if the end of input has been reached. -
.const(value : T)
Creates a
Parserthat always succeeds with value. -
.fail(message : String)
Creates a
Parserthat always fails with message. -
.head
Creates a
Parserthat consumes the parse head, or fails if the end of input has been reached.
Instance Method Summary
-
#&(other : Parser(B)) : Parser(B) forall B
Given
A & B, creates a parser that succeeds when both A and B succeed for the same input. -
#*(count : Int) : Parser(Array(T))
Creates a new parser that repeats
selfexactly count times. -
#*(range : Range(Int, Int) | Range(Int, Nil)) : Parser(Array(T))
Creates a new parser that repeats
selfcontinuously up to range.end times. -
#+(other : Parser(B)) forall B
Sequences
selfwith other, providing a new Parser that returns the results as a Tuple. -
#<<(other : Parser(B)) : Parser(T) forall B
Sequences the current parser with another parser, and disregards the other parser's result, but ensures the two succeed.
-
#>>(other : Parser(B)) : Parser(B) forall B
Sequences the current parser with another parser, and disregards the original parser's result, but ensures the two succeed.
-
#^(other : Parser(B)) : Parser(T | B) forall B
Given
A ^ B, creates a parser that succeeds if A or B succeed exclusively for the same input. -
#|(other : Parser(T)) : Parser(T)
Given
A | B, creates a new parser that succeeds when A succeeds or B succeeds. -
#|(other : Parser(B)) : Parser(T | B) forall B
Given
A | B, creates a new parser that succeeds when A succeeds or B succeeds. -
#|(message : String) : Parser(T)
Creates a new
Parser(T)that fails with message ifselfis unsuccessful. -
#bind(&block : T -> Parser(B)) : Parser(B) forall B
Sequences
selfwith another parser. -
#map(&block : T -> B) : Parser(B) forall B
Transforms the result of the parser such that, when the parser runs, the output value becomes a different value.
-
#parse(input) : T | ParseError
Parses the input string
inputgiven the parser's logic provided by its block at definition. -
#run(context : ParseContext) : ParseResult(T)
Runs
selffor a given context.
Constructor Detail
Class Method Detail
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 Method Detail
Given A & B, creates a parser that succeeds when both A and B succeed
for the same input.
Creates a new parser that repeats self exactly count times.
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 a Tuple.
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.
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.