Class: Rattler::Parsers::CombinatorParser
- Inherits:
-
Runtime::Parser
- Object
- Util::Node
- Runtime::Parser
- Rattler::Parsers::CombinatorParser
- Defined in:
- lib/rattler/parsers/combinator_parser.rb
Overview
CombinatorParser
is a runtime parser that parses using the parse rules directly instead of using match methods generated from the parse rules
Instance Attribute Summary
Attributes inherited from Runtime::Parser
Class Method Summary collapse
-
.as_class(start_rule, rule_set) ⇒ Class
A subclass of
CombinatorParser
that uses the given start rule and rule set and can be instantiated with only a source.
Instance Method Summary collapse
-
#__parse__ ⇒ Object
Parse by matching the rule returned by
#start_rule
or:start
if#start_rule
is not defined. -
#initialize(source, start_rule, rule_set) ⇒ CombinatorParser
constructor
Create a new
CombinatorParser
to parsesource
usingrule_set
and starting withstart_rule
.
Methods inherited from Runtime::Parser
#fail, #fail!, #fail_parse, #failure, #failure?, #parse, #parse!, parse!, #parse_fully, #parse_fully!, parse_fully!, #pos, #pos=
Methods inherited from Util::Node
#==, #[], [], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #inspect, #method_missing, #name, #pretty_print, #pretty_print_cycle, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children
Constructor Details
#initialize(source, start_rule, rule_set) ⇒ CombinatorParser
Create a new CombinatorParser
to parse source
using rule_set
and starting with start_rule
28 29 30 31 32 |
# File 'lib/rattler/parsers/combinator_parser.rb', line 28 def initialize(source, start_rule, rule_set) super source @start_rule = start_rule @rule_set = rule_set end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rattler::Util::Node
Class Method Details
.as_class(start_rule, rule_set) ⇒ Class
Returns a subclass of CombinatorParser
that uses the given start rule and rule set and can be instantiated with only a source.
14 15 16 17 18 19 20 |
# File 'lib/rattler/parsers/combinator_parser.rb', line 14 def self.as_class(start_rule, rule_set) new_class = Class.new(self) new_class.send :define_method, :initialize do |source| super source, start_rule, rule_set end new_class end |
Instance Method Details
#__parse__ ⇒ Object
Parse by matching the rule returned by #start_rule
or :start
if #start_rule
is not defined.
35 36 37 |
# File 'lib/rattler/parsers/combinator_parser.rb', line 35 def __parse__ @start_rule.parse(@scanner, @rule_set) end |