# class Treetop::Compiler::SequenceElementAccessorModule

### Attributes

sequence_elements[R]

### Public Class Methods

new(sequence_elements) click to toggle source

    # File lib/treetop/compiler/node_classes/sequence.rb, line 49
    def initialize(sequence_elements)
      @sequence_elements = sequence_elements
    end

### Public Instance Methods

compile(idx, builder, rule) click to toggle source
Calls superclass method Treetop::Compiler::InlineModuleMixin#compile

    # File lib/treetop/compiler/node_classes/sequence.rb, line 53
    def compile(idx, builder, rule)
      super
      builder.module_declaration(module_name) do
        elements_by_name = sequence_elements.inject({}){|h,e| (h[e.label_name.to_s] ||= []) << e; h}
        sequence_elements.each_with_index do |element, index|
          if element.label_name
            repetitions = elements_by_name[element.label_name.to_s]
            label_name = element.label_name + (repetitions.size > 1 ? (repetitions.index(element)+1).to_s : "")
            builder.method_declaration(label_name) do
              builder << "elements[#{index}]"
            end
            builder.newline unless index == sequence_elements.size - 1
          end
        end
      end
    end