From 8a49d9c0eea711f470e7a4e5ae9d7e607d955edd Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 29 Jul 2015 22:06:25 +0200 Subject: [PATCH] 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. --- lib/oga/xpath/compiler.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index 7263433..ecf2501 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -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]