get the conditionals to work again

This commit is contained in:
Torsten Ruger 2014-05-08 19:49:15 +03:00
parent b82c2241b7
commit 53a8efaa59
3 changed files with 6 additions and 6 deletions

View File

@ -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('-') }

View File

@ -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)
}

View File

@ -6,7 +6,7 @@ class TestConditional < MiniTest::Test
def test_conditional
@string_input = <<HERE
if (0)
if(0)
42
else
667