Class: SingletonPredictionContext

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

Direct Known Subclasses

EmptyPredictionContext

Constant Summary

Constants inherited from PredictionContext

PredictionContext::EMPTY_RETURN_STATE

Instance Attribute Summary collapse

Attributes inherited from PredictionContext

#cachedHashCode

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PredictionContext

EMPTY, EMPTY_RETURN_STATE, calculateEmptyHashCode, calculateHashCode, #hasEmptyPath, #isEmpty

Constructor Details

#initialize(parent, returnState) ⇒ SingletonPredictionContext

Returns a new instance of SingletonPredictionContext.



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/antlr4/PredictionContext.rb', line 109

def initialize( parent, returnState)
    #assert returnState!=ATNState.INVALID_STATE_NUMBER
    if parent.nil? then
      hashCode = PredictionContext.calculateEmptyHashCode
    else
      hashCode = PredictionContext.calculateHashCode(parent, returnState) 
    end
    super(hashCode)
    @parentCtx = parent
    @returnState = returnState
end

Instance Attribute Details

#cache_stringObject

Returns the value of attribute cache_string.



108
109
110
# File 'lib/antlr4/PredictionContext.rb', line 108

def cache_string
  @cache_string
end

#parentCtxObject (readonly)

Returns the value of attribute parentCtx.



107
108
109
# File 'lib/antlr4/PredictionContext.rb', line 107

def parentCtx
  @parentCtx
end

#returnStateObject (readonly)

Returns the value of attribute returnState.



107
108
109
# File 'lib/antlr4/PredictionContext.rb', line 107

def returnState
  @returnState
end

Class Method Details

.create(parent, returnState) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/antlr4/PredictionContext.rb', line 98

def self.create(parent, returnState)
    if returnState == PredictionContext::EMPTY_RETURN_STATE and parent.nil?  then
        # someone can pass in the bits of an array ctx that mean $
        return PredictionContext.EMPTY
    else
        return SingletonPredictionContext.new(parent, returnState)
    end
end

Instance Method Details

#==(other) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/antlr4/PredictionContext.rb', line 138

def ==(other)
    return true  if self.equal?(other)
    return false unless self.class == other.class
    if self.hash != other.hash
        false #      can't be same if hash is different
    else
        self.returnState == other.returnState and \
        (self.parentCtx.equal?(other.parentCtx) \
                      or self.parentCtx==other.parentCtx )
    end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/antlr4/PredictionContext.rb', line 135

def eql?(other)
  self == other
end

#getParent(index) ⇒ Object



125
126
127
128
# File 'lib/antlr4/PredictionContext.rb', line 125

def getParent(index)
    # assert index == 0
    return self.parentCtx
end

#getReturnState(index) ⇒ Object



130
131
132
133
# File 'lib/antlr4/PredictionContext.rb', line 130

def getReturnState(index)
    #assert index == 0
    return self.returnState
end

#hashObject



149
150
151
# File 'lib/antlr4/PredictionContext.rb', line 149

def hash
    return self.cachedHashCode
end

#lengthObject



121
122
123
# File 'lib/antlr4/PredictionContext.rb', line 121

def length 
    return 1
end

#mk_stringObject



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/antlr4/PredictionContext.rb', line 157

def mk_string
    if @parentCtx.nil? then
        if @returnState == PredictionContext::EMPTY_RETURN_STATE 
            return "$"
        else
            return @returnState.to_s
        end
    else
        return "#{@returnState} #{@parentCtx}" 
    end
end

#to_sObject



153
154
155
156
# File 'lib/antlr4/PredictionContext.rb', line 153

def to_s 
  @cache_string = mk_string if @cache_string.nil?
  return @cache_string 
end