From e2fb0a5f3447661f24144825bfcc9da2466e4b30 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 12 May 2014 12:20:31 +0300 Subject: [PATCH] rename conditional to control in parser --- lib/ast/conditional_expression.rb | 2 -- lib/parser/{conditional.rb => control.rb} | 2 +- lib/parser/crystal.rb | 4 ++-- test/parser/test_conditional.rb | 20 ----------------- test/parser/test_while.rb | 26 +++++++++++++++++++++++ 5 files changed, 29 insertions(+), 25 deletions(-) rename lib/parser/{conditional.rb => control.rb} (94%) create mode 100644 test/parser/test_while.rb diff --git a/lib/ast/conditional_expression.rb b/lib/ast/conditional_expression.rb index 9891ab7e..25bdac11 100644 --- a/lib/ast/conditional_expression.rb +++ b/lib/ast/conditional_expression.rb @@ -12,6 +12,4 @@ module Ast [:cond, :if_true, :if_false] end end - - end \ No newline at end of file diff --git a/lib/parser/conditional.rb b/lib/parser/control.rb similarity index 94% rename from lib/parser/conditional.rb rename to lib/parser/control.rb index fd166740..43137fac 100644 --- a/lib/parser/conditional.rb +++ b/lib/parser/control.rb @@ -1,5 +1,5 @@ module Parser - module Conditional + module Control include Parslet rule(:conditional) do keyword_if >> left_parenthesis >> expression.as(:conditional) >> right_parenthesis >> newline >> diff --git a/lib/parser/crystal.rb b/lib/parser/crystal.rb index 7ecfe09f..440c714a 100644 --- a/lib/parser/crystal.rb +++ b/lib/parser/crystal.rb @@ -1,7 +1,7 @@ require_relative "basic_types" require_relative "tokens" require_relative "keywords" -require_relative "conditional" +require_relative "control" require_relative "expression" require_relative "function_call" require_relative "function_definition" @@ -21,7 +21,7 @@ module Parser include BasicTypes include Tokens include Keywords - include Conditional + include Control include Expression include FunctionCall include FunctionDefinition diff --git a/test/parser/test_conditional.rb b/test/parser/test_conditional.rb index bcb9177a..8c48044b 100644 --- a/test/parser/test_conditional.rb +++ b/test/parser/test_conditional.rb @@ -20,24 +20,4 @@ HERE @parser = @parser.conditional end - - def test_while - @string_input = <"while", - :while_cond=>{:expressions=>[{: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::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")), - Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] ) - @parser = @parser.while_do - end end \ No newline at end of file diff --git a/test/parser/test_while.rb b/test/parser/test_while.rb new file mode 100644 index 00000000..9acd9389 --- /dev/null +++ b/test/parser/test_while.rb @@ -0,0 +1,26 @@ +require_relative "helper" + +class TestWhile < MiniTest::Test + # include the magic (setup and parse -> test method translation), see there + include ParserHelper + + def test_while + @string_input = <"while", + :while_cond=>{:expressions=>[{: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::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")), + Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] ) + @parser = @parser.while_do + end +end \ No newline at end of file