This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Allow {} in Ruby.

  • Loading branch information...
threedaymonk committed Mar 22, 2012
1 parent 02efb85 commit 06a6dc42140e9d2a0c321ef0a44b50314fe96d3b
Showing with 16 additions and 1 deletion.
  1. +4 −1 lib/sibyl/parser.rb
  2. +12 −0 test/parsing_test.rb
View
@@ -26,8 +26,11 @@ class Parser < Parslet::Parser
rule(:branch_otherwise) {
str('otherwise').as(:type) >> s? >> arrow >> target
}
+ rule(:braced) {
+ ((str('{') >> braced >> str('}')) | match('[^}]')).repeat
+ }
rule(:code) {
- str('{') >> match('[^}]').repeat.as(:code) >> str('}') >> s?
+ str('{') >> braced.as(:code) >> str('}') >> s?
}
rule(:stepdef) {
str('step').as(:type) >> s? >> string.as(:subtype) >> string.as(:name)
View
@@ -138,6 +138,18 @@ def sexp(source)
assert_equal expected, actual
end
+ it "should ignore paired {} inside an expression" do
+ actual = sexp(%{
+ step any a
+ set foo_bar { foo.map { |a| a } }
+ })
+
+ expected = [
+ [:step, "any", "a", [
+ [:set, "foo_bar", "foo.map { |a| a }"]]]]
+
+ assert_equal expected, actual
+ end
it "should ignore a comment inside a unit" do
actual = sexp(%{

0 comments on commit 06a6dc4

Please sign in to comment.