Skip to content

Commit

Permalink
Patch for issue #6
Browse files Browse the repository at this point in the history
this change allows:
  * almost statments enclosed by '()'
  * some literals enclosed by '()': show t/01-stmts.t for the details
  • Loading branch information
Daehyub Kim committed Oct 13, 2011
1 parent 55bb11c commit ab17c75
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/parser/grammar.pg
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ rule alias {
} }


token stmt { 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>*
]
{*} {*}
} }


Expand Down
87 changes: 80 additions & 7 deletions t/01-stmts.t
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
# If this is to test the basic statements then we can't really use Test.rb # 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 # Although of course Test.rb itself contains all the statements tested
puts "1..11" puts "1..30"


if 1 then if 1 then
puts "ok 1" puts "ok 1"
Expand Down Expand Up @@ -55,18 +55,91 @@ else
puts "not ok 8 # an empty string '' should evaluate to true - Issue 28" puts "not ok 8 # an empty string '' should evaluate to true - Issue 28"
end end


# test parrentheses () # the statements enclosed by parentheses '()'
if (1) (if 1
puts "ok 9" puts "ok 9"
end)

( if 1
puts "ok 10"
end )

(
if 1
puts "ok 11"
end
)

if (1)
puts "ok 12"
else else
puts "not ok 9" puts "not ok 13"
end end


if (-1) if (-1)
puts "ok 10" puts "ok 14"
else else
puts "not ok 10" puts "not ok 14"
end end


# the literals(objects) enclosed by parentheses '()'
(1)
puts "ok 15"

(-1) (-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.