Class: ATNDeserializer

Inherits:
Object show all
Defined in:
lib/antlr4/atn/ATNDeserializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ ATNDeserializer

Returns a new instance of ATNDeserializer.



19
20
21
22
23
24
25
26
27
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 19

def initialize(options=nil)
    if options.nil?
        options = ATNDeserializationOptions.defaultOptions
    end
    self.deserializationOptions = options
    self.edgeFactories = nil
    self.stateFactories = nil
    self.actionFactories = nil
end

Instance Attribute Details

#actionFactoriesObject

Returns the value of attribute actionFactories.



16
17
18
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 16

def actionFactories
  @actionFactories
end

#dataObject

Returns the value of attribute data.



17
18
19
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 17

def data
  @data
end

#deserializationOptionsObject

Returns the value of attribute deserializationOptions.



15
16
17
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 15

def deserializationOptions
  @deserializationOptions
end

#edgeFactoriesObject

Returns the value of attribute edgeFactories.



16
17
18
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 16

def edgeFactories
  @edgeFactories
end

#posObject (readonly)

Returns the value of attribute pos.



18
19
20
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 18

def pos
  @pos
end

#stateFactoriesObject

Returns the value of attribute stateFactories.



16
17
18
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 16

def stateFactories
  @stateFactories
end

#uuidObject

Returns the value of attribute uuid.



17
18
19
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 17

def uuid
  @uuid
end

Instance Method Details

#checkCondition(condition, message = nil) ⇒ Object



473
474
475
476
477
478
479
480
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 473

def checkCondition(condition, message=nil)
    unless condition then
        if message.nil? 
            message = "IllegalState"
        end
        raise Exception.new(message)
    end
end

#checkUUIDObject



92
93
94
95
96
97
98
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 92

def checkUUID()
    uuid = self.readUUID()
    if not SUPPORTED_UUIDS.member? uuid then
        raise Exception.new("Could not deserialize ATN with UUID: #{uuid} (expected #{SERIALIZED_UUID} or a legacy UUID).")
    end
    self.uuid = uuid
end

#checkVersionObject



85
86
87
88
89
90
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 85

def checkVersion()
  version = self.readInt()
  if version != SERIALIZED_VERSION
      raise Exception.new("Could not deserialize ATN with version #{version} (expected #{SERIALIZED_VERSION}).")
  end
end

#deserialize(data) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 50

def deserialize(data)
    self.reset(data)
    self.checkVersion()
    self.checkUUID()
    atn = self.readATN()
    self.readStates(atn)
    self.readRules(atn)
    self.readModes(atn)
    sets = self.readSets(atn)
    self.readEdges(atn, sets)
    self.readDecisions(atn)
    self.readLexerActions(atn)
    self.markPrecedenceDecisions(atn)
    self.verifyATN(atn)
    if self.deserializationOptions.generateRuleBypassTransitions \
            and atn.grammarType == ATNType.PARSER
        self.generateRuleBypassTransitions(atn)
        # re-verify after modification
        self.verifyATN(atn)
    end
    return atn
end

#edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets) ⇒ Object



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 515

def edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets)
  target = atn.states[trg]
  if self.edgeFactories.nil? then
      ef = Array.new(11)  # [nil] * 11
      ef[0] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target| raise Exception.new("The specified state type 0 is not valid.") }
      ef[Transition::EPSILON] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target|  EpsilonTransition.new(target) }
      ef[Transition::RANGE] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target|
          if arg3 != 0 
              RangeTransition.new(target, Token::EOF, arg2) 
          else 
            RangeTransition.new(target, arg1, arg2)
          end
      }
      ef[Transition::RULE] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target | 
            RuleTransition.new(atn.states[arg1], arg2, arg3, target) }
      ef[Transition::PREDICATE] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target |
            PredicateTransition.new(target, arg1, arg2, arg3 != 0) }
      ef[Transition::PRECEDENCE] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target |
            PrecedencePredicateTransition.new(target, arg1) }
      ef[Transition::ATOM] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target | 
            if arg3 != 0 
                AtomTransition.new(target, Token::EOF) 
            else 
                AtomTransition.new(target, arg1)
            end
      }
      ef[Transition::ACTION] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target |
            ActionTransition.new(target, arg1, arg2, arg3 != 0)  }
      ef[Transition::SET] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target|
            SetTransition.new(target, sets[arg1]) }
      ef[Transition::NOT_SET] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target |  
            NotSetTransition.new(target, sets[arg1]) }
      ef[Transition::WILDCARD] = lambda {|atn, src, trg, arg1, arg2, arg3, sets, target |
            WildcardTransition.new(target) }
      self.edgeFactories = ef
    end
    if type > self.edgeFactories.length() or self.edgeFactories[type].nil?  then
        raise Exception.new("The specified transition type: #{type} is not valid.")
    else
        return self.edgeFactories[type].call(atn, src, trg, arg1, arg2, arg3, sets, target)
    end
