Class: Parser::CurrentArgStack Private

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/current_arg_stack.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Stack that holds names of current arguments, i.e. while parsing

def m1(a = (def m2(b = def m3(c = 1); end); end)); end
                                ^

stack is [:a, :b, :c]

Emulates ‘p->cur_arg` in MRI’s parse.y

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCurrentArgStack

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CurrentArgStack.



17
18
19
20
# File 'lib/parser/current_arg_stack.rb', line 17

def initialize
  @stack = []
  freeze
end

Instance Attribute Details

#stackObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/parser/current_arg_stack.rb', line 15

def stack
  @stack
end

Instance Method Details

#popObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
# File 'lib/parser/current_arg_stack.rb', line 31

def pop
  @stack.pop
end

#push(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/parser/current_arg_stack.rb', line 22

def push(value)
  @stack << value
end

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
# File 'lib/parser/current_arg_stack.rb', line 35

def reset
  @stack.clear
end

#set(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
# File 'lib/parser/current_arg_stack.rb', line 26

def set(value)
  pop
  push(value)
end

#topObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/parser/current_arg_stack.rb', line 39

def top
  @stack.last
end