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
|
end
|
||||||
|
|
||||||
rule(:while_do) do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ module Parser
|
|||||||
end
|
end
|
||||||
|
|
||||||
rule(:while => simple(:while),
|
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
|
:body => {:expressions => sequence(:body) , :end => simple(:e) }) do
|
||||||
Ast::WhileExpression.new(while_cond, body)
|
Ast::WhileExpression.new(while_cond, body)
|
||||||
end
|
end
|
||||||
|
@ -4,6 +4,7 @@ require_relative "test_arguments"
|
|||||||
require_relative "test_expressions"
|
require_relative "test_expressions"
|
||||||
require_relative "test_function_call"
|
require_relative "test_function_call"
|
||||||
require_relative "test_conditional"
|
require_relative "test_conditional"
|
||||||
|
require_relative "test_while"
|
||||||
require_relative "test_operators"
|
require_relative "test_operators"
|
||||||
require_relative "test_function_definition"
|
require_relative "test_function_definition"
|
||||||
require_relative "test_root"
|
require_relative "test_root"
|
@ -6,21 +6,21 @@ class TestWhile < MiniTest::Test
|
|||||||
|
|
||||||
def test_while
|
def test_while
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
while 1 do
|
while(1) do
|
||||||
tmp = a
|
tmp = a
|
||||||
puts(b)
|
puts(b)
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
|
|
||||||
@parse_output = {:while=>"while",
|
@parse_output = {:while=>"while",
|
||||||
:while_cond=>{:expressions=>[{:integer=>"1"}],
|
:while_cond=>{:integer=>"1"},
|
||||||
:do=>"do"},
|
:do=>"do",
|
||||||
:body=>{:expressions=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}},
|
:body=>{:expressions=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}},
|
||||||
{:function_call=>{:name=>"puts"}, :argument_list=>[{:argument=>{:name=>"b"}}]}], :end=>"end"}}
|
{:function_call=>{:name=>"puts"}, :argument_list=>[{:argument=>{:name=>"b"}}]}], :end=>"end"}}
|
||||||
@transform_output = Ast::WhileExpression.new(
|
@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::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")),
|
||||||
Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] )
|
Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] )
|
||||||
@parser = @parser.while_do
|
@parser = @parser.while_do
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user