get the conditionals to work again
This commit is contained in:
parent
b82c2241b7
commit
53a8efaa59
@ -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('-') }
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ class TestConditional < MiniTest::Test
|
||||
|
||||
def test_conditional
|
||||
@string_input = <<HERE
|
||||
if (0)
|
||||
if(0)
|
||||
42
|
||||
else
|
||||
667
|
||||
|
Loading…
Reference in New Issue
Block a user