Class: StyleScript::TryNode

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

Overview

A try/catch/finally block.

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.



921
922
923
# File 'lib/style_script/nodes.rb', line 921

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.



918
919
920
# File 'lib/style_script/nodes.rb', line 918

def error
  @error
end

Instance Method Details

#compile_node(o) ⇒ Object



925
926
927
928
929
930
931
932
# File 'lib/style_script/nodes.rb', line 925

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