Module: Walrus::Grammar::Memoizing
- Included in:
- Parslet, ParsletCombination, Predicate
- Defined in:
- lib/walrus/grammar/memoizing.rb
Instance Method Summary collapse
-
#check_left_recursion(parseable, options = {}) ⇒ Object
Can only check for left recursion if memoizing is turned on (the help of the memoizer is needed).
-
#memoizing_parse(string, options = {}) ⇒ Object
This method provides a clean, optional implementation of memoizing by serving as a wrapper for all parse invocations.
Instance Method Details
#check_left_recursion(parseable, options = {}) ⇒ Object
Can only check for left recursion if memoizing is turned on (the help of the memoizer is needed).
32 33 34 35 |
# File 'lib/walrus/grammar/memoizing.rb', line 32 def check_left_recursion(parseable, = {}) return unless .has_key?(:memoizer) [:memoizer].check_left_recursion(parseable, ) end |
#memoizing_parse(string, options = {}) ⇒ Object
This method provides a clean, optional implementation of memoizing by serving as a wrapper for all parse invocations. Rather than calling the parse methods directly, this method should be called; if it is appropriate to use a memoizer then it will be invoked, otherwise control will fall through to the real parse method. Turning off memoizing is as simple as not parsing a value with the :memoizer key in the options hash. This method defined is in a separate module so that it can easily be mixed in with all Parslets, ParsletCombinations and Predicates.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/walrus/grammar/memoizing.rb', line 18 def memoizing_parse(string, = {}) # Will use memoizer if available and not instructed to ignore it if .has_key?(:memoizer) and not (.has_key?(:ignore_memoizer) and [:ignore_memoizer]) [:parseable] = self [:memoizer].parse(string, ) else # otherwise will proceed as normal [:ignore_memoizer] = false parse(string, ) end end |