class

Pars3k::Parser(T)

Inherits Reference / Object

Parser(T) is a parser with return type T.

Constructors

Class methods

const(value : T)

Parser.const(T) returns a parser that always succeeds with value of type T.

Source

Instance methods

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

Sequences the current parser with another parser given they are the same type.

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
<<(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(T)) : Parser(T)

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.

Source
block
Source
parse(input : String) : T | ParseError

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

Source
sequence

Sequences the current parser with another parser. Expects a block that receives the result of the current parser and returns a new parser of any type, presumably dynamically created.

Source
transform

Transforms the result of the parser such that, when the parser is parsed, 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 Parser(Char).transform { |char| char.to_s }. It is similar to a map method on arrays from other languages.

Source