class Rattler::Parsers::Parser

Parser is the base class for all of Rattler’s combinator parser types.

Public Instance Methods

&(other) click to toggle source

@param [Parser] other the next parser to try if this parser succeeds. @return [Sequence] a new parser that tries both this parser and other

and fails unless both parse in sequence
# File lib/rattler/parsers/parser.rb, line 62
def &(other)
  Sequence[self, other]
end
>>(semantic) click to toggle source

@param [Parser] semantic a semantic action. @return [AttributedSequence] a new parser that tries this parser and

returns the result of the semantic action if it succeeds
# File lib/rattler/parsers/parser.rb, line 69
def >>(semantic)
  AttributedSequence[self, semantic]
end
capturing?() click to toggle source

@return true if the parser returns parse results on success, or false

if the parser simply returns +true+ on success
# File lib/rattler/parsers/parser.rb, line 17
def capturing?
  true
end
capturing_decidable?() click to toggle source

@return true if it can be determined statically whether the parser

returns parse results on success
# File lib/rattler/parsers/parser.rb, line 29
def capturing_decidable?
  true
end
labeled?() click to toggle source

true if the parser associates a label with parse results. Only instances of Label should return true.

@return true if the parser associates a label with parse

results
# File lib/rattler/parsers/parser.rb, line 38
def labeled?
  false
end
list(sep_parser, lower_bound, upper_bound) click to toggle source

@param [Parser] sep_parser the parser for matching the list separator @param [Integer] lower_bound the minimum number of times to match @param [Integer] upper_bound the maximum number of times to match @return [Repeat] a new parser that matches lists with this parser

# File lib/rattler/parsers/parser.rb, line 103
def list(sep_parser, lower_bound, upper_bound)
  ListParser[self, sep_parser, lower_bound, upper_bound]
end
one_or_more() click to toggle source

@return [Repeat] a new parser that tries this parser until it fails

and returns all of the results if it succeeded at least once and fails
otherwise
# File lib/rattler/parsers/parser.rb, line 95
def one_or_more
  repeat(1, nil)
end
optional() click to toggle source

@return [Repeat] a new parser that tries this parser but returns true

if it fails
# File lib/rattler/parsers/parser.rb, line 82
def optional
  repeat(0, 1)
end
repeat(lower_bound, upper_bound) click to toggle source

@param [Integer] lower_bound the minimum number of times to match @param [Integer] upper_bound the maximum number of times to match @return [Repeat] a new parser that tries this parser repeatedly

# File lib/rattler/parsers/parser.rb, line 76
def repeat(lower_bound, upper_bound)
  Repeat[self, lower_bound, upper_bound]
end
semantic?() click to toggle source

@return true if the parser is a semantic action

# File lib/rattler/parsers/parser.rb, line 48
def semantic?
  false
end
sequence?() click to toggle source

@return true if the parser is a sequence

# File lib/rattler/parsers/parser.rb, line 43
def sequence?
  false
end
skip() click to toggle source

@return [Skip] a new parser that skips over what this parser matches

# File lib/rattler/parsers/parser.rb, line 108
def skip
  Skip[self]
end
variable_capture_count?() click to toggle source

@return true if the number of parse results returned by the parser

varies based on the input
# File lib/rattler/parsers/parser.rb, line 23
def variable_capture_count?
  false
end
with_ws(ws) click to toggle source

@param [Parser] ws the parser used to skip whitespace @return [Parser] a new parser that uses ws to skip whitespace

# File lib/rattler/parsers/parser.rb, line 114
def with_ws(ws)
  self
end
zero_or_more() click to toggle source

@return [Repeat] a new parser that tries this parser until it fails

and returns all of the results
# File lib/rattler/parsers/parser.rb, line 88
def zero_or_more
  repeat(0, nil)
end
|(other) click to toggle source

@param [Parser] other the parser to try if this parser fails. @return [Choice] a new parser that tries this parser first and if it

fails tries +other+
# File lib/rattler/parsers/parser.rb, line 55
def |(other)
  Choice[self, other]
end