Method: Treetop::Compiler::ParsingRule#generate_cache_lookup

Defined in:
lib/treetop/compiler/node_classes/parsing_rule.rb

#generate_cache_lookup(builder) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/treetop/compiler/node_classes/parsing_rule.rb', line 34

def generate_cache_lookup(builder)
  builder.if_ "node_cache[:#{name}].has_key?(index)" do
    cache_address = "node_cache[:#{name}][index]"
    builder.assign 'cached', cache_address
    builder.if_ "cached" do
      # Handle lazily instantiated nodes:
      builder << "#{cache_address} = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true"
      builder << '@index = cached.interval.end'
    end
    builder << 'return cached'
  end
end