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

#empty?Boolean

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:

  • (Boolean)


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

def empty?
  @stack.size == 0
end

#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.



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

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.



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

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.



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

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.



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

def set(value)
  @stack[@stack.length - 1] = 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.



42
43
44
# File 'lib/parser/current_arg_stack.rb', line 42

def top
  @stack.last
end