Class: Treetop::Compiler::Repetition

Inherits:
ParsingExpression show all
Defined in:
lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/repetition.rb

Direct Known Subclasses

OneOrMore, ZeroOrMore

Instance Attribute Summary

Attributes inherited from ParsingExpression

#address, #builder, #parent_expression, #subexpression_address, #var_symbols

Attributes inherited from Runtime::SyntaxNode

#elements, #input, #interval, #parent

Instance Method Summary collapse

Methods inherited from ParsingExpression

#accumulate_subexpression_result, #accumulator_var, #assign_failure, #assign_result, #begin_comment, #declared_module_name, #end_comment, #epsilon_node, #extend_result, #extend_result_with_declared_module, #extend_result_with_inline_module, #init_value, #node_class_name, #obtain_new_subexpression_address, #on_one_line, #optional_arg, #reset_index, #result_var, #start_index_var, #subexpression_result_var, #subexpression_success?, #use_vars, #var, #var_initialization

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

#assign_and_extend_resultObject



26
27
28
29
# File 'lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/repetition.rb', line 26

def assign_and_extend_result
  assign_result "#{node_class_name}.new(input, #{start_index_var}...index, #{accumulator_var})"
  extend_result_with_inline_module
end

#compile(address, builder, parent_expression) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/repetition.rb', line 4

def compile(address, builder, parent_expression)
  super
  repeated_expression = parent_expression.atomic
  begin_comment(parent_expression)
  use_vars :result, :accumulator, :start_index

  builder.loop do
    obtain_new_subexpression_address
    repeated_expression.compile(subexpression_address, builder)
    builder.if__ subexpression_success? do
      accumulate_subexpression_result
    end
    builder.else_ do
      builder.break
    end
  end
end

#inline_module_nameObject



22
23
24
# File 'lib/gems/treetop-1.2.4/lib/treetop/compiler/node_classes/repetition.rb', line 22

def inline_module_name
  parent_expression.inline_module_name
end