using hash_key and value rules
This commit is contained in:
parent
fdb5dd4f67
commit
ff612446be
@ -10,8 +10,7 @@ module Parser
|
||||
space? >> right_bracket
|
||||
end
|
||||
|
||||
|
||||
rule(:hash_pair) { basic_type.as(:argument) >> association >> (operator_expression|value_expression).as(:element) }
|
||||
rule(:hash_pair) { basic_type.as(:hash_key) >> association >> (operator_expression|value_expression).as(:hash_value) }
|
||||
rule(:hash) { left_brace >> ((hash_pair.as(:hash_pair) >>
|
||||
(comma >> space? >> hash_pair.as(:hash_pair)).repeat(0)).repeat(0,1)).as(:hash)>>
|
||||
space? >> right_brace }
|
||||
|
@ -13,7 +13,7 @@ module Parser
|
||||
rule(:array => sequence(:array) ) { Ast::ArrayExpression.new(array) }
|
||||
rule(:element => simple(:element)) { element }
|
||||
rule(:hash => sequence(:hash) ) { Ast::HashExpression.new(hash) }
|
||||
rule(:argument => simple(:argument) , :element => simple(:element)) { Ast::AssociationExpression.new(argument,element) }
|
||||
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 }
|
||||
|
||||
rule(:argument => simple(:argument)) { argument }
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
require_relative "test_basic"
|
||||
require_relative "test_compund"
|
||||
require_relative "test_compound"
|
||||
require_relative "test_arguments"
|
||||
require_relative "test_expressions"
|
||||
require_relative "test_function_call"
|
||||
|
@ -29,14 +29,14 @@ class TestCompound < MiniTest::Test
|
||||
|
||||
def test_hash
|
||||
@string_input = '{ foo => 33 }'
|
||||
@parse_output = {:hash=>[{:hash_pair=>{:argument=>{:name=>"foo"}, :element=>{:integer=>"33"}}}]}
|
||||
@parse_output = {:hash=>[{: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
|
||||
end
|
||||
|
||||
def test_hash_list
|
||||
@string_input = "{foo => 33 , bar => 42}"
|
||||
@parse_output = {:hash=>[{:hash_pair=>{:argument=>{:name=>"foo"}, :element=>{:integer=>"33"}}}, {:hash_pair=>{:argument=>{:name=>"bar"}, :element=>{:integer=>"42"}}}]}
|
||||
@parse_output = {:hash=>[{: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
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user