end

#generateRuleBypassTransition(atn, idx) ⇒ Object



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 320

def generateRuleBypassTransition(atn, idx)
    bypassStart = BasicBlockStartState.new()
    bypassStart.ruleIndex = idx
    atn.addState(bypassStart)

    bypassStop = BlockEndState.new()
    bypassStop.ruleIndex = idx
    atn.addState(bypassStop)

    bypassStart.endState = bypassStop
    atn.defineDecisionState(bypassStart)

    bypassStop.startState = bypassStart

    excludeTransition = nil

    if atn.ruleToStartState[idx].isPrecedenceRule
        # wrap from the beginning of the rule to the StarLoopEntryState
        endState = nil
        for state in atn.states do
            if self.stateIsEndStateFor(state, idx) then
                endState = state
                excludeTransition = state.loopBackState.transitions[0]
                break
            end
        end
        if excludeTransition.nil? 
            raise Exception.new("Couldn't identify final state of the precedence rule prefix section.")
        end
    else
        endState = atn.ruleToStopState[idx]
    end

    # all non-excluded transitions that currently target end state need to target blockEnd instead
    for state in atn.states
        for transition in state.transitions
            if transition == excludeTransition
                next
            end
            if transition.target == endState
                transition.target = bypassStop
            end
        end
    end
    # all transitions leaving the rule start state need to leave blockStart instead
    ruleToStartState = atn.ruleToStartState[idx]
    count = ruleToStartState.transitions.length() 
    0.upto(ruleToStartState.transitions.length()  -1) do |i|
        transition = ruleToStartState.removeTransition(i)
        bypassStart.addTransition(transition)
    end
    # link the new states
    atn.ruleToStartState[idx].addTransition(EpsilonTransition.new(bypassStart))
    bypassStop.addTransition(EpsilonTransition.new(endState))

    matchState = BasicState.new()
    atn.addState(matchState)
    matchState.addTransition(AtomTransition.new(bypassStop, atn.ruleToTokenType[idx]))
    bypassStart.addTransition(EpsilonTransition.new(matchState))
end

#generateRuleBypassTransitions(atn) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 308

def generateRuleBypassTransitions(atn)
    count = atn.ruleToStartState.length()
    atn.ruleToTokenType = Array.new(count, 0)  #[ 0 ] * count
    0.upto(count-1) do |i| # for i in range(0, count)
        atn.ruleToTokenType[i] = atn.maxTokenType + i + 1
    end

    0.upto(count-1) do |i| # for i in range(0, count)
        self.generateRuleBypassTransition(atn, i)
    end
end

#isFeatureSupported(feature, actualUuid) ⇒ @code true

Determines if a particular serialized representation of an ATN supports a particular feature, identified by the UUID used for serializing the ATN at the time the feature was first introduced.

supported in the serialized ATN. currently being deserialized. serialized ATN at or after the feature identified by feature was introduced; otherwise, false.

Parameters:

  • feature

    The UUID marking the first time the feature was

  • actualUuid

    The UUID of the actual serialized ATN which is

Returns:

  • (@code true)

    if the actualUuid value represents a



41
42
43
44
45
46
47
48
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 41

def isFeatureSupported(feature, actualUuid)
    idx1 = SUPPORTED_UUIDS.index(feature)
    if idx1<0
        return false
    end
    idx2 = SUPPORTED_UUIDS.index(actualUuid)
    return idx2 >= idx1
end

#lexerActionFactory(type, data1, data2) ⇒ Object



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 585

def lexerActionFactory(type, data1, data2)
    if self.actionFactories.nil? then
        af = Array.new(8)  #[ nil ] * 8
        af[LexerActionType::CHANNEL] = lambda {|data1, data2| LexerChannelAction.new(data1) }
        af[LexerActionType::CUSTOM] = lambda {|data1, data2| LexerCustomAction.new(data1, data2) }
        af[LexerActionType::MODE] = lambda {|data1, data2| LexerModeAction.new(data1) } 
        af[LexerActionType::MORE] = lambda {|data1, data2| LexerMoreAction.INSTANCE } 
        af[LexerActionType::POP_MODE] = lambda {|data1, data2| LexerPopModeAction.INSTANCE }
        af[LexerActionType::PUSH_MODE] = lambda {|data1, data2| LexerPushModeAction.new(data1) }
        af[LexerActionType::SKIP] = lambda {|data1, data2| LexerSkipAction.INSTANCE }
        af[LexerActionType::TYPE] = lambda {|data1, data2| LexerTypeAction.new(data1) }
        self.actionFactories = af
    end
    if type> self.actionFactories.length() or self.actionFactories[type].nil?
        raise Exception("The specified lexer action type #{type} is not valid.")
    else
        return self.actionFactories[type].call(data1, data2)
    end
