Class: Antlr4::Runtime::ArrayPredictionContext
- Inherits:
-
PredictionContext
- Object
- PredictionContext
- Antlr4::Runtime::ArrayPredictionContext
- Defined in:
- lib/antlr4/runtime/array_prediction_context.rb
Constant Summary
Constants inherited from PredictionContext
PredictionContext::EMPTY_RETURN_STATE, PredictionContext::INITIAL_HASH
Instance Attribute Summary collapse
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#return_states ⇒ Object
Returns the value of attribute return_states.
Attributes inherited from PredictionContext
Instance Method Summary collapse
-
#empty? ⇒ Boolean
since EMPTY_RETURN_STATE can only appear in the last position, we.
- #equals(o) ⇒ Object
- #get_parent(index) ⇒ Object
- #get_return_state(index) ⇒ Object
-
#initialize(parents, return_states = nil) ⇒ ArrayPredictionContext
constructor
A new instance of ArrayPredictionContext.
- #size ⇒ Object
- #to_s ⇒ Object
Methods inherited from PredictionContext
#empty_path?, #hash, #to_s_recog, #to_strings, #to_strings3, #to_strings3_inner
Constructor Details
#initialize(parents, return_states = nil) ⇒ ArrayPredictionContext
Returns a new instance of ArrayPredictionContext.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 7 def initialize(parents, return_states = nil) if parents.is_a? SingletonPredictionContext return_states = [parents.return_state] parents = [parents.parent] end super(PredictionContextUtils.calculate_hash_code2(parents, return_states)) @parents = parents @return_states = return_states end |
Instance Attribute Details
#parents ⇒ Object
Returns the value of attribute parents.
4 5 6 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 4 def parents @parents end |
#return_states ⇒ Object
Returns the value of attribute return_states.
5 6 7 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 5 def return_states @return_states end |
Instance Method Details
#empty? ⇒ Boolean
since EMPTY_RETURN_STATE can only appear in the last position, we
18 19 20 21 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 18 def empty? # since EMPTY_RETURN_STATE can only appear in the last position, we # don't need to verify that size==1 @return_states[0] == EMPTY_RETURN_STATE end |
#equals(o) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 35 def equals(o) if self == o return true elsif !(o.is_a? ArrayPredictionContext) return false end if hash != o.hash return false # can't be same if hash is different end (@return_states.eql? o.return_states) && (@parents.eql? o.parents) end |
#get_parent(index) ⇒ Object
27 28 29 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 27 def get_parent(index) @parents[index] end |
#get_return_state(index) ⇒ Object
31 32 33 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 31 def get_return_state(index) @return_states[index] end |
#size ⇒ Object
23 24 25 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 23 def size @return_states.length end |
#to_s ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/antlr4/runtime/array_prediction_context.rb', line 49 def to_s return '[]' if empty? buf = '' buf << '[' i = 0 while i < @return_states.length buf << ', ' if i > 0 if return_states[i] == EMPTY_RETURN_STATE buf << '$' i += 1 next end buf << @return_states[i] if !@parents[i].nil? buf << ' ' buf << @parents[i].to_s else buf << 'nil' end i += 1 end buf << ']' buf.to_s end |