Module: OOPeg::Parser::ClassMethods

Includes:
Combinators
Included in:
OOPeg::Parser
Defined in:
lib/oo_peg/parser/class_methods.rb

Instance Method Summary collapse

Methods included from Combinators

#_maybe, #_sequence

Instance Method Details

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



10
11
12
# File 'lib/oo_peg/parser/class_methods.rb', line 10

def and(*parsers, name: nil)
  _sequence(*parsers, name:)
end

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



14
15
16
# File 'lib/oo_peg/parser/class_methods.rb', line 14

def or(*parsers, name: nil)
  _select(*parsers, name:)
end

#parse(parser, input) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oo_peg/parser/class_methods.rb', line 19

def parse(parser, input)
  raise ArgumentError, "parser must be an instance of #{self}" unless self === parser
  case input
  when String
    parser.parse(OOPeg::Input.new(input.grapheme_clusters))
  when OOPeg::Input
    parser.parse(input)
  else
    raise ArgumentError, "input must be a string or instance of Input" unless self.class === parser
  end
end