Class: Ripper::RubyBuilder::Stack

Inherits:
Array show all
Defined in:
lib/ripper/ruby_builder/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#flush

Constructor Details

#initializeStack

Returns a new instance of Stack.



49
50
51
52
# File 'lib/ripper/ruby_builder/stack.rb', line 49

def initialize
  @queue = Queue.new
  @buffer = Buffer.new
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



47
48
49
# File 'lib/ripper/ruby_builder/stack.rb', line 47

def buffer
  @buffer
end

#queueObject (readonly)

Returns the value of attribute queue.



47
48
49
# File 'lib/ripper/ruby_builder/stack.rb', line 47

def queue
  @queue
end

Instance Method Details

#_popObject



62
# File 'lib/ripper/ruby_builder/stack.rb', line 62

alias :_pop :pop

#pop(*types) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ripper/ruby_builder/stack.rb', line 63

def pop(*types)
  options = types.last.is_a?(::Hash) ? types.pop : {}
  max, pass, revert = options.delete_at(:max, :pass, :reverse)
  ignored, tokens = [], []
  reverse! if revert

  while !empty? && !(max && tokens.length >= max)
    if types.include?(last.type) && matches?(options)
      tokens << _pop()
    elsif last.opener? && !pass
      break
    else
      ignored.unshift(_pop())
    end
  end

  replace(self + ignored)
  reverse! if revert
  tokens
end

#push(token) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/ripper/ruby_builder/stack.rb', line 54

def push(token)
  return token if buffer.aggregate(token)
  tokens = queue << token
  tokens.each do |token|
    self << token
  end
end