redid while with brackets and just one condition expression
This commit is contained in:
parent
e2fb0a5f34
commit
ee4d8033af
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user