Use return_nodeset? vs USE_NODESET

This commit is contained in:
Yorick Peterse 2015-07-24 00:28:35 +02:00
parent 9000d5efdb
commit 0e9f533358
1 changed files with 9 additions and 3 deletions

View File

@ -18,7 +18,7 @@ module Oga
STAR = '*' STAR = '*'
# Node types that require a NodeSet to push nodes into. # Node types that require a NodeSet to push nodes into.
USE_NODESET = [:path, :absolute_path, :axis, :predicate] RETURN_NODESET = [:path, :absolute_path, :axis, :predicate]
## ##
# Compiles and caches an AST. # Compiles and caches an AST.
@ -39,7 +39,7 @@ module Oga
document = node_literal document = node_literal
matched = matched_literal matched = matched_literal
if USE_NODESET.include?(ast.type) if return_nodeset?(ast)
ruby_ast = process(ast, document) { |node| matched.push(node) } ruby_ast = process(ast, document) { |node| matched.push(node) }
else else
ruby_ast = process(ast, document) ruby_ast = process(ast, document)
@ -48,7 +48,7 @@ module Oga
vars = variables_literal.assign(literal('nil')) vars = variables_literal.assign(literal('nil'))
proc_ast = literal('lambda').add_block(document, vars) do proc_ast = literal('lambda').add_block(document, vars) do
if USE_NODESET.include?(ast.type) if return_nodeset?(ast)
matched.assign(literal(XML::NodeSet).new) matched.assign(literal(XML::NodeSet).new)
.followed_by(ruby_ast) .followed_by(ruby_ast)
.followed_by(matched) .followed_by(matched)
@ -387,6 +387,12 @@ module Oga
def xpath_number?(ast) def xpath_number?(ast)
ast.type == :int || ast.type == :float ast.type == :int || ast.type == :float
end end
# @param [AST::Node] ast
# @return [TrueClass|FalseClass]
def return_nodeset?(ast)
RETURN_NODESET.include?(ast.type)
end
end # Compiler end # Compiler
end # XPath end # XPath
end # Oga end # Oga