Class: Parslet::Atoms::Rule::Position
- Inherits:
-
Struct
- Object
- Struct
- Parslet::Atoms::Rule::Position
- Includes:
- Context
- Defined in:
- lib/parslet/atoms/rule/position.rb
Overview
Update/fetch parsed entry at a given position in source Eval rule body at a given position in source and cache the result
Defined Under Namespace
Modules: Context Classes: LR, MemoEntry
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#rule ⇒ Object
Returns the value of attribute rule.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
Methods included from Context
#entry, #entry=, #head, #head=, #lr_stack
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context
3 4 5 |
# File 'lib/parslet/atoms/rule/position.rb', line 3 def context @context end |
#pos ⇒ Object
Returns the value of attribute pos
3 4 5 |
# File 'lib/parslet/atoms/rule/position.rb', line 3 def pos @pos end |
#rule ⇒ Object
Returns the value of attribute rule
3 4 5 |
# File 'lib/parslet/atoms/rule/position.rb', line 3 def rule @rule end |
#source ⇒ Object
Returns the value of attribute source
3 4 5 |
# File 'lib/parslet/atoms/rule/position.rb', line 3 def source @source end |
Instance Method Details
#apply_rule ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/parslet/atoms/rule/position.rb', line 70 def apply_rule result = recall if result.nil? # Eval rule body with LR supported by # placing a LR flag before eval rule body # and growing LR seed after detected LR lr = LR.new(fail('left recursion detected'), self.rule, self.pos) lr_stack.push(lr) self.entry = lr self.entry = eval_rule_body lr_stack.pop if self.entry.first && lr.detected? grow_lr(lr.head) end result = self.entry elsif result.is_a?(LR) # Find out all involved lrs in stack # Collect rules of involved lrs # And set head of involved lrs for re-eval # rules in recall process result.setup_for_re_eval_involved_rules(lr_stack) end source.pos = result.pos a = result.answer if a.is_a? Parslet::Atoms::Rule::Position::MemoEntry a = a.answer end a end |