Module: Walrat::Memoizing
- Included in:
- Parslet, ParsletCombination, Predicate
- Defined in:
- lib/walrat/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).
49 50 51 52 |
# File 'lib/walrat/memoizing.rb', line 49 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 passing 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.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/walrat/memoizing.rb', line 35 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 |