Class: Treetop::Compiler::Choice
- Inherits:
-
ParsingExpression
- Object
- Runtime::SyntaxNode
- ParsingExpression
- Treetop::Compiler::Choice
- Defined in:
- lib/treetop/compiler/node_classes/choice.rb
Instance Attribute Summary
Attributes inherited from ParsingExpression
#address, #builder, #parent_expression, #subexpression_address, #var_symbols
Attributes inherited from Runtime::SyntaxNode
#dot_id, #input, #interval, #parent
Instance Method Summary collapse
- #compile(address, builder, parent_expression = nil) ⇒ Object
- #compile_alternatives(alternatives) ⇒ Object
Methods inherited from ParsingExpression
#accumulate_subexpression_result, #accumulator_var, #assign_failure, #assign_lazily_instantiated_node, #assign_result, #begin_comment, #declared_module_name, #decorated?, #end_comment, #epsilon_node, #extend_result, #extend_result_with_declared_module, #extend_result_with_inline_module, #init_value, #inline_module_name, #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
#<=>, #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
#compile(address, builder, parent_expression = nil) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/treetop/compiler/node_classes/choice.rb', line 4 def compile(address, builder, parent_expression = nil) super begin_comment(self) use_vars :result, :start_index compile_alternatives(alternatives) end_comment(self) end |
#compile_alternatives(alternatives) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/treetop/compiler/node_classes/choice.rb', line 12 def compile_alternatives(alternatives) obtain_new_subexpression_address alternatives.first.compile(subexpression_address, builder) builder.if__ subexpression_success? do assign_result subexpression_result_var extend_result_with_declared_module extend_result_with_inline_module end builder.else_ do if alternatives.size == 1 reset_index assign_failure start_index_var else compile_alternatives(alternatives[1..-1]) end end end |