Skip to content

Commit

Permalink
Added specs for matching booleans and nil, and refactored the associa…
Browse files Browse the repository at this point in the history
…ted matches in the parser into their own rules to make sure it only matches on those values.
  • Loading branch information
Twisol committed Dec 6, 2010
1 parent ad22ced commit 223d762
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/lupin/parser/parser.citrus
Expand Up @@ -176,9 +176,8 @@ grammar Lupin::Parser::Lua
( table
| number
| string
| 'nil' { Lupin::AST::Nil.new }
| 'false' { Lupin::AST::False.new }
| 'true' { Lupin::AST::True.new }
| boolean
| nil
)
end

Expand Down Expand Up @@ -227,6 +226,18 @@ grammar Lupin::Parser::Lua
| str: /\[(=*)\[.*?\]\1\]/m <Lupin::Parser::LongStringLiteral>
)
end

### Boolean
rule boolean
( 'false' { Lupin::AST::False.new }
| 'true' { Lupin::AST::True.new }
)
end

### Nil
rule nil
'nil' { Lupin::AST::Nil.new }
end

### Whitespace and comments
rule WS
Expand Down
6 changes: 6 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -34,6 +34,12 @@ def check (type, text)
check(:string, "[==[foo\\\"bar\\'baz\\r\\n]==]") { "foo\\\"bar\\'baz\\r\\n" }
end

it "matches booleans and nil" do
check(:boolean, "true") { true }
check(:boolean, "false") { false }
check(:nil, "nil") { nil }
end

it "matches tables" do
check(:table, "{}") { [:table] }
check(:table, "{1}") { [:table, [:pair, nil, 1.0]] }
Expand Down

0 comments on commit 223d762

Please sign in to comment.