end

#markPrecedenceDecisions(atn) ⇒ Object

Analyze the StarLoopEntryState states in the specified ATN to set the StarLoopEntryState#precedenceRuleDecision field to the correct value.

Parameters:

  • atn

    The ATN.



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 402

def markPrecedenceDecisions(atn)
    for state in atn.states do
        next if not state.kind_of? StarLoopEntryState

        # We analyze the ATN to determine if this ATN decision state is the
        # decision for the closure block that determines whether a
        # precedence rule should continue or complete.
        #
        if atn.ruleToStartState[state.ruleIndex].isPrecedenceRule
            maybeLoopEndState = state.transitions[-1].target
            if maybeLoopEndState.kind_of? LoopEndState
                if maybeLoopEndState.epsilonOnlyTransitions and \
                        maybeLoopEndState.transitions[0].target.kind_of? RuleStopState
                    state.precedenceRuleDecision = true
                end
            end
        end
    end
end

#readATNObject



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

def readATN()
    idx = self.readInt()
    grammarType = ATNType.fromOrdinal(idx)
    maxTokenType = self.readInt()
    #puts "(readATN: #{grammarType.inspect} #{maxTokenType.inspect} )"
    return ATN.new(grammarType, maxTokenType)
end

#readByteObject



481
482
483
484
485
486
487
488
489
490
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 481

def readByte()
    i = @data[self.pos]
    begin
    ii = i.ord
    rescue
      puts "#{i.class} #{i} #{i.encoding}"
    end
    @pos = @pos + 1
    return ii
end

#readDecisions(atn) ⇒ Object



280
281
282
283
284
285
286
287
288
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 280

def readDecisions(atn)
    ndecisions = self.readInt()
    1.upto(ndecisions) do |i| # for i in range(0, ndecisions)
        s = self.readInt()
        decState = atn.states[s]
        atn.decisionToState.push(decState)
        decState.decision = i
    end
end

#readEdges(atn, sets) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 228

def readEdges(atn, sets)
    #print "Current position: #{self.pos}, "
    nedges = self.readInt()
    #puts "readEdges n:  #{nedges} #{self.pos}"
    1.upto(nedges) do |i| #for i in range(0, nedges)
        src = self.readInt()
        trg = self.readInt()
        ttype = self.readInt()
        arg1 = self.readInt()
        arg2 = self.readInt()
        arg3 = self.readInt()
        trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets)
        srcState = atn.states[src]
        srcState.addTransition(trans)
    end
    # edges for rule stop states can be derived, so they aren't serialized
    for state in atn.states do 
        state.transitions.each_index do |i| # for i in range(0, len(state.transitions))
            t = state.transitions[i]
            next if not t.kind_of?  RuleTransition
            atn.ruleToStopState[t.target.ruleIndex].addTransition(EpsilonTransition.new(t.followState))
        end
    end
    for state in atn.states do
        if state.kind_of? BlockStartState then
            # we need to know the end state to set its start state
            if state.endState.nil? then 
                raise Exception.new("IllegalState")
            end
            # block end states can only be associated to a single block start state
            if state.endState.startState 
                raise Exception.new("IllegalState")
            end
            state.endState.startState = state
        end
        if state.kind_of? PlusLoopbackState then
            state.transitions.each_index do |i| #for i in range(0, len(state.transitions))
                target = state.transitions[i].target
                if target.kind_of? PlusBlockStartState
                    target.loopBackState = state
                end
            end
        elsif state.kind_of? StarLoopbackState
            state.transitions.each_index do |i| #for i in range(0, len(state.transitions))
                target = state.transitions[i].target
                if target.kind_of? StarLoopEntryState
                    target.loopBackState = state
                end
            end
        end
    end
end

#readIntObject



491
492
493
494
495
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 491

def readInt()
    high = readByte()
    low = readByte()
    return (low | (high << 8)) - 2
end

#readInt32Object



497
498
499
500
501
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 497

def readInt32()
    low = self.readInt()
    high = self.readInt()
    return low | (high << 16)
