Class: IDL::Engine::ProductionStack
- Inherits:
-
Object
- Object
- IDL::Engine::ProductionStack
- Defined in:
- lib/ridl/runner.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #empty? ⇒ Boolean
- #has?(id) ⇒ Boolean
-
#initialize ⇒ ProductionStack
constructor
A new instance of ProductionStack.
- #peek ⇒ Object
- #pop ⇒ Object
- #push(id, prod) ⇒ Object
- #remove(id) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ ProductionStack
Returns a new instance of ProductionStack.
38 39 40 41 |
# File 'lib/ridl/runner.rb', line 38 def initialize @stack = [] @index = {} end |
Instance Method Details
#[](id) ⇒ Object
83 84 85 |
# File 'lib/ridl/runner.rb', line 83 def [](id) @stack[@index[id.to_sym]].last end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/ridl/runner.rb', line 47 def empty? @stack.empty? end |
#has?(id) ⇒ Boolean
79 80 81 |
# File 'lib/ridl/runner.rb', line 79 def has?(id) @index.has_key?(id.to_sym) end |
#peek ⇒ Object
64 65 66 67 68 69 |
# File 'lib/ridl/runner.rb', line 64 def peek return nil if empty? id, _ = @stack.first id end |
#pop ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ridl/runner.rb', line 56 def pop return nil if empty? id, prod = @stack.shift @index.delete(id) prod end |
#push(id, prod) ⇒ Object
51 52 53 54 |
# File 'lib/ridl/runner.rb', line 51 def push(id, prod) @index[id.to_sym] = @stack.size @stack << [id.to_sym, prod] end |
#remove(id) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/ridl/runner.rb', line 71 def remove(id) return nil unless has?(id) i = @index.delete(id.to_sym) _, producer = @productionstack.delete(i) producer end |
#size ⇒ Object
43 44 45 |
# File 'lib/ridl/runner.rb', line 43 def size @stack.size end |