Class: ArrayPredictionContext

Inherits:
PredictionContext show all
Defined in:
lib/antlr4/PredictionContext.rb

Constant Summary

Constants inherited from PredictionContext

PredictionContext::EMPTY_RETURN_STATE

Instance Attribute Summary

Attributes inherited from PredictionContext

#cachedHashCode

Instance Method Summary collapse

Methods inherited from PredictionContext

EMPTY, EMPTY_RETURN_STATE, calculateEmptyHashCode, calculateHashCode, #hasEmptyPath, #hash, #initialize

Constructor Details

This class inherits a constructor from PredictionContext

Instance Method Details

#==(other) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/antlr4/PredictionContext.rb', line 229

def ==(other)
    return false if self.class != other.class
    return true if self.equal?(other)
    if self.hash != other.hash
        false # can't be same if hash is different
    else
        self.returnStates==other.returnStates and self.parents==other.parents
    end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


226
227
228
# File 'lib/antlr4/PredictionContext.rb', line 226

def eql?(other)
  self == other
end

#getParent(index) ⇒ Object



220
221
222
# File 'lib/antlr4/PredictionContext.rb', line 220

def getParent(index)
    return self.parents[index]
end

#getReturnState(index) ⇒ Object



223
224
225
# File 'lib/antlr4/PredictionContext.rb', line 223

def getReturnState(index)
    return self.returnStates[index]
end

#initialzie(parents, returnStates) ⇒ Object

Parent can be null only if full ctx mode and we make an array

from {@link #EMPTY} and non-empty. We merge {@link #EMPTY} by using null parent and
returnState == {@link #EMPTY_RETURN_STATE}.


202
203
204
205
206
207
208
# File 'lib/antlr4/PredictionContext.rb', line 202

def initialzie(parents, returnStates)
    super(PredictionContext.calculateHashCode(parents, returnStates))
#        assert parents is not None and len(parents)>0
#        assert returnStates is not None and len(returnStates)>0
    self.parents = parents
    self.returnStates = returnStates
end

#isEmptyObject



210
211
212
213
214
# File 'lib/antlr4/PredictionContext.rb', line 210

def isEmpty
    # since EMPTY_RETURN_STATE can only appear in the last position, we
    # don't need to verify that size==1
    return self.returnStates[0]==PredictionContext::EMPTY_RETURN_STATE
end

#lengthObject



216
217
218
# File 'lib/antlr4/PredictionContext.rb', line 216

def length
    return self.returnStates.length()
end

#to_sObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/antlr4/PredictionContext.rb', line 239

def to_s
   if self.isEmpty()
       return "[]"
   end
   StringIO.open  do |buf|
       buf.write("[")
       for i in 0..self.returnStates.length-1 do
           buf.write(", ") if i>0
           if self.returnStates[i]==PredictionContext::EMPTY_RETURN_STATE
               buf.write("$")
               next
           end
           buf.write(self.returnStates[i].to_s)
           if not self.parents[i].nil?
               buf.write(' ')
               buf.write(self.parents[i].to_s())
           end
       end
       buf.write("]")
       return buf.string()
   end
end