Class: Stupidedi::Builder::IdentifierStack::ST

Inherits:
Object
  • Object
show all
Defined in:
lib/stupidedi/builder/identifier_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, id) ⇒ ST

Returns a new instance of ST


110
111
112
# File 'lib/stupidedi/builder/identifier_stack.rb', line 110

def initialize(parent, id)
  @sequence, @parent, @id = 0, parent, id
end

Instance Attribute Details

#sequence=(value) (writeonly)

Sets the attribute sequence

Parameters:

  • value

    the value to set the attribute sequence to.


108
109
110
# File 'lib/stupidedi/builder/identifier_stack.rb', line 108

def sequence=(value)
  @sequence = value
end

Instance Method Details

#count(builder)

Number of segments (ST..SE)


123
124
125
126
127
128
129
130
131
132
133
# File 'lib/stupidedi/builder/identifier_stack.rb', line 123

def count(builder)
  m = Either.success(builder.machine)

  while m.defined?
    if m.flatmap(&:segment).map{|s| s.node.id == :ST }.fetch(false)
      return m.flatmap{|n| n.distance(builder.machine) }.fetch(0) + 2
    else
      m = m.flatmap(&:parent)
    end
  end
end

#hl


114
115
116
# File 'lib/stupidedi/builder/identifier_stack.rb', line 114

def hl
  HL.new(self, @sequence += 1)
end

#id


118
119
120
# File 'lib/stupidedi/builder/identifier_stack.rb', line 118

def id
  @id.to_s.rjust(4, "0")
end

#pop


135
136
137
# File 'lib/stupidedi/builder/identifier_stack.rb', line 135

def pop
  @parent
end