class Citrus::MemoizedInput

A MemoizedInput is an Input that caches segments of the event stream for particular rules in a parse. This technique (also known as “Packrat” parsing) guarantees parsers will operate in linear time but costs significantly more in terms of time and memory required to perform a parse. For more information, please read the paper on Packrat parsing at pdos.csail.mit.edu/~baford/packrat/icfp02/.

Attributes

cache[R]

A nested hash of rules to offsets and their respective matches.

cache_hits[R]

The number of times the cache was hit.

Public Class Methods

new(string) click to toggle source
Calls superclass method Citrus::Input.new
# File lib/citrus.rb, line 298
def initialize(string)
  super(string)
  @cache = {}
  @cache_hits = 0
end

Public Instance Methods

memoized?() click to toggle source

Returns true when using memoization to cache match results.

# File lib/citrus.rb, line 317
def memoized?
  true
end