Class: OOPeg::Parser

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods, Combinators::Lazy
Includes:
Combinators
Defined in:
lib/oo_peg/parser.rb,
lib/oo_peg/parser/combinators.rb,
lib/oo_peg/parser/class_methods.rb,
lib/oo_peg/parser/combinators/lazy.rb,
lib/oo_peg/parser/combinators/basics.rb,
lib/oo_peg/parser/combinators/mappers.rb,
lib/oo_peg/parser/combinators/repeaters.rb,
lib/oo_peg/parser/combinators/selectors.rb,
lib/oo_peg/parser/combinators/satisfiers.rb

Overview

This class represents a, well, parser

It exposes a class method parse which takes an input or a string (making it to an instance of OOPeg::Input if necessary) and returns a OOPeg::Result

It also exposes an homonymous instance method which must be called with an instance of OOPeg::Input

# example: the parse methods

expect(OOPeg::Parser.parse(end_parser, "")).to be_a OOPeg::Result

# but for efficeny there is no check or conversion in the instance
# method

expect { end_parser.parse("") }
  .to raise_error(NoMethodError, "undefined method 'content' for an instance of String")

Defined Under Namespace

Modules: ClassMethods, Combinators Classes: InfiniteLoop

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Combinators::Lazy

delay

Methods included from Combinators

#_maybe, #_sequence

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



35
36
37
# File 'lib/oo_peg/parser.rb', line 35

def name
  @name
end

Instance Method Details

#and(*parsers, name: nil) ⇒ Object

Combinators



42
# File 'lib/oo_peg/parser.rb', line 42

def and(*parsers, name: nil) = _sequence([self, *parsers], name:)

#debug(name: nil) ⇒ Object



44
# File 'lib/oo_peg/parser.rb', line 44

def debug(name: nil) = _debug(self, name:)

#ignoreObject



46
# File 'lib/oo_peg/parser.rb', line 46

def ignore = self.map { nil }

#join_list(name: nil) ⇒ Object



48
# File 'lib/oo_peg/parser.rb', line 48

def join_list(name: nil) = _join_list(parser: self, name:)

#joined(joiner: "") ⇒ Object



49
# File 'lib/oo_peg/parser.rb', line 49

def joined(joiner: "") = self.map { |ast| ast.join(joiner) }

#lookahead(name: nil) ⇒ Object



51
# File 'lib/oo_peg/parser.rb', line 51

def lookahead(name: nil) = _lookahead(self, name:)

#many(name: nil, max: nil, min: 0, &blk) ⇒ Object



53
# File 'lib/oo_peg/parser.rb', line 53

def many(name: nil, max: nil, min: 0, &blk) = _many(self, name:, max:, min:, &blk)

#map(name: nil, &blk) ⇒ Object



54
# File 'lib/oo_peg/parser.rb', line 54

def map(name: nil, &blk) = _map(parser: self, name:, &blk)

#map_many(name: nil, &blk) ⇒ Object



55
# File 'lib/oo_peg/parser.rb', line 55

def map_many(name: nil, &blk) = _map_many(parser: self, name:, &blk)

#map_or_rename(name: nil, error: nil, &blk) ⇒ Object



56
# File 'lib/oo_peg/parser.rb', line 56

def map_or_rename(name: nil, error: nil, &blk) = _map_or_rename(parser: self, name:, error:, &blk)

#maybe(name: nil, replace_with: nil) ⇒ Object



57
# File 'lib/oo_peg/parser.rb', line 57

def maybe(name: nil, replace_with: nil) = _maybe(parser: self, name:, replace_with:)

#not(name: nil) ⇒ Object



59
# File 'lib/oo_peg/parser.rb', line 59

def not(name: nil) = _not(parser: self, name:)

#or(*parsers, name: nil) ⇒ Object



61
# File 'lib/oo_peg/parser.rb', line 61

def or(*parsers, name: nil) = _select(self, *parsers, name:)

#parse(input) ⇒ Object



38
# File 'lib/oo_peg/parser.rb', line 38

def parse(input) = @parse_fn.(input)

#satisfy(name: nil, &satisfier) ⇒ Object



63
# File 'lib/oo_peg/parser.rb', line 63

def satisfy(name: nil, &satisfier) = _satisfy(self, name:, &satisfier)

#tagged(tag, name: nil) ⇒ Object



65
# File 'lib/oo_peg/parser.rb', line 65

def tagged(tag, name: nil) = _tagged(tag, parser: self, name:)