Class: Rattler::Runtime::ExtendedPackratParser
- Inherits:
-
PackratParser
- Object
- Util::Node
- Parser
- RecursiveDescentParser
- PackratParser
- Rattler::Runtime::ExtendedPackratParser
- Defined in:
- lib/rattler/runtime/extended_packrat_parser.rb
Overview
ExtendedPackratParser
implements the algorithm described by Alessandro Warth, James R. Douglass, and Todd Millstein for extending packrat parsing to support left-recursive grammars.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Parser
Instance Method Summary collapse
-
#apply(match_method_name) ⇒ Object
Apply a rule by dispatching to the given match method.
-
#initialize(source, options = {}) ⇒ ExtendedPackratParser
constructor
Create a new extended packrat parser to parse
source
.
Methods inherited from RecursiveDescentParser
#match, #method_missing, #respond_to?
Methods included from ParserHelper
Methods inherited from 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, options = {}) ⇒ ExtendedPackratParser
Create a new extended packrat parser to parse source
.
15 16 17 18 19 |
# File 'lib/rattler/runtime/extended_packrat_parser.rb', line 15 def initialize(source, ={}) super @heads = {} @lr_stack = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rattler::Runtime::RecursiveDescentParser
Instance Method Details
#apply(match_method_name) ⇒ Object
Apply a rule by dispatching to the given match method. The result of applying the rule is memoized so that the match method is invoked at most once at a given parse position.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rattler/runtime/extended_packrat_parser.rb', line 28 def apply(match_method_name) start_pos = @scanner.pos if m = memo_lr(match_method_name, start_pos) recall m, match_method_name else lr = LR.new(false, match_method_name, nil) @lr_stack.push lr m = inject_memo match_method_name, start_pos, lr, start_pos result = eval_rule match_method_name @lr_stack.pop if lr.head m.end_pos = @scanner.pos lr.seed = result lr_answer match_method_name, start_pos, m else save m, result end end end |