Class: Antlr4::Runtime::SingletonPredictionContext

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

Direct Known Subclasses

EmptyPredictionContext

Constant Summary

Constants inherited from PredictionContext

PredictionContext::EMPTY_RETURN_STATE, PredictionContext::INITIAL_HASH

Instance Attribute Summary collapse

Attributes inherited from PredictionContext

#cachedHashCode

Instance Method Summary collapse

Methods inherited from PredictionContext

#empty_path?, #hash, #to_s_recog, #to_strings, #to_strings3, #to_strings3_inner

Constructor Details

#initialize(parent, return_state) ⇒ SingletonPredictionContext


7
8
9
10
11
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 7

def initialize(parent, return_state)
  super(!parent.nil? ? PredictionContextUtils.calculate_hash_code1(parent, return_state) : PredictionContextUtils.calculate_empty_hash_code)
  @parent = parent
  @return_state = return_state
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent


4
5
6
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 4

def parent
  @parent
end

#return_stateObject

Returns the value of attribute return_state


5
6
7
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 5

def return_state
  @return_state
end

Instance Method Details

#empty?Boolean


21
22
23
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 21

def empty?
  @return_state == EMPTY_RETURN_STATE
end

#equals(other) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 29

def equals(other)
  if self == other
    return true
  elsif !(other.is_a? SingletonPredictionContext)
    return false
  end

  if hash != other.hash
    return false # can't be same if hash is different
  end

  @return_state == other.return_state && (!@parent.nil? && @parent.eql?(other.parent))
end

#get_parent(_i) ⇒ Object


13
14
15
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 13

def get_parent(_i)
  @parent
end

#get_return_state(_index) ⇒ Object


25
26
27
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 25

def get_return_state(_index)
  @return_state
end

#sizeObject


17
18
19
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 17

def size
  1
end

#to_sObject


43
44
45
46
47
48
49
50
51
# File 'lib/antlr4/runtime/singleton_prediction_context.rb', line 43

def to_s
  up = !@parent.nil? ? @parent.to_s : ''
  if up.empty?
    return '$' if @return_state == EMPTY_RETURN_STATE

    return @return_state.to_s
  end
  @return_state.to_s + ' ' + up
end