From ef59f160c738d65c6ae9cedf8b5bb33fdb0543e6 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 29 Jul 2015 09:44:14 +0200 Subject: [PATCH] XPath compiler support for true()/false() --- lib/oga/xpath/compiler.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index bf0bc39..4cf0785 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -399,6 +399,39 @@ module Oga .or(send_message('raise', string("Undefined XPath variable: #{name}"))) end + ## + # Delegates function calls to specific handlers. + # + # @param [AST::Node] ast + # @param [Oga::Ruby::Node] input + # @return [Oga::Ruby::Node] + # + def on_call(ast, input, &block) + name, test = *ast.children + + handler = name.gsub('-', '_') + + send(:"on_call_#{handler}", test, input, &block) + end + + ## + # Processes the `true()` function call. + # + # @see [#on_call] + # + def on_call_true(ast, input) + literal('true') + end + + ## + # Processes the `false()` function call. + # + # @see [#on_call] + # + def on_call_false(ast, input) + literal('false') + end + private # @param [#to_s] value