rename conditional to control in parser
This commit is contained in:
parent
7940efc64d
commit
e2fb0a5f34
@ -12,6 +12,4 @@ module Ast
|
||||
[:cond, :if_true, :if_false]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -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 >>
|
@ -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
|
||||
|
@ -20,24 +20,4 @@ HERE
|
||||
|
||||
@parser = @parser.conditional
|
||||
end
|
||||
|
||||
def test_while
|
||||
@string_input = <<HERE
|
||||
while 1 do
|
||||
tmp = a
|
||||
puts(b)
|
||||
end
|
||||
HERE
|
||||
|
||||
@parse_output = {:while=>"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
|
26
test/parser/test_while.rb
Normal file
26
test/parser/test_while.rb
Normal file
@ -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 = <<HERE
|
||||
while 1 do
|
||||
tmp = a
|
||||
puts(b)
|
||||
end
|
||||
HERE
|
||||
|
||||
@parse_output = {:while=>"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
|
Loading…
Reference in New Issue
Block a user