Thank you for the excellent parser generator library. It makes it straightforward to handle complex grammars in ruby.
I ran into a problem where a regular expression looking for a left curly brace was causing Treetop parsing to fail. Here is a patch with a test case that will trigger the issue:
diff --git a/spec/compiler/grammar_spec.rb b/spec/compiler/grammar_spec.rb
index 7b8e515..f16935d 100644
--- a/spec/compiler/grammar_spec.rb
+++ b/spec/compiler/grammar_spec.rb
@@ -38,4 +38,21 @@ module GrammarSpec
self.class.const_get(:Foo).ancestors.should include(GrammarSpec::Bar)
end
end
+
+ describe "handling of curly braces" do
+ before do
+ @grammar = %{
+ grammar Test
+ rule foo
+ 'foo' { def foo_method(str); str =~ /\{/ end }
+ end
+ end
+ }
+ end
+
+ it "does not raise for an unbalanced left curly brace within a block" do
+ expect { parse_with_metagrammar(@grammar.strip, :grammar) }.to_not raise_error
+ end
+ end
end
The rule in metagrammar.treetop that is leading to the exception appears to be this one:
rule inline_module
'{' (inline_module / ![{}] .)* '}' <InlineModule>
end
I think the logic needs to be a little more complex here. I would have attempted a fix, but I'm having difficulty getting the existing specs to pass.