Implicit returns for class methods

gets us parsing of parfaits second file data_object
This commit is contained in:
2019-08-19 15:56:15 +03:00
parent d5d1df951c
commit 0e694a38f7
6 changed files with 48 additions and 25 deletions

View File

@ -2,7 +2,8 @@ module Ruby
class ClassMethodStatement < MethodStatement
def to_vool
Vool::ClassMethodExpression.new( @name , @args.dup , @body.to_vool)
body = normalized_body
Vool::ClassMethodExpression.new( @name , @args.dup , body.to_vool)
end
def to_s(depth = 0)

View File

@ -8,13 +8,17 @@ module Ruby
@clazz = clazz
end
# At the moment normalizing means creating implicit returns for some cases
# see replace_return for details.
def normalized_body
return replace_return( @body ) unless @body.is_a?(Statements)
body = Statements.new( @body.statements.dup )
body << replace_return( body.pop )
end
def to_vool
if @body.is_a?(Statements)
@body << replace_return( @body.pop )
else
@body = replace_return( @body )
end
Vool::MethodExpression.new( @name , @args.dup , @body.to_vool)
body = normalized_body
Vool::MethodExpression.new( @name , @args.dup , body.to_vool)
end
def replace_return(statement)