Class: NScript::TryNode

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

Constant Summary

Constants inherited from Node

Node::TAB

Instance Attribute Summary collapse

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(try, error, recovery, finally = nil) ⇒ TryNode

Returns a new instance of TryNode.



791
792
793
# File 'lib/nscript/parser/nodes.rb', line 791

def initialize(try, error, recovery, finally=nil)
  @try, @error, @recovery, @finally = try, error, recovery, finally
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



788
789
790
# File 'lib/nscript/parser/nodes.rb', line 788

def error
  @error
end

Instance Method Details

#compile_node(o) ⇒ Object



795
796
797
798
799
800
801
802
# File 'lib/nscript/parser/nodes.rb', line 795

def compile_node(o)
  o[:indent] = idt(1)
  o[:top] = true
  error_part = @error ? " (#{@error}) " : ' '
  catch_part = @recovery &&  " catch#{error_part}{\n#{@recovery.compile(o)}\n#{idt}}"
  finally_part = @finally && " finally {\n#{@finally.compile(o.merge(:return => nil))}\n#{idt}}"
  write("#{idt}try {\n#{@try.compile(o)}\n#{idt}}#{catch_part}#{finally_part}")
end