diff --git a/lib/parser/transform.rb b/lib/parser/transform.rb index 321eb25b..5e09691e 100644 --- a/lib/parser/transform.rb +++ b/lib/parser/transform.rb @@ -10,9 +10,9 @@ module Parser rule(:integer => simple(:value)) { Ast::IntegerExpression.new(value.to_i) } rule(:name => simple(:name)) { Ast::NameExpression.new(name.to_s) } - rule(:array => sequence(:array) ) { Ast::ArrayExpression.new(array) } + rule(:array_constant => sequence(:array_constant) ) { Ast::ArrayExpression.new(array_constant) } rule(:array_element => simple(:array_element)) { array_element } - rule(:hash => sequence(:hash) ) { Ast::HashExpression.new(hash) } + rule(:hash_constant => sequence(:hash_constant) ) { Ast::HashExpression.new(hash_constant) } rule(:hash_key => simple(:hash_key) , :hash_value => simple(:hash_value)) { Ast::AssociationExpression.new(hash_key,hash_value) } rule(:hash_pair => simple(:hash_pair) ) { hash_pair } diff --git a/test/parser/test_all.rb b/test/parser/test_all.rb index 39e8767c..9a092f6c 100644 --- a/test/parser/test_all.rb +++ b/test/parser/test_all.rb @@ -1,6 +1,6 @@ require_relative "test_basic" -#require_relative "test_compound" +require_relative "test_compound" require_relative "test_arguments" require_relative "test_expressions" require_relative "test_call_site" diff --git a/test/parser/test_compound.rb b/test/parser/test_compound.rb index 4604b61e..03121e7d 100644 --- a/test/parser/test_compound.rb +++ b/test/parser/test_compound.rb @@ -6,39 +6,39 @@ class TestCompound < MiniTest::Test def test_one_array @string_input = '[42]' - @parse_output = {:array=>[{:array_element=>{:integer=>"42"}}]} + @parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}]} @transform_output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42)]) - @parser = @parser.array + @parser = @parser.array_constant end def test_array_list @string_input = '[42, foo]' - @parse_output = {:array=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]} + @parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]} @transform_output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo")]) - @parser = @parser.array + @parser = @parser.array_constant end def test_array_ops @string_input = '[ 3 + 4 , foo(22) ]' - @parse_output = {:array=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]} + @parse_output = {:array_constant=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]} @transform_output = Ast::ArrayExpression.new( [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)), Ast::CallSiteExpression.new("foo", [Ast::IntegerExpression.new(22)] )]) - @parser = @parser.array + @parser = @parser.array_constant end def test_hash @string_input = '{ foo => 33 }' - @parse_output = {:hash=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]} + @parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]} @transform_output = Ast::HashExpression.new([Ast::AssociationExpression.new(Ast::NameExpression.new("foo") , Ast::IntegerExpression.new(33))]) - @parser = @parser.hash + @parser = @parser.hash_constant end def test_hash_list @string_input = "{foo => 33 , bar => 42}" - @parse_output = {:hash=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]} + @parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]} @transform_output = Ast::HashExpression.new([Ast::AssociationExpression.new(Ast::NameExpression.new("foo") , Ast::IntegerExpression.new(33)),Ast::AssociationExpression.new(Ast::NameExpression.new("bar") , Ast::IntegerExpression.new(42))]) - @parser = @parser.hash + @parser = @parser.hash_constant end end \ No newline at end of file