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
end
def inspect
self.class.name + ".new(" + name + ")"
self.class.name + '.new("' + name + '")'
end
def attributes
[:name]

View File

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

View File

@ -39,7 +39,7 @@ module Parser
end
rule(:asignee => simple(:left) , :asigned => simple(:right) ) do
Ast::AssignmentExpression.new(left.name, right )
Ast::AssignmentExpression.new(left , right )
end
#shortcut to get the ast tree for a given string
# 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
@string_input = "a = 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
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"}}]}}
@transform_output = Ast::WhileExpression.new(
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
end
end

View File

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

View File

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