redid while with brackets and just one condition expression

This commit is contained in:
Torsten Ruger 2014-05-12 12:26:38 +03:00
parent e2fb0a5f34
commit ee4d8033af
4 changed files with 12 additions and 9 deletions

View File

@ -7,7 +7,9 @@ module Parser
end
rule(:while_do) do
keyword_while >> expressions_do.as(:while_cond) >> expressions_end.as(:body)
keyword_while >> left_parenthesis >> expression.as(:while_cond) >> right_parenthesis >>
keyword_do >> newline >>
expressions_end.as(:body)
end
end
end

View File

@ -25,7 +25,7 @@ module Parser
end
rule(:while => simple(:while),
:while_cond => { :expressions => sequence(:while_cond) , :do => simple(:do)} ,
:while_cond => simple(:while_cond) , :do => simple(:do) ,
:body => {:expressions => sequence(:body) , :end => simple(:e) }) do
Ast::WhileExpression.new(while_cond, body)
end

View File

@ -4,6 +4,7 @@ require_relative "test_arguments"
require_relative "test_expressions"
require_relative "test_function_call"
require_relative "test_conditional"
require_relative "test_while"
require_relative "test_operators"
require_relative "test_function_definition"
require_relative "test_root"

View File

@ -6,19 +6,19 @@ class TestWhile < MiniTest::Test
def test_while
@string_input = <<HERE
while 1 do
while(1) do
tmp = a
puts(b)
end
HERE
@parse_output = {:while=>"while",
:while_cond=>{:expressions=>[{:integer=>"1"}],
:do=>"do"},
:while_cond=>{:integer=>"1"},
:do=>"do",
:body=>{:expressions=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}},
{:function_call=>{:name=>"puts"}, :argument_list=>[{:argument=>{:name=>"b"}}]}], :end=>"end"}}
@transform_output = Ast::WhileExpression.new(
[Ast::IntegerExpression.new(1)],
Ast::IntegerExpression.new(1),
[Ast::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")),
Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] )
@parser = @parser.while_do