Class: NScript::ReturnNode

Inherits:
Node
  • Object
show all
Defined in:
lib/nscript/parser/nodes.rb

Constant Summary

Constants inherited from Node

Node::TAB

Instance Method Summary collapse

Methods inherited from Node

#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write

Constructor Details

#initialize(expression) ⇒ ReturnNode

Returns a new instance of ReturnNode.



175
176
177
# File 'lib/nscript/parser/nodes.rb', line 175

def initialize(expression)
  @expression = expression
end

Instance Method Details

#compile_node(o) ⇒ Object



179
180
181
182
183
# File 'lib/nscript/parser/nodes.rb', line 179

def compile_node(o)
  return write(@expression.compile(o.merge(:return => true))) if @expression.statement?
  compiled = @expression.compile(o)
  write(@expression.statement? ? "#{compiled}\n#{idt}return null;" : "#{idt}return #{compiled};")
end