end

#readLexerActions(atn) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 289

def readLexerActions(atn)
    if atn.grammarType == ATNType.LEXER
        count = self.readInt()
        atn.lexerActions = Array.new # [ nil ] * count
        0.upto(count-1) do |i|  # for i in range(0, count)
            actionType = self.readInt()
            data1 = self.readInt()
            if data1 == 0xFFFF
                data1 = -1
            end
            data2 = self.readInt()
            if data2 == 0xFFFF
                data2 = -1
            end
            lexerAction = self.lexerActionFactory(actionType, data1, data2)
            atn.lexerActions[i] = lexerAction
        end
    end
end

#readLongObject



502
503
504
505
506
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 502

def readLong()
    low = self.readInt32()
    high = self.readInt32()
    return (low & 0x00000000FFFFFFFF) | (high << 32)
end

#readModes(atn) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 181

def readModes(atn)
    nmodes = self.readInt()
    1.upto(nmodes) do  #for i in range(0, nmodes)
        s = self.readInt()
        atn.modeToStartState.push(atn.states[s])
    end
end

#readRules(atn) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 152

def readRules(atn)        
    nrules = self.readInt()
    if atn.grammarType == ATNType.LEXER
        atn.ruleToTokenType = Array.new(nrules, 0) # [0] * nrules
    end

    atn.ruleToStartState = Array.new(nrules, 0) # [0] * nrules
    0.upto(nrules - 1) do |i| #for i in range(0, nrules)
        s = self.readInt()
        startState = atn.states[s]
        atn.ruleToStartState[i] = startState
        if atn.grammarType == ATNType.LEXER
            tokenType = self.readInt()
            if tokenType == 0xFFFF
                tokenType = Token::EOF
            end
            atn.ruleToTokenType[i] = tokenType
        end
    end
    atn.ruleToStopState = Array.new(nrules, 0)  #[0] * nrules
    for state in atn.states do
        if not state.kind_of? RuleStopState then
            next
        end
        atn.ruleToStopState[state.ruleIndex] = state
        atn.ruleToStartState[state.ruleIndex].stopState = state
    end
end

#readSets(atn) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 209

def readSets(atn)
    sets = Array.new
    m = self.readInt()
    1.upto(m) do |i|  #for i in range(0, m)
        iset = IntervalSet.new()
        sets.push(iset)
        n = self.readInt()
        containsEof = self.readInt()
        if containsEof !=0 then
            iset.addOne(-1)
        end
        1.upto(n) do |j| # for j in range(0, n)
            i1 = self.readInt()
            i2 = self.readInt()
            iset.addRange(i1..i2) 
        end
    end
    return sets
end

#readStates(atn) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 107

def readStates(atn)
    loopBackStateNumbers = Array.new
    endStateNumbers = Array.new
    nstates = self.readInt()
    1.upto(nstates) do |i| 
        stype = self.readInt()
        # ignore bad type of states
        if stype==ATNState::INVALID_TYPE
            atn.addState(nil)
            next
        end
        ruleIndex = self.readInt()
        if ruleIndex == 0xFFFF
            ruleIndex = -1
        end
        s = self.stateFactory(stype, ruleIndex)
        if stype == ATNState::LOOP_END # special case
            loopBackStateNumber = self.readInt()
            loopBackStateNumbers.push([s, loopBackStateNumber])
        elsif s.kind_of? BlockStartState
            endStateNumber = self.readInt()
            endStateNumbers.push([s, endStateNumber])
        end

        atn.addState(s)
    end
    # delay the assignment of loop back and end states until we know all the state instances have been initialized
    for pair in loopBackStateNumbers do
        pair[0].loopBackState = atn.states[pair[1]]
    end
    for pair in endStateNumbers do
        pair[0].endState = atn.states[pair[1]]
    end

    numNonGreedyStates = self.readInt()
    1.upto(numNonGreedyStates) do |i|
        stateNumber = self.readInt()
        atn.states[stateNumber].nonGreedy = true
    end
    numPrecedenceStates = self.readInt()
    1.upto(numPrecedenceStates) do |i|
        stateNumber = self.readInt()
        atn.states[stateNumber].isPrecedenceRule = true
    end
end

#readUUIDObject



508
509
510
511
512
513
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 508

def readUUID()
    low = self.readLong()
    high = self.readLong()
    allBits = (low & 0xFFFFFFFFFFFFFFFF) | (high << 64)
    return UUID.create_from_bytes(allBits)
end

#reset(_data) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 72

