leave assignee as name_expression in assignment, fix tests accordingly

This commit is contained in:
Torsten Ruger 2014-05-10 19:11:32 +03:00
parent 47f1608685
commit 6378209f33
7 changed files with 12 additions and 11 deletions

View File

@ -29,7 +29,7 @@ module Ast
variable variable
end end
def inspect def inspect
self.class.name + ".new(" + name + ")" self.class.name + '.new("' + name + '")'
end end
def attributes def attributes
[:name] [:name]

View File

@ -31,7 +31,7 @@ module Ast
@assignee, @assigned = assignee, assigned @assignee, @assigned = assignee, assigned
end end
def inspect def inspect
self.class.name + ".new(" + assignee + ", " + assigned.inspect+ ")" self.class.name + ".new(" + assignee.inspect + ", " + assigned.inspect + ")"
end end
def compile context def compile context

View File

@ -39,7 +39,7 @@ module Parser
end end
rule(:asignee => simple(:left) , :asigned => simple(:right) ) do rule(:asignee => simple(:left) , :asigned => simple(:right) ) do
Ast::AssignmentExpression.new(left.name, right ) Ast::AssignmentExpression.new(left , right )
end end
#shortcut to get the ast tree for a given string #shortcut to get the ast tree for a given string
# optional second arguement specifies a rule that will be parsed (mainly for testing) # optional second arguement specifies a rule that will be parsed (mainly for testing)

View File

@ -46,7 +46,7 @@ class TestBasic < MiniTest::Test
def test_assignment def test_assignment
@string_input = "a = 5" @string_input = "a = 5"
@parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } } @parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
@transform_output = Ast::AssignmentExpression.new("a", Ast::IntegerExpression.new(5) ) @transform_output = Ast::AssignmentExpression.new(Ast::NameExpression.new("a"), Ast::IntegerExpression.new(5))
@parser = @parser.assignment @parser = @parser.assignment
end end

View File

@ -36,7 +36,9 @@ HERE
@parse_output = {:while=>"while", :while_cond=>{:integer=>"1"}, :do=>"do", :body=>{:expressions=>[{:asignee=>{:name=>"tmp"}, :asigned=>{:name=>"a"}}, {:asignee=>{:name=>"a"}, :asigned=>{:name=>"b"}}]}} @parse_output = {:while=>"while", :while_cond=>{:integer=>"1"}, :do=>"do", :body=>{:expressions=>[{:asignee=>{:name=>"tmp"}, :asigned=>{:name=>"a"}}, {:asignee=>{:name=>"a"}, :asigned=>{:name=>"b"}}]}}
@transform_output = Ast::WhileExpression.new( @transform_output = Ast::WhileExpression.new(
Ast::IntegerExpression.new(1), Ast::IntegerExpression.new(1),
[Ast::AssignmentExpression.new("tmp", Ast::NameExpression.new("a")), Ast::AssignmentExpression.new("a", Ast::NameExpression.new("b"))] ) [Ast::AssignmentExpression.new(Ast::NameExpression.new("tmp"),
Ast::NameExpression.new("a")),
Ast::AssignmentExpression.new(Ast::NameExpression.new("a"), Ast::NameExpression.new("b"))] )
@parser = @parser.while @parser = @parser.while
end end
end end

View File

@ -29,8 +29,8 @@ HERE
:parmeter_list => [{ :parmeter => { :name => "x" } }], :parmeter_list => [{ :parmeter => { :name => "x" } }],
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ] :expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
} }
@transform_output = Ast::FunctionExpression.new( "foo", [Ast::NameExpression.new("x")], @transform_output = Ast::FunctionExpression.new(:foo, [Ast::NameExpression.new("x")] ,
[Ast::AssignmentExpression.new( "abba", Ast::IntegerExpression.new(5) ) ]) [Ast::AssignmentExpression.new(Ast::NameExpression.new("abba"), Ast::IntegerExpression.new(5))] )
@parser = @parser.function_definition @parser = @parser.function_definition
end end

View File

@ -16,10 +16,9 @@ HERE
{:function_definition=> { :name=>"foo"}, :parmeter_list => [ {:parmeter=>{:name=>"x"}} ] , {:function_definition=> { :name=>"foo"}, :parmeter_list => [ {:parmeter=>{:name=>"x"}} ] ,
:expressions=>[{:asignee=>{:name=>"a"}, :asigned=>{:integer=>"5"} } ] } , :expressions=>[{:asignee=>{:name=>"a"}, :asigned=>{:integer=>"5"} } ] } ,
{:function_call => { :name => "foo" }, :argument_list => [ { :argument => { :integer => "3" } } ] }] {:function_call => { :name => "foo" }, :argument_list => [ { :argument => { :integer => "3" } } ] }]
@transform_output = [ Ast::FunctionExpression.new("foo" , @transform_output = [Ast::FunctionExpression.new(:foo, [Ast::NameExpression.new("x")] ,
[Ast::NameExpression.new("x")] , [Ast::AssignmentExpression.new(Ast::NameExpression.new("a"), Ast::IntegerExpression.new(5))] ),
[Ast::AssignmentExpression.new( "a", Ast::IntegerExpression.new(5)) ] ) , Ast::FuncallExpression.new("foo", [Ast::IntegerExpression.new(3)] )]
Ast::FuncallExpression.new( "foo", [ Ast::IntegerExpression.new(3) ] ) ]
end end