Class: Treetop::Compiler::OccurrenceRange

Inherits:
Repetition show all
Defined in:
lib/treetop/compiler/node_classes/repetition.rb

Instance Attribute Summary

Attributes inherited from ParsingExpression

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

Attributes inherited from Runtime::SyntaxNode

#input, #interval, #parent

Instance Method Summary collapse

Methods inherited from Repetition

#assign_and_extend_result, #inline_module_name

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

#<=>, #dot_id, #elements, #empty?, #extension_modules, #initialize, #inspect, #inspect_children, #inspect_self, #nonterminal?, #terminal?, #text_value, #write_dot, #write_dot_file

Constructor Details

This class inherits a constructor from Treetop::Runtime::SyntaxNode

Instance Method Details

#clean_unsaturatedObject

remove the last terminal_failure if we merely failed to reach the maximum



95
96
97
98
99
100
101
# File 'lib/treetop/compiler/node_classes/repetition.rb', line 95

def clean_unsaturated
	if !max.empty? && max.text_value.to_i > 0
	  builder.if_ "#{accumulator_var}.size < #{max.text_value}" do
	    builder << '@terminal_failures.pop'  # Ignore the last failure.
	  end
	end
end

#compile(address, builder, parent_expression) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/treetop/compiler/node_classes/repetition.rb', line 73

def compile(address, builder, parent_expression)
  super

  if !min.empty? && min.text_value.to_i != 0
    # We got some, but fewer than we wanted. There'll be a failure reported already
    builder.if__ "#{accumulator_var}.size < #{min.text_value}" do
      reset_index
      assign_failure start_index_var
	  end
    builder.else_ do
	    clean_unsaturated
	    assign_and_extend_result parent_expression
	  end
  else
	  clean_unsaturated
	  assign_and_extend_result parent_expression
	end

  end_comment(parent_expression)
end

#expectedObject



103
104
105
# File 'lib/treetop/compiler/node_classes/repetition.rb', line 103

def expected
	parent_expression.atomic.expected && "at least #{min.text_value} "+parent_expression.atomic.expected
end