Sha256: b9899abc93e24f406f8a0c4b28a4163cadf47afcd0dfb43b5b9ceb12a28e772b

Contents?: true

Size: 1.72 KB

Versions: 272

Compression:

Stored size: 1.72 KB

Contents

module Treetop
  module Compiler
    class ParsingRule < Runtime::SyntaxNode

      def compile(builder)
        compile_inline_module_declarations(builder)
        generate_method_definition(builder)
      end
      
      def compile_inline_module_declarations(builder)
        parsing_expression.inline_modules.each_with_index do |inline_module, i|
          inline_module.compile(i, builder, self)
          builder.newline
        end
      end
      
      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 << result_var
        end
      end
      
      def generate_cache_lookup(builder)
        builder.if_ "node_cache[:#{name}].has_key?(index)" do
          builder.assign 'cached', "node_cache[:#{name}][index]"
          builder.if_ "cached" do
            builder << 'cached = SyntaxNode.new(input, index...(index + 1)) if cached == true'
            builder << '@index = cached.interval.end'
          end
          builder << 'return cached'
        end
      end
      
      def generate_cache_storage(builder, result_var)
        builder.assign "node_cache[:#{name}][start_index]", result_var
      end
      
      def method_name
        "_nt_#{name}"
      end
      
      def name
        nonterminal.text_value
      end
    end
  end
end

Version data entries

272 entries across 227 versions & 31 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/treetop-1.4.15/lib/treetop/compiler/node_classes/parsing_rule.rb