Class: Duby::Transform::Transformer
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #expand(fvcall, parent) ⇒ Object
- #find_ensures(type) ⇒ Object
- #find_scope(kind, before = nil) ⇒ Object
-
#initialize ⇒ Transformer
constructor
A new instance of Transformer.
- #push_jump_scope(klass, *args) ⇒ Object
- #tmp ⇒ Object
- #transform(node, parent) ⇒ Object
Constructor Details
#initialize ⇒ Transformer
Returns a new instance of Transformer.
17 18 19 20 21 |
# File 'lib/duby/transform.rb', line 17 def initialize @errors = [] @jump_scope = [] @tmp_count = 0 end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
16 17 18 |
# File 'lib/duby/transform.rb', line 16 def errors @errors end |
Instance Method Details
#expand(fvcall, parent) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/duby/transform.rb', line 71 def (fvcall, parent) result = yield self, fvcall, parent unless result.kind_of?(AST::Node) raise Error.new('Invalid macro result', fvcall.position) end result end |
#find_ensures(type) ⇒ Object
53 54 55 |
# File 'lib/duby/transform.rb', line 53 def find_ensures(type) find_scope(Duby::AST::Ensure, type) end |
#find_scope(kind, before = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/duby/transform.rb', line 38 def find_scope(kind, before=nil) found = [] @jump_scope.reverse_each do |scope| if kind === scope if before found << scope else return scope end end break if scope === before end found if before end |
#push_jump_scope(klass, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/duby/transform.rb', line 27 def push_jump_scope(klass, *args) klass.new(*args) do |node| begin @jump_scope << node yield node ensure @jump_scope.pop end end end |
#tmp ⇒ Object
23 24 25 |
# File 'lib/duby/transform.rb', line 23 def tmp "xform$#{@tmp_count += 1}" end |
#transform(node, parent) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/duby/transform.rb', line 57 def transform(node, parent) begin puts caller(0) unless node.respond_to? :transform node.transform(self, parent) rescue Error => ex @errors << ex Duby::AST::ErrorNode.new(parent, ex) rescue Exception => ex error = Error.new(ex., node.position, ex) @errors << error Duby::AST::ErrorNode.new(parent, error) end end |