Module RParsec::Parsers
In: rparsec/parser.rb

This module provides all out-of-box parser implementations.

Methods

alt   among   any   are   arent   char   comment_block   comment_line   eof   failure   get_index   integer   is   isnt   lazy   longer   longest   map   mapn   not_among   not_char   not_string   number   one   range   regexp   satisfies   sequence   set_index   shorter   shortest   str   string   string_nocase   sum   throwp   token   value   watch   watchn   whitespace   whitespaces   word   zero  

Constants

Whitespaces = " \t\r\n"   characters considered white space.

Public Instance methods

A parser that calls alternative parsers until one succeeds.

A parser that succeeds when the the current input is among the given values.

A parser that consumes one input.

A parser that tries to match the current inputs one by one with the given values. It succeeds only when all given values are matched, in which case all the matched inputs are consumed.

A parser that makes sure that the given values don‘t match the current inputs. One input is consumed if it succeeds.

A parser that succeeds when the the current input is the given character.

A parser that parses a chunk of text started with open and ended by close. nil is the result.

A parser that parses a line started with start. nil is the result.

A parser that succeeds when there‘s no input available.

A parser that always fails with the given error message.

A parser that returns the current input index (starting from 0).

A parser that parses an integer and return the matched integer as string.

A parser that succeeds when the the current input is equal to the given value. expected is the error message when pred returns false.

A parser that succeeds when the the current input is not equal to the given value. expected is the error message when pred returns false.

A lazy parser, when executed, calls the given block to get a parser object and delegate the call to this lazily instantiated parser.

longer(*parsers)

Alias for longest

A parser that tries all given alternative parsers and picks the one with the longest match.

A parser that maps current parser result to a new result using the given block.

Different from Parser#map, this method does not need to be combined with any Parser object. It is rather an independent Parser object that maps the current parser result.

parser1.map{|x|…} is equivalent to parser1 >> map{|x|…}

A parser that maps current parser result to a new result using the given block. If the current parser result is an array, the array elements are expanded and then passed as parameters to the block.

Different from Parser#mapn, this method does not need to be combined with any Parser object. It is rather an independent Parser object that maps the current parser result.

parser1.mapn{|x,y|…} is equivalent to parser1 >> mapn{|x,y|…}

A parser that succeeds when the the current input is not among the given values.

A parser that succeeds when the the current input is not the given character.

A parser that makes sure that the current input doesn‘t match a string. One character is consumed if it succeeds.

A parser that parses a number (integer, or decimal number) and return the matched number as string.

A parser that always succeeds.

A parser that succeeds if the current input is within a certain range.

A parser that succeeds if the current inputs match the given regular expression. The matched string is consumed and returned as result.

A parser that succeeds when the given predicate returns true (with the current input as the parameter). expected is the error message when pred returns false.

A parser that sequentially run the given parsers. The result of the last parser is used as return value. If a block is given, the results of the parsers are passed into the block as parameters, and the block return value is used as result instead.

A parser that moves the current input pointer to a certain index.

shorter(*parsers)

Alias for shortest

A parser that tries all given alternative parsers and picks the one with the shortest match.

str(str, msg = "\"

Alias for string

A parser that matches the given string.

A parser that matches the given string, case insensitively.

A parser that calls alternative parsers until one succeed, or any failure with input consumption beyond the current look-ahead.

A parser that throws a symbol.

A parser that succeeds when the current input is a token with one of the the given token kinds. If a block is given, the token text is passed to the block as parameter, and the block return value is used as result. Otherwise, the token object is used as result.

A parser that always succeeds with the given return value.

A parser that watches the current parser result without changing it. The following assert will succeed:

char(?a) >> watch{|x|assert_equal(?a, x)}

watch can also be used as a handy tool to print trace information, for example:

some_parser >> watch {puts "some_parser succeeded."}

A parser that watches the current parser result without changing it. The following assert will succeed:

char(?a).repeat(2) >> watchn{|x,y|assert_equal([?a,?a], [x,y])}

Slightly different from watch, watchn expands the current parser result before passing it into the associated block.

A parser that parses a white space character.

A parser that parses 1 or more white space characters.

A parser that parses a word (starting with alpha or underscore, followed by 0 or more alpha, number or underscore). and return the matched word as string.

A parser that always fails.

[Validate]