struct

Pars::Parser(T)

Inherits Struct / Value / Object

Constructors

Class methods

byte

Creates a Parser that consumes the parse head, or fails if the end of input has been reached.

Source
char

Creates a Parser that consumes the parse head, or fails if the end of input has been reached.

Source
const(value : T)

Creates a Parser that always succeeds with value.

Source
fail(message : String)

Creates a Parser that always fails with message.

Source
head

Creates a Parser that consumes the parse head, or fails if the end of input has been reached.

Source

Instance methods

&(other : Parser(B)) : Parser(Tuple(T, B)) forall B

Given A & B, creates a parser that succeeds when both A and B succeed for the same input, returning the results as a Tuple.

Source
&+(other : Parser(B)) forall B

Sequences self with other, providing a new Parser that returns the results as a Tuple.

If multiple parsers are chained, the results are flattened.

Source
*(count : Int) : Parser(Array(T))

Creates a new parser that repeats self exactly count times.

Source
*(range : Range(Int, Int) | Range(Int, Nil)) : Parser(Array(T))

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.

Source
+(other : Parser(B)) forall B

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.

Source
<<(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.

Source
>>(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.

Source
^(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.

If both succeed, the parser will fail.

Source
|(other : Parser(B)) : Parser(T | B) forall B

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.

Source
|(message : String) : Parser(T)

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.

Source
bind

Sequences self with another parser.

Expects a block that receives the result of the current parser and returns a new parser of any type.

Source
map

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.

Source
parse(input) : T | ParseError

Parses the input string input given the parser's logic provided by its block at definition.

Source
run(context : ParseContext) : ParseResult(T)

Runs self for a given context.

Source