Method: ANTLR3::AST::BaseTree#walk

Defined in:
lib/antlr3/tree.rb

#walkObject



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/antlr3/tree.rb', line 417

def walk
  block_given? or return( enum_for( :walk ) )
  stack = []
  cursor = self
  while true
    begin
      yield( cursor )
      stack.push( Array[ *cursor ] ) unless cursor.empty?
    rescue StopIteration
      # skips adding children to prune the node
    ensure
      break if stack.empty?
      cursor = stack.last.shift
      stack.pop if stack.last.empty?
    end
  end
  return self
end