Skip to content

Commit

Permalink
Refactoring: For failure last index, just using the current index at …
Browse files Browse the repository at this point in the history
…time of assignment.
  • Loading branch information
Nathan Sobo committed Mar 15, 2008
1 parent 965efca commit 63236d0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/treetop/compiler/node_classes/choice.rb
Expand Up @@ -24,7 +24,7 @@ def compile_alternatives(alternatives)
builder.accumulate "failed_alternatives", subexpression_result_var
if alternatives.size == 1
reset_index
assign_failure start_index_var, subexpression_result_var
assign_failure start_index_var
else
compile_alternatives(alternatives[1..-1])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/treetop/compiler/node_classes/parsing_expression.rb
Expand Up @@ -91,8 +91,8 @@ def epsilon_node(include_endpoint = false)
"SyntaxNode.new(input, index#{elipsis}index)"
end

def assign_failure(start_index_var, precipitating_result)
assign_result("ParseFailure.new(#{start_index_var}..#{precipitating_result}.index)")
def assign_failure(start_index_var)
assign_result("ParseFailure.new(#{start_index_var}..index)")
end

def var_initialization
Expand Down
2 changes: 1 addition & 1 deletion lib/treetop/compiler/node_classes/predicate.rb
Expand Up @@ -13,7 +13,7 @@ def compile(address, builder, parent_expression)
end

def assign_failure
super(start_index_var, subexpression_result_var)
super(start_index_var)
accumulate_dependency subexpression_result_var
end

Expand Down
2 changes: 1 addition & 1 deletion lib/treetop/compiler/node_classes/repetition.rb
Expand Up @@ -44,7 +44,7 @@ def compile(address, builder, parent_expression)
super
builder.if__ "#{accumulator_var}.empty?" do
reset_index
assign_failure start_index_var, subexpression_result_var
assign_failure start_index_var
end
builder.else_ do
assign_and_extend_result
Expand Down
2 changes: 1 addition & 1 deletion lib/treetop/compiler/node_classes/sequence.rb
Expand Up @@ -14,8 +14,8 @@ def compile(address, builder, parent_expression = nil)
extend_result_with_inline_module
end
builder.else_ do
assign_failure start_index_var
reset_index
assign_failure start_index_var, "#{accumulator_var}.last"
builder << "#{result_var}.dependencies.concat(#{accumulator_var})"
end
end_comment(self)
Expand Down

0 comments on commit 63236d0

Please sign in to comment.