Class: ATNConfig
Overview
A tuple: (ATN state, predicted alt, syntactic, semantic context).
The syntactic context is a graph-structured stack node whose
path(s) to the root is the rule invocation(s)
chain used to arrive at the state. The semantic context is
the tree of semantic predicates encountered before reaching
an ATN state.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#context ⇒ Object
Returns the value of attribute context.
-
#hashcode ⇒ Object
readonly
Returns the value of attribute hashcode.
-
#reachesIntoOuterContext ⇒ Object
Returns the value of attribute reachesIntoOuterContext.
-
#semanticContext ⇒ Object
readonly
Returns the value of attribute semanticContext.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#eql?(other) ⇒ Boolean
An ATN configuration is equal to another if both have the same state, they predict the same alternative, and syntactic/semantic contexts are the same.
- #hash ⇒ Object
-
#initialize(state = nil, alt = nil, context = nil, semantic = nil, config = nil) ⇒ ATNConfig
constructor
A new instance of ATNConfig.
- #mk_hashcode ⇒ Object
- #to_s(recog = nil, showAlt = true) ⇒ Object
- #toString(recog = nil, showAlt = true) ⇒ Object
Constructor Details
#initialize(state = nil, alt = nil, context = nil, semantic = nil, config = nil) ⇒ ATNConfig
Returns a new instance of ATNConfig.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 16 def initialize(state=nil, alt=nil, context=nil, semantic=nil, config=nil) if config then state = config.state if state.nil? alt = config.alt if alt.nil? context = config.context if context.nil? semantic = config.semanticContext if semantic.nil? semantic = SemanticContext.NONE if semantic.nil? @reachesIntoOuterContext = config.reachesIntoOuterContext else # We cannot execute predicates dependent upon local context unless # we know for sure we are in the correct context. Because there is # no way to do this efficiently, we simply cannot evaluate # dependent predicates unless we are in the rule that initially # invokes the ATN simulator. # # closure() tracks the depth of how far we dip into the # outer context: depth > 0. Note that it may not be totally # accurate depth since I don't ever decrement. TODO: make it a boolean then @reachesIntoOuterContext = 0 end #if not isinstance(state, ATNState): # pass # The ATN state associated with this configuration#/ @state = state # What alt (or lexer rule) is predicted by this configuration#/ @alt = alt # The stack of invoking states leading to the rule/states associated # with this config. We track only those contexts pushed during # execution of the ATN simulator. @context = context @semanticContext = semantic mk_hashcode end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
14 15 16 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 14 def alt @alt end |
#context ⇒ Object
Returns the value of attribute context.
14 15 16 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 14 def context @context end |
#hashcode ⇒ Object (readonly)
Returns the value of attribute hashcode.
15 16 17 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 15 def hashcode @hashcode end |
#reachesIntoOuterContext ⇒ Object
Returns the value of attribute reachesIntoOuterContext.
13 14 15 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 13 def reachesIntoOuterContext @reachesIntoOuterContext end |
#semanticContext ⇒ Object (readonly)
Returns the value of attribute semanticContext.
14 15 16 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 14 def semanticContext @semanticContext end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
14 15 16 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 14 def state @state end |
Class Method Details
.createConfigState(config, state) ⇒ Object
10 11 12 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 10 def self.createConfigState(config, state) new(state,nil,nil,nil,config) end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 57 def ==(other) self.equal?(other) or \ other.kind_of?(ATNConfig) and \ (@state.stateNumber==other.state.stateNumber and @alt==other.alt and (@context==other.context) and @semanticContext==other.semanticContext ) end |
#eql?(other) ⇒ Boolean
An ATN configuration is equal to another if both have
the same state, they predict the same alternative, and
syntactic/semantic contexts are the same.
54 55 56 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 54 def eql?(other) self == other end |
#hash ⇒ Object
72 73 74 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 72 def hash @hashcode end |
#mk_hashcode ⇒ Object
69 70 71 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 69 def mk_hashcode @hashcode = "#{@state.stateNumber}/#{@alt}/#{@context}/#{@semanticContext}".hash end |
#to_s(recog = nil, showAlt = true) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 78 def to_s(recog=nil, showAlt=true) StringIO.open do |buf| buf.write('(') buf.write(self.state.to_s) if showAlt then buf.write(",") buf.write(self.alt.to_s) end if self.context then buf.write(",[") buf.write(self.context.to_s) buf.write("]") end if self.semanticContext and (! self.semanticContext.equal? SemanticContext.NONE) then buf.write(",") buf.write(self.semanticContext.to_s) end if self.reachesIntoOuterContext>0 then buf.write(",up=") buf.write(self.reachesIntoOuterContext.to_s) end buf.write(')') return buf.string() end end |
#toString(recog = nil, showAlt = true) ⇒ Object
75 76 77 |
# File 'lib/antlr4/atn/ATNConfig.rb', line 75 def toString(recog=nil, showAlt=true) to_s(recog,showAlt) end |