From 6d01adafc75274b89d3cb682f60ca2426b264dd7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 7 Jul 2015 10:26:22 +0200 Subject: [PATCH] XPath compiler now actually returns a Proc --- lib/oga/xpath/compiler.rb | 7 ++++++- spec/oga/xpath/compiler_spec.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index f30f181..1872b0e 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -30,11 +30,16 @@ module Oga end end - literal('lambda').add_block(document) do + proc_ast = literal('lambda').add_block(document) do matched.assign(literal(XML::NodeSet).new) .followed_by(ruby_ast) .followed_by(matched) end + + generator = Ruby::Generator.new + source = generator.process(proc_ast) + + eval(source) end ## diff --git a/spec/oga/xpath/compiler_spec.rb b/spec/oga/xpath/compiler_spec.rb index 18b8a22..3e4f372 100644 --- a/spec/oga/xpath/compiler_spec.rb +++ b/spec/oga/xpath/compiler_spec.rb @@ -31,7 +31,7 @@ describe Oga::XPath::Compiler do ast = parse_xpath('foo') block = @compiler.compile(ast) - block.call(doc).should be_an_instance_of(NodeSet) + block.call(doc).should be_an_instance_of(Oga::XML::NodeSet) end end end