Class: Taipo::Parser::Stack Private

Inherits:
Array
  • Object
show all
Defined in:
lib/taipo/parser/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.

A stack of parsed or partially parsed elements

Since:

  • 1.4.0

Instance Method Summary collapse

Constructor Details

#initializeStack

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.

Initialize the stack

Since:

  • 1.4.0



20
21
22
# File 'lib/taipo/parser/stack.rb', line 20

def initialize
  self.push Taipo::TypeElements.new
end

Instance Method Details

#add_childTaipo::Parser::Stack

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.

Note:

Due to the way Taipo::Parser is implemented, this method first removes the child that is at the top of the stack, adds that to the set of children and then add a new child.

Add a TypeElements object to the top of the stack

Returns:

Since:

  • 1.4.0



82
83
84
85
86
# File 'lib/taipo/parser/stack.rb', line 82

def add_child
  child = self.pop
  self.last.push child
  self.push Taipo::TypeElements.new
end

#add_childrenTaipo::Parser::Stack

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.

Note:

Due to the way Taipo::Parser is implemented, this method will also add an empty TypeElements object to the stack. This represents the first (and possibly only) component of the collection.

Add a TypeElement::Children object to the top of the stack

Returns:

Since:

  • 1.4.0



51
52
53
54
# File 'lib/taipo/parser/stack.rb', line 51

def add_children
  self.push Taipo::TypeElement::Children.new
  self.push Taipo::TypeElements.new
end

#add_constraint(name:, value:) ⇒ Taipo::Parser::Stack

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.

Add a TypeElement::Constraint object to the top of the stack

Returns:

Since:

  • 1.4.0



115
116
117
118
119
# File 'lib/taipo/parser/stack.rb', line 115

def add_constraint(name:, value:)
  self.last.push Taipo::TypeElement::Constraint.new(name: name,
                                                    value: value)
  self
end

#add_constraintsTaipo::Parser::Stack

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.

Add a TypeElement::Constraints object to the top of the stack

Returns:

Since:

  • 1.4.0



94
95
96
# File 'lib/taipo/parser/stack.rb', line 94

def add_constraints
  self.push Taipo::TypeElement::Constraints.new
end

#add_element(name:) ⇒ Taipo::Parser::Stack

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.

Add a TypeElement object to the top of the stack

Returns:

Since:

  • 1.4.0



127
128
129
130
# File 'lib/taipo/parser/stack.rb', line 127

def add_element(name:)
  self.last.push Taipo::TypeElement.new(name: name)
  self
end

#remove_childrenTaipo::TypeElement::Children

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.

Note:

Due to the way Taipo::Parser is implemented, this method first removes the child that is at the top of the stack, adds that to the set of children and then returns the children.

Remove a TypeElement::Children object from the top of the stack

Returns:

Since:

  • 1.4.0



66
67
68
69
70
# File 'lib/taipo/parser/stack.rb', line 66

def remove_children
  child = self.pop
  self.last.push child
  self.pop
end

#remove_constraintsTaipo::TypeElement::Constraints

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.

Remove a TypeElement::Constraints object from the top of the stack

Returns:

Since:

  • 1.4.0



105
106
107
# File 'lib/taipo/parser/stack.rb', line 105

def remove_constraints
  self.pop
end

#resultTaipo::TypeElements

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.

Note:

This should not be called until parsing is complete.

Return the resulting TypeElements object

Returns:

Raises:

  • (RuntimeError)

    if there is more than one element in the stack

Since:

  • 1.4.0



35
36
37
38
39
# File 'lib/taipo/parser/stack.rb', line 35

def result
  msg = "Something went wrong. There should only be one element left."
  raise RuntimeError, msg if self.size != 1
  self.first
end

#update_element(method, arg) ⇒ Taipo::Parser::Stack

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.

Update the TypeElement object at the top of the stack

Returns:

Since:

  • 1.4.0



138
139
140
141
# File 'lib/taipo/parser/stack.rb', line 138

def update_element(method, arg)
  self.last.last.send method, arg
  self
end