Class: Taipo::Parser::Stack Private
- Inherits:
-
Array
- Object
- Array
- Taipo::Parser::Stack
- 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
Instance Method Summary collapse
-
#add_child ⇒ Taipo::Parser::Stack
private
Add a TypeElements object to the top of the stack.
-
#add_children ⇒ Taipo::Parser::Stack
private
Add a TypeElement::Children object to the top of the stack.
-
#add_constraint(name:, value:) ⇒ Taipo::Parser::Stack
private
Add a TypeElement::Constraint object to the top of the stack.
-
#add_constraints ⇒ Taipo::Parser::Stack
private
Add a TypeElement::Constraints object to the top of the stack.
-
#add_element(name:) ⇒ Taipo::Parser::Stack
private
Add a TypeElement object to the top of the stack.
-
#initialize ⇒ Stack
constructor
private
Initialize the stack.
-
#remove_children ⇒ Taipo::TypeElement::Children
private
Remove a TypeElement::Children object from the top of the stack.
-
#remove_constraints ⇒ Taipo::TypeElement::Constraints
private
Remove a TypeElement::Constraints object from the top of the stack.
-
#result ⇒ Taipo::TypeElements
private
Return the resulting TypeElements object.
-
#update_element(method, arg) ⇒ Taipo::Parser::Stack
private
Update the TypeElement object at the top of the stack.
Constructor Details
#initialize ⇒ 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.
Initialize the stack
20 21 22 |
# File 'lib/taipo/parser/stack.rb', line 20 def initialize self.push Taipo::TypeElements.new end |
Instance Method Details
#add_child ⇒ 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.
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
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_children ⇒ 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.
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
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
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_constraints ⇒ 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::Constraints object to the top of the stack
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
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_children ⇒ Taipo::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.
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
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_constraints ⇒ Taipo::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
105 106 107 |
# File 'lib/taipo/parser/stack.rb', line 105 def remove_constraints self.pop end |
#result ⇒ Taipo::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.
This should not be called until parsing is complete.
Return the resulting TypeElements object
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
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 |