Permalink
Browse files

Patch for issue #6

this change allows:
  * almost statments enclosed by '()'
  * some literals enclosed by '()': show t/01-stmts.t for the details
  • Loading branch information...
1 parent 55bb11c commit ab17c7563afd735cbb1448d903c7baba89b6df7f @lateau lateau committed Oct 13, 2011
Showing with 84 additions and 8 deletions.
  1. +4 −1 src/parser/grammar.pg
  2. +80 −7 t/01-stmts.t
View
5 src/parser/grammar.pg
@@ -61,7 +61,10 @@ rule alias {
}
token stmt {
- <basic_stmt> <.ws> <stmt_mod>*
+ [
+ | '(' \s*\n* <basic_stmt> <.ws> <stmt_mod>* \s*\n* ')' # NOTE: this change is not allows '(- 1)'
+ | <basic_stmt> <.ws> <stmt_mod>*
+ ]
{*}
}
View
87 t/01-stmts.t
@@ -1,6 +1,6 @@
# If this is to test the basic statements then we can't really use Test.rb
# Although of course Test.rb itself contains all the statements tested
-puts "1..11"
+puts "1..30"
if 1 then
puts "ok 1"
@@ -55,18 +55,91 @@ else
puts "not ok 8 # an empty string '' should evaluate to true - Issue 28"
end
-# test parrentheses ()
-if (1)
+# the statements enclosed by parentheses '()'
+(if 1
puts "ok 9"
+end)
+
+( if 1
+ puts "ok 10"
+end )
+
+(
+ if 1
+ puts "ok 11"
+ end
+)
+
+if (1)
+ puts "ok 12"
else
- puts "not ok 9"
+ puts "not ok 13"
end
if (-1)
- puts "ok 10"
+ puts "ok 14"
else
- puts "not ok 10"
+ puts "not ok 14"
end
+# the literals(objects) enclosed by parentheses '()'
+(1)
+puts "ok 15"
+
(-1)
-puts "ok 11"
+puts "ok 16"
+
+# failed
+#(- 1)
+puts "not ok 17"
+
+# failed
+(
+-
+1
+)
+puts "ok 18"
+
+# failed
+(
+-
+ 1
+)
+puts "ok 19"
+
+# failed
+( - 1 )
+puts "ok 20"
+
+(1.0)
+puts "ok 21"
+
+([])
+puts "ok 22"
+
+# failed
+(%W(a b c))
+puts "ok 23"
+
+({})
+puts "ok 24"
+
+# failed
+(//)
+puts "ok 25"
+
+("")
+puts "ok 26"
+
+# failed
+(%Q())
+puts "ok 27"
+
+(true)
+puts "ok 28"
+
+(false)
+puts "ok 29"
+
+(true)
+puts "ok 30"

0 comments on commit ab17c75

Please sign in to comment.