Permalink
Browse files

return the last block called as the result to #parse

  • Loading branch information...
1 parent c9fc238 commit 7e266ae8324a001285ab799cb36a182cd71e56bc @smtlaissezfaire committed May 20, 2009
Showing with 13 additions and 8 deletions.
  1. +2 −1 ext/gazelle_ruby_bindings/gazelle_ruby_bindings.c
  2. +1 −1 lib/gazelle/parser.rb
  3. +10 −6 spec/gazelle_integration_spec.rb
@@ -136,7 +136,8 @@ static VALUE rb_gazelle_parse_p(VALUE self, VALUE input) {
}
static VALUE rb_gazelle_parse(VALUE self, VALUE input) {
- return run_gazelle_parse(self, input, true);
+ run_gazelle_parse(self, input, true);
+ return rb_ivar_get(self, rb_intern("@last_result"));
}
/* Hook up the ruby methods. Similar to lua's luaopen_(mod) functions */
View
@@ -21,7 +21,7 @@ def rules(&block)
attr_writer :debug
def run_rule(action, str)
- with_action(action, str) do |rule|
+ @last_result = with_action(action, str) do |rule|
rule.call(str)
end
end
@@ -15,12 +15,12 @@ module Gazelle
it "should find the file even when given with a short path" do
parser = Parser.new("spec/hello.gzc")
- parser.parse("(5)").should be_true
+ parser.parse?("(5)").should be_true
end
it "should find the file when it is missing the .gzc extension" do
parser = Parser.new("spec/hello")
- parser.parse("(5)").should be_true
+ parser.parse?("(5)").should be_true
end
it "should raise an 'Errno::ENOENT' error if the file does not exist" do
@@ -109,10 +109,6 @@ module Gazelle
}.should_not raise_error
end
- it "should return true when the parse matches, but there is no triggered rule" do
- @parser.parse("(5)").should be_true
- end
-
it "should be able to call a rule defined with a string, but called with a symbol" do
called = false
@@ -123,6 +119,14 @@ module Gazelle
@parser.parse("(5)")
called.should be_true
end
+
+ it "should return the result of the last rule" do
+ @parser.on "hello" do
+ 5
+ end
+
+ @parser.parse("(5)").should == 5
+ end
end
describe "parsing subnodes" do

0 comments on commit 7e266ae

Please sign in to comment.