XPath compiler support for the following axis

This commit is contained in:
Yorick Peterse 2015-08-05 09:37:30 +02:00
parent e04ca9be35
commit 4698e98632
1 changed files with 43 additions and 1 deletions

View File

@ -88,6 +88,10 @@ module Oga
generator = Ruby::Generator.new
source = generator.process(proc_ast)
#File.open('/tmp/xpath.rb', 'w') do |handle|
# handle.write(source.gsub("\n\n", "\n"))
#end
eval(source)
ensure
reset
@ -299,7 +303,7 @@ module Oga
end
next_check = (!check).or(parent != doc_node.parent).if_true do
literal('next')
send_message(:next)
end
match_node = backup_variable(node, doc_node) do
@ -317,6 +321,44 @@ module Oga
.followed_by(each_node)
end
# @param [AST::Node] ast
# @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node]
def on_axis_following(ast, input, &block)
node = node_literal
orig_input = original_input_literal
doc_node = literal('doc_node')
check = literal('check')
root = literal('root')
root_assign = orig_input.is_a?(XML::Node)
.if_true { root.assign(orig_input.root_node) }
.else { root.assign(orig_input) }
check_assign = check.assign(literal('false'))
each_node = root.each_node.add_block(doc_node) do
doc_compare = doc_node.eq(input).if_true do
check.assign(literal('true'))
.followed_by(throw_message(:skip_children))
end
next_check = (!check).if_true { send_message(:next) }
match_node = backup_variable(node, doc_node) do
process(ast, node, &block).if_true do
yield node
end
end
doc_compare.followed_by(next_check)
.followed_by(match_node)
end
root_assign.followed_by(check_assign)
.followed_by(each_node)
end
# @param [AST::Node] ast
# @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node]