Class: Treetop::Compiler::Grammar
- Inherits:
-
Runtime::SyntaxNode
- Object
- Runtime::SyntaxNode
- Treetop::Compiler::Grammar
- Defined in:
- lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/grammar.rb
Instance Attribute Summary
Attributes inherited from Runtime::SyntaxNode
#elements, #input, #interval, #parent
Instance Method Summary collapse
Methods inherited from Runtime::SyntaxNode
#empty?, #extension_modules, #initialize, #inspect, #nonterminal?, #terminal?, #text_value
Constructor Details
This class inherits a constructor from Treetop::Runtime::SyntaxNode
Instance Method Details
#compile ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gems/treetop-1.2.4/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_level ⇒ Object
19 20 21 |
# File 'lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/grammar.rb', line 19 def indent_level input.column_of(interval.begin) - 1 end |
#parser_name ⇒ Object
23 24 25 |
# File 'lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/grammar.rb', line 23 def parser_name grammar_name.text_value + 'Parser' end |