fix parsing bug w/no conditional in a for loop
diff --git a/ruby/lib/lox/parser.rb b/ruby/lib/lox/parser.rb
index 0728bb4..2c1ecf8 100644
--- a/ruby/lib/lox/parser.rb
+++ b/ruby/lib/lox/parser.rb
@@ -68,10 +68,10 @@ module Lox
expression_stmt
end
- condition = !check?(:SEMICOLON) ? expression : Expr::Literal(true)
+ condition = check?(:SEMICOLON) ? Expr::Literal.new(true) : expression
consume!(:SEMICOLON, "Expect ';' after loop condition.")
- increment = !check?(:RIGHT_PAREN) ? expression : nil
+ increment = check?(:RIGHT_PAREN) ? nil : expression
consume!(:RIGHT_PAREN, "Expect ')' after for clauses.")
body = statement
diff --git a/ruby/test/lox/test_parser.rb b/ruby/test/lox/test_parser.rb
index f59cddc..0e73a26 100644
--- a/ruby/test/lox/test_parser.rb
+++ b/ruby/test/lox/test_parser.rb
@@ -90,6 +90,10 @@ class TestParser < Lox::Test
assert_parsed <<~AST.chomp, :statement, "for(var i=0; i<3; i=i+1) print i;"
(block (var i 0.0) (while (< (var i) 3.0) (block (print (var i)) (assign i (+ (var i) 1.0)))))
AST
+
+ assert_parsed <<~AST.chomp, :statement, "for(var i=0; ; i=i+1) print i;"
+ (block (var i 0.0) (while true (block (print (var i)) (assign i (+ (var i) 1.0)))))
+ AST
end
private