Class RParsec::Parser
In: rparsec/parser.rb
Parent: Object

Represents a parser that parses a certain grammar rule.

Methods

*   <<   >>   atomize   bindn   catchp   delimited   delimited1   expect   followed   fragment   infixl   infixn   infixr   lexeme   lookahead   many   many_   map   mapn   nested   new   not   optional   parse   peek   postfix   prefix   repeat   repeat_   separated   separated1   seq   setName   some   some_   to_s   token   |   ~  

Included Modules

Functors Monad

Constants

MyMonad = ParserMonad.new

Attributes

name  [RW] 

Public Class methods

Public Instance methods

*(min, max=min)

Alias for repeat_

<<(other)

Alias for followed

Similar to seq. other is auto-boxed if it is not of type Parser.

Create a new parser that‘s atomic., meaning that when it fails, input consumption is undone.

self is first executed, the parser result is then passed as parameter to the associated block, which evaluates to another Parser object at runtime. This new Parser object is then executed to get the final parser result.

Different from bind, parser result of self will be expanded first if it is an array.

a.catchp(:somesymbol) will catch the :somesymbol thrown by a.

To create a parser that repeats self for unlimited times, with the pattern recognized by delim as separator that separates each occurrence and also possibly ends the pattern. Return values of self are collected in an array.

To create a parser that repeats self for unlimited times, with the pattern recognized by delim as separator that separates each occurrence and also possibly ends the pattern. self has to match for at least once. Return values of self are collected in an array.

To create a parser that fails with a given error message.

a.followed b will sequentially run a and b; result of a is preserved as the ultimate return value.

a.fragment will return the string matched by a.

For left-associative infix binary operator. op has to return a Proc that takes two parameters, who are returned by the self parser as operands.

For non-associative infix binary operator. op has to return a Proc that takes two parameters, who are returned by the self parser as operands.

For right-associative infix binary operator. op has to return a Proc that takes two parameters, who are returned by the self parser as operands.

a.lexeme(delim) will parse a for 0 or more times and ignore all patterns recognized by delim. Values returned by a are collected in an array.

To create a parser that does "look ahead" for n inputs.

To create a parser that repeats self for at least least times. All return values are collected in an array.

To create a parser that repeats self for at least least times. parser.many_ is equivalent to bnf notation "parser*". Only the return value of the last execution is preserved.

a.map{|x|x+1} will first execute parser a, when it succeeds, the associated block is executed to transform the result to a new value (increment it in this case).

a.mapn{|x,y|x+y} will first execute parser a, when it succeeds, the array result (if any) is expanded and passed as parameters to the associated block. The result of the block is then used as the parsing result.

a.nested b will feed the token array returned by parser a to parser b for a nested parsing.

To create a new parser that succeed only if self fails.

a.optional(default) is equivalent to a.plus(value(default))

parses a string.

Create a new parser that looks at inputs whthout consuming them.

For postfix unary operator. a.postfix op will run parser a for once and then op for 0 or more times. op should return a Proc that accepts one parameter. Proc objects returned by op is then fed with the value returned by a from left to right. The final result is returned as return value.

For prefix unary operator. a.prefix op will run parser op for 0 or more times and eventually run parser a for one time. op should return a Proc that accepts one parameter. Proc objects returned by op is then fed with the value returned by a from right to left. The final result is returned as return value.

To create a parser that repeats self for a minimum min times, and maximally max times. All return values are collected in an array.

To create a parser that repeats self for a minimum min times, and maximally max times. Only the return value of the last execution is preserved.

To create a parser that repeats self for unlimited times, with the pattern recognized by delim as separator that separates each occurrence. Return values of self are collected in an array.

To create a parser that repeats self for unlimited times, with the pattern recognized by delim as separator that separates each occurrence. self has to match for at least once. Return values of self are collected in an array.

a.seq b will sequentially run a then b. The result of b is preserved as return value. If a block is associated, values returned by a and b are passed into the block and the return value of the block is used as the final result of the parser.

Set name for the parser. self is returned.

To create a parser that repeats self for at most max times. All return values are collected in an array.

To create a parser that repeats self for at most max times. Only the return value of the last execution is preserved.

String representation

a.token(:word_token) will return a Token object when a succeeds. The matched string (or the string returned by a, if any) is encapsulated in the token, together with the :word_token symbol and the starting index of the match.

a | b will run b when a fails. b is auto-boxed to Parser when it is not of type Parser.

~(msg="

Alias for not

[Validate]