Skip to content
Browse files

added Position::Context to maintain context related methods in Position

  • Loading branch information...
1 parent a762306 commit 2ea717e10261e9d3b80ae6bbbd2c00340eb94edc @xli committed Aug 18, 2011
Showing with 21 additions and 18 deletions.
  1. +21 −18 lib/parslet/atoms/rule.rb
View
39 lib/parslet/atoms/rule.rb
@@ -56,30 +56,33 @@ def eval?(rule)
# Update/fetch parsed entry at a given position in source
# Eval rule body at a given position in source and cache the result
class Position < Struct.new(:pos, :source, :context, :rule)
- def entry=(entry)
- context.set rule, pos, entry
- end
+ module Context
+ def entry=(entry)
+ context.set rule, pos, entry
+ end
- def entry
- context.lookup(rule, pos)
- end
+ def entry
+ context.lookup(rule, pos)
+ end
- def head
- context.heads[pos]
- end
+ def head
+ context.heads[pos]
+ end
- def head=(h)
- context.heads[pos] = h
- end
+ def head=(h)
+ context.heads[pos] = h
+ end
- def push_into_lr_stack(lr)
- lr.next = context.lr_stack
- context.lr_stack = lr
- end
+ def push_into_lr_stack(lr)
+ lr.next = context.lr_stack
+ context.lr_stack = lr
+ end
- def pop_lr_stack
- context.lr_stack = context.lr_stack.next
+ def pop_lr_stack
+ context.lr_stack = context.lr_stack.next
+ end
end
+ include Context
def apply_rule
self.recall || self.eval_rule_body_with_lr_support

0 comments on commit 2ea717e

Please sign in to comment.
Something went wrong with that request. Please try again.