class Pars3k::Parser(T)

Overview

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

Defined in:

pars3k.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(&block : ParseContext -> ParseResult(T)) #

[View source]

Class Method Detail

def self.const(value : T) #

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


[View source]

Instance Method Detail

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

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


[View source]
def /(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.


[View source]
def <<(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.


[View source]
def >>(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.


[View source]
def |(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.


[View source]
def block #

[View source]
def parse(input : String) : T | ParseError #

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


[View source]
def sequence(&new_block : T -> Parser(B)) : Parser(B) forall B #

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.


[View source]
def 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. 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.


[View source]