Started removing usage of backup_variable

This was a hack that never should've made it into the code in the first
place. This breaks some of the CSS specs, but this should be taken care
of when I refactor predicate support.
This commit is contained in:
Yorick Peterse 2015-08-18 21:56:19 +02:00
parent 15ecca4a64
commit ee44907ca5
1 changed files with 18 additions and 54 deletions

View File

@ -222,15 +222,13 @@ module Oga
def on_axis_descendant_or_self(ast, input, &block) def on_axis_descendant_or_self(ast, input, &block)
node = node_literal node = node_literal
backup_variable(node, input) do process(ast, input, &block)
process(ast, node, &block) .if_true { yield input }
.if_true { yield node } .followed_by do
.followed_by do input.each_node.add_block(node) do
node.each_node.add_block(node) do process(ast, node, &block).if_true { yield node }
process(ast, node, &block).if_true { yield node }
end
end end
end end
end end
# @param [AST::Node] ast # @param [AST::Node] ast
@ -239,10 +237,8 @@ module Oga
def on_axis_descendant(ast, input, &block) def on_axis_descendant(ast, input, &block)
node = node_literal node = node_literal
backup_variable(node, input) do input.each_node.add_block(node) do
node.each_node.add_block(node) do process(ast, node, &block).if_true { yield node }
process(ast, node, &block).if_true { yield node }
end
end end
end end
@ -250,11 +246,12 @@ module Oga
# @param [Oga::Ruby::Node] input # @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node] # @return [Oga::Ruby::Node]
def on_axis_parent(ast, input, &block) def on_axis_parent(ast, input, &block)
node = node_literal node = node_literal
parent = unique_literal(:parent)
input.is_a?(XML::Node).if_true do input.is_a?(XML::Node).if_true do
backup_variable(node, input.parent) do parent.assign(input.parent).followed_by do
process(ast, node, &block).if_true { yield node } process(ast, parent, &block).if_true { yield parent }
end end
end end
end end
@ -265,9 +262,7 @@ module Oga
def on_axis_self(ast, input, &block) def on_axis_self(ast, input, &block)
node = node_literal node = node_literal
backup_variable(node, input) do process(ast, input, &block).if_true { yield input }
process(ast, node, &block).if_true { yield node }
end
end end
# @param [AST::Node] ast # @param [AST::Node] ast
@ -303,9 +298,7 @@ module Oga
end end
end end
.followed_by do .followed_by do
backup_variable(node, doc_node) do process(ast, doc_node, &block).if_true { yield doc_node }
process(ast, node, &block).if_true { yield node }
end
end end
end end
end end
@ -315,7 +308,6 @@ module Oga
# @param [Oga::Ruby::Node] input # @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node] # @return [Oga::Ruby::Node]
def on_axis_following(ast, input, &block) def on_axis_following(ast, input, &block)
node = node_literal
orig_input = original_input_literal orig_input = original_input_literal
doc_node = literal(:doc_node) doc_node = literal(:doc_node)
check = literal(:check) check = literal(:check)
@ -336,10 +328,8 @@ module Oga
check.if_false { send_message(:next) } check.if_false { send_message(:next) }
end end
.followed_by do .followed_by do
backup_variable(node, doc_node) do process(ast, doc_node, &block).if_true do
process(ast, node, &block).if_true do yield doc_node
yield node
end
end end
end end
end end
@ -380,9 +370,7 @@ module Oga
doc_node.eq(input) doc_node.eq(input)
.if_true { self.break } .if_true { self.break }
.followed_by do .followed_by do
backup_variable(node, doc_node) do process(ast, doc_node, &block).if_true { yield doc_node }
process(ast, node, &block).if_true { yield node }
end
end end
end end
end end
@ -414,9 +402,7 @@ module Oga
.if_true { self.break } .if_true { self.break }
.followed_by do .followed_by do
doc_node.parent.eq(parent).if_true do doc_node.parent.eq(parent).if_true do
backup_variable(node, doc_node) do process(ast, doc_node, &block).if_true { yield doc_node }
process(ast, node, &block).if_true { yield node }
end
end end
end end
end end
@ -1390,28 +1376,6 @@ module Oga
.followed_by { yield left_var, right_var } .followed_by { yield left_var, right_var }
end end
##
# Backs up a local variable and restores it after yielding the block.
#
# This is useful when processing axes followed by other segments in a
# path. In these cases each segment doesn't know about its input (since
# it's determined later), thus they resort to just using whatever `node`
# is set to. By re-assigning (and re-storing) this variable the input can
# be controller more easily.
#
# @param [Oga::Ruby::Node] variable
# @param [Oga::Ruby::Node] new
# @return [Oga::Ruby::Node]
#
def backup_variable(variable, new)
backup = unique_literal(:backup)
backup.assign(variable)
.followed_by(variable.assign(new))
.followed_by(yield)
.followed_by(variable.assign(backup))
end
# @return [Oga::Ruby::Node] # @return [Oga::Ruby::Node]
def matched_literal def matched_literal
literal(:matched) literal(:matched)