Class: Treetop::Compiler::SequenceElementAccessorModule

Inherits:
Object
  • Object
show all
Includes:
InlineModuleMixin
Defined in:
lib/treetop/compiler/node_classes/sequence.rb

Instance Attribute Summary collapse

Attributes included from InlineModuleMixin

#module_name

Instance Method Summary collapse

Constructor Details

#initialize(sequence_elements) ⇒ SequenceElementAccessorModule

Returns a new instance of SequenceElementAccessorModule.



49
50
51
# File 'lib/treetop/compiler/node_classes/sequence.rb', line 49

def initialize(sequence_elements)
  @sequence_elements = sequence_elements
end

Instance Attribute Details

#sequence_elementsObject (readonly)

Returns the value of attribute sequence_elements.



47
48
49
# File 'lib/treetop/compiler/node_classes/sequence.rb', line 47

def sequence_elements
  @sequence_elements
end

Instance Method Details

#compile(index, rule, builder) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/treetop/compiler/node_classes/sequence.rb', line 53

def compile(index, rule, builder)
  super
  builder.module_declaration(module_name) do
    sequence_elements.each_with_index do |element, index|
      if element.label_name
        builder.method_declaration(element.label_name) do
          builder << "elements[#{index}]"
        end
        builder.newline unless index == sequence_elements.size - 1
      end
    end
  end
end