Sha256: 261f32cf6c94b91021bd51f19c8b4b4cb5f2b2fa68a750fddbb351912cd4e059

Contents?: true

Size: 807 Bytes

Versions: 6

Compression:

Stored size: 807 Bytes

Contents

module Treetop
  module Compiler
    class Grammar < Runtime::SyntaxNode
      def compile
        builder = RubyBuilder.new
        
        builder.module_declaration "#{grammar_name.text_value}" do
          builder.in(indent_level) # account for initial indentation of grammar declaration
          builder << "include ::Treetop::Runtime"
          builder.newline
          declaration_sequence.compile(builder)
        end
        builder.newline
        builder.class_declaration "#{parser_name} < ::Treetop::Runtime::CompiledParser" do
          builder << "include #{grammar_name.text_value}"
        end
      end
      
      def indent_level
        input.column_of(interval.begin) - 1
      end
      
      def parser_name
        grammar_name.text_value + 'Parser'
      end
    end
 end 
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
treetop-1.1.1 lib/treetop/compiler/node_classes/grammar.rb
treetop-1.0.1 lib/treetop/compiler/node_classes/grammar.rb
treetop-1.0.0 lib/treetop/compiler/node_classes/grammar.rb
treetop-1.0.2 lib/treetop/compiler/node_classes/grammar.rb
treetop-1.1.0 lib/treetop/compiler/node_classes/grammar.rb
treetop-1.1.2 lib/treetop/compiler/node_classes/grammar.rb