fix and test function transform without braces

This commit is contained in:
Torsten Ruger 2014-06-26 12:46:34 +03:00
parent 9a1dd3ba1d
commit edd77bc218
2 changed files with 16 additions and 0 deletions

View File

@ -57,6 +57,11 @@ module Parser
Ast::FunctionExpression.new(function_name.name, parameter_list, expressions)
end
rule(:function_name => simple(:function_name),
:expressions => sequence(:expressions) , :end => simple(:e)) do
Ast::FunctionExpression.new(function_name.name, [], expressions)
end
rule(:receiver=> simple(:receiver),
:function_name => simple(:function_name),
:parameter_list => sequence(:parameter_list),

View File

@ -15,6 +15,17 @@ HERE
@parser = @parser
end
def test_function_no_braces
@string_input = <<HERE
def foo
5
end
HERE
@parse_output = {:expression_list=>[{:function_name=>{:name=>"foo"}, :expressions=>[{:integer=>"5"}], :end=>"end"}]}
@transform_output = Ast::ExpressionList.new( [Ast::FunctionExpression.new(:foo, [] , [Ast::IntegerExpression.new(5)] ,nil )])
@parser = @parser
end
def test_class_function
@string_input = <<HERE
def String.length(x)