From 53a8efaa59e2eba055ccc1bbe0cfd2270e68a545 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 8 May 2014 19:49:15 +0300 Subject: [PATCH] get the conditionals to work again --- lib/parser/basic_types.rb | 4 ++-- lib/parser/composed.rb | 6 +++--- test/parser/test_conditional.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/parser/basic_types.rb b/lib/parser/basic_types.rb index 8cc9d21c..fa0214b4 100644 --- a/lib/parser/basic_types.rb +++ b/lib/parser/basic_types.rb @@ -8,11 +8,11 @@ module Parser # rule of thumb is that anything eats space behind it, but only space, no newlines rule(:space) { (str('\t') | str(' ')).repeat(1) } rule(:space?) { space.maybe } - rule(:newline){ str('\n') } + rule(:newline){ str("\n") >> space?} rule(:comment){ match('#') >> (newline.absent? >> any).repeat.as(:comment) >> newline } - rule(:eol) { (newline >> space?) | any.absent? } + rule(:eol) { newline | any.absent? } rule(:double_quote){ str('"') } rule(:minus) { str('-') } diff --git a/lib/parser/composed.rb b/lib/parser/composed.rb index a69eb5c9..6eba0000 100644 --- a/lib/parser/composed.rb +++ b/lib/parser/composed.rb @@ -30,14 +30,14 @@ module Parser #| (name >> space? >> equal_sign.absent?) rule(:simple_expression) { function_call | integer | string | name } - rule(:expression) { conditional | simple_expression } + rule(:expression) { (conditional | simple_expression ) >> newline.maybe } def delimited_expressions( delimit ) - ( (delimit.absent? >> (assignment | expression)).repeat(1)).as(:expressions) >> delimit + ( (delimit.absent? >> (assignment | expression)).repeat(1)).as(:expressions) >> delimit >> newline.maybe end rule(:conditional) { - keyword_if >> left_parenthesis >> expression.as(:conditional) >> right_parenthesis >> + keyword_if >> left_parenthesis >> expression.as(:conditional) >> right_parenthesis >> newline >> delimited_expressions(keyword_else).as(:if_true) >> delimited_expressions(keyword_end).as(:if_false) } diff --git a/test/parser/test_conditional.rb b/test/parser/test_conditional.rb index e7877f78..1a502d7f 100644 --- a/test/parser/test_conditional.rb +++ b/test/parser/test_conditional.rb @@ -6,7 +6,7 @@ class TestConditional < MiniTest::Test def test_conditional @string_input = <