Skip to content
This repository
Browse code

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...
commit ab17c7563afd735cbb1448d903c7baba89b6df7f 1 parent 55bb11c
lateau authored

Showing 2 changed files with 84 additions and 8 deletions. Show diff stats Hide diff stats

  1. +4 1 src/parser/grammar.pg
  2. +80 7 t/01-stmts.t
5 src/parser/grammar.pg
@@ -61,7 +61,10 @@ rule alias {
61 61 }
62 62
63 63 token stmt {
64   - <basic_stmt> <.ws> <stmt_mod>*
  64 + [
  65 + | '(' \s*\n* <basic_stmt> <.ws> <stmt_mod>* \s*\n* ')' # NOTE: this change is not allows '(- 1)'
  66 + | <basic_stmt> <.ws> <stmt_mod>*
  67 + ]
65 68 {*}
66 69 }
67 70
87 t/01-stmts.t
... ... @@ -1,6 +1,6 @@
1 1 # If this is to test the basic statements then we can't really use Test.rb
2 2 # Although of course Test.rb itself contains all the statements tested
3   -puts "1..11"
  3 +puts "1..30"
4 4
5 5 if 1 then
6 6 puts "ok 1"
@@ -55,18 +55,91 @@ else
55 55 puts "not ok 8 # an empty string '' should evaluate to true - Issue 28"
56 56 end
57 57
58   -# test parrentheses ()
59   -if (1)
  58 +# the statements enclosed by parentheses '()'
  59 +(if 1
60 60 puts "ok 9"
  61 +end)
  62 +
  63 +( if 1
  64 + puts "ok 10"
  65 +end )
  66 +
  67 +(
  68 + if 1
  69 + puts "ok 11"
  70 + end
  71 +)
  72 +
  73 +if (1)
  74 + puts "ok 12"
61 75 else
62   - puts "not ok 9"
  76 + puts "not ok 13"
63 77 end
64 78
65 79 if (-1)
66   - puts "ok 10"
  80 + puts "ok 14"
67 81 else
68   - puts "not ok 10"
  82 + puts "not ok 14"
69 83 end
70 84
  85 +# the literals(objects) enclosed by parentheses '()'
  86 +(1)
  87 +puts "ok 15"
  88 +
71 89 (-1)
72   -puts "ok 11"
  90 +puts "ok 16"
  91 +
  92 +# failed
  93 +#(- 1)
  94 +puts "not ok 17"
  95 +
  96 +# failed
  97 +(
  98 +-
  99 +1
  100 +)
  101 +puts "ok 18"
  102 +
  103 +# failed
  104 +(
  105 +-
  106 + 1
  107 +)
  108 +puts "ok 19"
  109 +
  110 +# failed
  111 +( - 1 )
  112 +puts "ok 20"
  113 +
  114 +(1.0)
  115 +puts "ok 21"
  116 +
  117 +([])
  118 +puts "ok 22"
  119 +
  120 +# failed
  121 +(%W(a b c))
  122 +puts "ok 23"
  123 +
  124 +({})
  125 +puts "ok 24"
  126 +
  127 +# failed
  128 +(//)
  129 +puts "ok 25"
  130 +
  131 +("")
  132 +puts "ok 26"
  133 +
  134 +# failed
  135 +(%Q())
  136 +puts "ok 27"
  137 +
  138 +(true)
  139 +puts "ok 28"
  140 +
  141 +(false)
  142 +puts "ok 29"
  143 +
  144 +(true)
  145 +puts "ok 30"

0 comments on commit ab17c75

Please sign in to comment.
Something went wrong with that request. Please try again.