def reset(_data)
   #for (int i = 1; i < data.length; i++) {
   #     data[i] = (char)(data[i] - 2);
   # don't adjust the first value since that's the version number
   temp = Array.new(_data.length)
   temp = _data
   ver = _data[1]
   temp[1] = (_data[1].ord + 2)
   self.data = temp
   @pos = 0
   #puts "idx =1288 <573>: #{temp[1288].inspect} : #{_data[1288].ord.inspect} | len #{temp.length}, #{_data.length}"
end

#stateFactory(type, ruleIndex) ⇒ Object



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 557

def stateFactory(type, ruleIndex)
    if self.stateFactories.nil? 
        sf = Array.new(13)  # [nil] * 13
        sf[ATNState::INVALID_TYPE] = lambda {  nil }
        sf[ATNState::BASIC] = lambda { BasicState.new } 
        sf[ATNState::RULE_START] = lambda { RuleStartState.new }
        sf[ATNState::BLOCK_START] = lambda { BasicBlockStartState.new }
        sf[ATNState::PLUS_BLOCK_START] = lambda { PlusBlockStartState.new }
        sf[ATNState::STAR_BLOCK_START] = lambda { StarBlockStartState.new }
        sf[ATNState::TOKEN_START] = lambda { TokensStartState.new }
        sf[ATNState::RULE_STOP] = lambda { RuleStopState.new }
        sf[ATNState::BLOCK_END] = lambda { BlockEndState.new }
        sf[ATNState::STAR_LOOP_BACK] = lambda { StarLoopbackState.new }
        sf[ATNState::STAR_LOOP_ENTRY] = lambda { StarLoopEntryState.new }
        sf[ATNState::PLUS_LOOP_BACK] = lambda { PlusLoopbackState.new }
        sf[ATNState::LOOP_END] = lambda { LoopEndState.new }
        self.stateFactories = sf
    end
    if type> self.stateFactories.length() or self.stateFactories[type].nil?
        raise Exceptionn.new("The specified state type #{type} is not valid.")
    else
        s = self.stateFactories[type].call()
        if s 
            s.ruleIndex = ruleIndex
        end
    end
    return s
end

#stateIsEndStateFor(state, idx) ⇒ Object



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 381

def stateIsEndStateFor(state, idx)
    return nil if state.ruleIndex != idx
    return nil if not state.kind_of? StarLoopEntryState

    maybeLoopEndState = state.transitions[-1].target
    return nil if not maybeLoopEndState.kind_of? LoopEndState

    if maybeLoopEndState.epsilonOnlyTransitions and  maybeLoopEndState.transitions[0].target.kind_of? RuleStopState
        return state
    else
        return nil
    end
end

#verifyATN(atn) ⇒ Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/antlr4/atn/ATNDeserializer.rb', line 422

def verifyATN(atn)
  return if not self.deserializationOptions.verifyATN
  # verify assumptions
  for state in atn.states do
    next if state.nil? 
    self.checkCondition((state.epsilonOnlyTransitions or state.transitions.length <= 1))
    if state.kind_of? PlusBlockStartState then
       self.checkCondition( !state.loopBackState.nil?)

       if state.kind_of? StarLoopEntryState then
            self.checkCondition( !state.loopBackState.nil? )
            self.checkCondition(state.transitions.length() == 2)

            if state.transitions[0].target.kind_of? StarBlockStartState then
                self.checkCondition(state.transitions[1].target.kind_of?(LoopEndState))
                self.checkCondition(!state.nonGreedy)
            elsif state.transitions[0].target.kind_of? LoopEndState then
                self.checkCondition(state.transitions[1].target.kind_of?(StarBlockStartState))
                self.checkCondition(state.nonGreedy)
            else
                raise Exception.new("IllegalState")
            end
        end
        if state.kind_of? StarLoopbackState then
            self.checkCondition(state.transitions.length() == 1)
            self.checkCondition(state.transitions[0].target.kind_of?(StarLoopEntryState))
        end
        if state.kind_of? LoopEndState then
            self.checkCondition(! state.loopBackState.nil?) 
        end

        if state.kind_of? RuleStartState then
            self.checkCondition( !state.stopState.nil? )
        end

        if state.kind_of? BlockStartState then
            self.checkCondition(!state.endState.nil? )
        end

        if state.kind_of? BlockEndState then
            self.checkCondition(!state.startState.nil? )
        end

        if state.kind_of? DecisionState then
            self.checkCondition( (( state.transitions.length() <= 1) || ( state.decision >= 0)))
        else
            self.checkCondition(((state.transitions.lenth() <= 1) || (state.kind_of?(RuleStopState) )))
        end
    end
  end
end