class Pars3k::Parser(T)
- Pars3k::Parser(T)
- Reference
- Object
Overview
Parser(T) is a parser with return type T.
Defined in:
pars3k.crConstructors
Class Method Summary
-
.const(value : T)
Parser.const(T) returns a parser that always succeeds with value of type T.
Instance Method Summary
-
#+(other : Parser(B)) : Parser(B) forall B
Sequences the current parser with another parser given they are the same type.
-
#/(other : Parser(B)) : Parser(T | B) forall B
Given
A / B
, creates a new parser that succeeds when A succeeds or B succeeds. -
#<<(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(T)) : Parser(T)
Given
A | B
, creates a new parser that succeeds when A succeeds or B succeeds. - #block
-
#parse(input : String) : T | ParseError
Parses the input string
input
given the parser's logic provided by its block at definition. -
#sequence(&new_block : T -> Parser(B)) : Parser(B) forall B
Sequences the current parser with another parser.
-
#transform(&new_block : T -> B) : Parser(B) forall B
Transforms the result of the parser such that, when the parser is parsed, the output value becomes a different value.
Constructor Detail
Class Method Detail
Parser.const(T) returns a parser that always succeeds with value of type T.
Instance Method Detail
Sequences the current parser with another parser given they are the same type.
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.
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 new parser that succeeds when
A succeeds or B succeeds. Checks A first, doesn't check B
if A succeeds.
Parses the input string input
given the parser's logic provided
by its block at definition.
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.
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.