Basic compiler support for descendant-or-self

The generated code isn't entirely correct which considering the tests do
pass means the tests need to be fixed too.
This commit is contained in:
Yorick Peterse 2015-07-29 22:06:25 +02:00
parent d50f89cdf1
commit 8a49d9c0ee
1 changed files with 14 additions and 0 deletions

View File

@ -214,6 +214,20 @@ module Oga
end
end
# @param [AST::Node] ast
# @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node]
def on_axis_descendant_or_self(ast, input, &block)
descendant = node_literal
self_test = process(ast, input, &block).if_true { yield input }
descendants_test = input.each_node.add_block(descendant) do
process(ast, descendant, &block).if_true { yield descendant }
end
self_test.followed_by(descendants_test)
end
# @param [AST::Node] ast
# @param [Oga::Ruby::Node] input
# @return [Oga::Ruby::Node]