Class: Depager::LALR::State
- Inherits:
-
Object
- Object
- Depager::LALR::State
- Defined in:
- lib/depager/lr.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#n ⇒ Object
Returns the value of attribute n.
Class Method Summary collapse
Instance Method Summary collapse
- #closure ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean (also: #==)
- #gg ⇒ Object
- #goto(x) ⇒ Object
- #hash ⇒ Object
-
#initialize(items, n = nil) ⇒ State
constructor
A new instance of State.
- #mkgoto ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(items, n = nil) ⇒ State
Returns a new instance of State.
193 194 195 196 197 198 199 |
# File 'lib/depager/lr.rb', line 193 def initialize(items, n = nil) @items = items @goto = {} @n = n @closure = nil @_hash = nil end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
191 192 193 |
# File 'lib/depager/lr.rb', line 191 def items @items end |
#n ⇒ Object
Returns the value of attribute n.
191 192 193 |
# File 'lib/depager/lr.rb', line 191 def n @n end |
Class Method Details
Instance Method Details
#closure ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'lib/depager/lr.rb', line 224 def closure return @closure if @closure r = [] @items.each do |i| r |= i.closure end @closure = r end |
#empty? ⇒ Boolean
216 217 218 |
# File 'lib/depager/lr.rb', line 216 def empty? @items.empty? end |
#eql?(other) ⇒ Boolean Also known as: ==
207 208 209 |
# File 'lib/depager/lr.rb', line 207 def eql?(other) @items == other.items end |
#gg ⇒ Object
234 235 236 |
# File 'lib/depager/lr.rb', line 234 def gg @goto end |
#goto(x) ⇒ Object
248 249 250 |
# File 'lib/depager/lr.rb', line 248 def goto(x) @goto[x] || State.new([]) end |
#hash ⇒ Object
201 202 203 204 205 |
# File 'lib/depager/lr.rb', line 201 def hash return @_hash if @_hash @_hash = @items.hash end |
#mkgoto ⇒ Object
238 239 240 241 242 243 244 245 246 |
# File 'lib/depager/lr.rb', line 238 def mkgoto r = Hash.new { |h, k| h[k] = [] } closure.each do |c| r[c.dotsym].push LRItem[c.rule, c.n + 1] if c.n < c.rule.rhs.size end r.map do |k, v| [k, (@goto[k] = State.new(v.sort_by { |it| [it.rule.n, it.n] }))] end end |
#to_s ⇒ Object
212 213 214 |
# File 'lib/depager/lr.rb', line 212 def to_s format("I%03i = \n", n) << @items.map(&:to_s).join("\n").lines.map { |i| " #{i}" }.join end |