class Treetop::Compiler::ParsingRule

def compile(builder)

def compile(builder)
  compile_inline_module_declarations(builder)
  generate_method_definition(builder)
end

def compile_inline_module_declarations(builder)

def compile_inline_module_declarations(builder)
  parsing_expression.inline_modules.each_with_index do |inline_module, i|
    inline_module.compile(i, self, builder)
    builder.newline
  end
end

def generate_cache_lookup(builder)

def generate_cache_lookup(builder)
  builder.if_ "node_cache[:#{name}].has_key?(index)" do
    builder.assign 'cached', "node_cache[:#{name}][index]"
    builder << '@index = cached.interval.end if cached'
    builder << 'return cached'
  end
end

def generate_cache_storage(builder, result_var)

def generate_cache_storage(builder, result_var)
  builder.assign "node_cache[:#{name}][start_index]", result_var
end

def generate_method_definition(builder)

def generate_method_definition(builder)
  builder.reset_addresses
  expression_address = builder.next_address
  result_var = "r#{expression_address}"
  
  builder.method_declaration(method_name) do
    builder.assign 'start_index', 'index'
    generate_cache_lookup(builder)
    builder.newline
    parsing_expression.compile(expression_address, builder)
    builder.newline
    generate_cache_storage(builder, result_var)
    builder.newline          
    builder << "return #{result_var}"
  end
end

def method_name

def method_name
  "_nt_#{name}"
end

def name

def name
  nonterminal.text_value
end