Class: Treetop::Compiler::Grammar

Inherits:
Runtime::SyntaxNode show all
Defined in:
lib/treetop/compiler/node_classes/grammar.rb

Instance Attribute Summary

Attributes inherited from Runtime::SyntaxNode

#input, #interval, #parent

Instance Method Summary collapse

Methods inherited from Runtime::SyntaxNode

#<=>, #dot_id, #elements, #empty?, #extension_modules, #initialize, #inspect, #nonterminal?, #terminal?, #text_value, #write_dot, #write_dot_file

Constructor Details

This class inherits a constructor from Treetop::Runtime::SyntaxNode

Instance Method Details

#compileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/treetop/compiler/node_classes/grammar.rb', line 4

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

#indent_levelObject



19
20
21
# File 'lib/treetop/compiler/node_classes/grammar.rb', line 19

def indent_level
  input.column_of(interval.begin) - 1
end

#parser_nameObject



23
24
25
# File 'lib/treetop/compiler/node_classes/grammar.rb', line 23

def parser_name
  grammar_name.text_value + 'Parser'
end