Class: LexerATNSimulator

Inherits:
ATNSimulator show all
Defined in:
lib/antlr4/atn/LexerATNSimulator.rb

Constant Summary collapse

MIN_DFA_EDGE =
0
MAX_DFA_EDGE =

forces unicode to stay in ATN

127
@@debug =
false
@@dfa_debug =
false
@@match_calls =
0

Constants inherited from ATNSimulator

ATNSimulator::ERROR

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from ATNSimulator

#atn, #sharedContextCache

Instance Method Summary collapse

Methods inherited from ATNSimulator

#getCachedContext

Methods included from PredictionContextFunctions

included

Constructor Details

#initialize(_recog, _atn, decision_to_dfa, shared_context_cache) ⇒ LexerATNSimulator

Returns a new instance of LexerATNSimulator.



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/LexerATNSimulator.rb', line 51

def initialize(_recog, _atn, decision_to_dfa, shared_context_cache)
    super(_atn, shared_context_cache)
    
    if decision_to_dfa.nil?  then
      raise Exception.new("Error: #{self.class} decisionToDFA is nil.")
    end
    @decisionToDFA = decision_to_dfa
    @recog = _recog
    # The current token's starting index into the character stream.
    #  Shared across DFA to ATN simulation in case the ATN fails and the
    #  DFA did not have a previous accept state. In this case, we use the
    #  ATN-generated exception object.
    @startIndex = -1
    # line number 1..n within the input#/
    @line = 1
    # The index of the character relative to the beginning of the line 0..n-1#/
    @column = 0
    @mode = Lexer::DEFAULT_MODE
    # Used during DFA/ATN exec to record the most recent accept configuration info
    self.prevAccept = SimState.new()
end

Class Attribute Details

.debugObject (readonly)

Returns the value of attribute debug.



36
37
38
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 36

def debug
  @debug
end

.dfa_debugObject (readonly)

Returns the value of attribute dfa_debug.



36
37
38
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 36

def dfa_debug
  @dfa_debug
end

.match_callsObject (readonly)

Returns the value of attribute match_calls.



36
37
38
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 36

def match_calls
  @match_calls
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



48
49
50
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 48

def column
  @column
end

#decisionToDFAObject

Returns the value of attribute decisionToDFA.



48
49
50
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 48

def decisionToDFA
  @decisionToDFA
end

#lineObject

Returns the value of attribute line.



48
49
50
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 48

def line
  @line
end

#modeObject

Returns the value of attribute mode.



49
50
51
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 49

def mode
  @mode
end

#prevAcceptObject

Returns the value of attribute prevAccept.



49
50
51
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 49

def prevAccept
  @prevAccept
end

#recogObject

Returns the value of attribute recog.



48
49
50
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 48

def recog
  @recog
end

#startIndexObject

Returns the value of attribute startIndex.



48
49
50
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 48

def startIndex
  @startIndex
end

Instance Method Details

#accept(input, lexerActionExecutor, start_index, index, _line, charPos) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 294

def accept(input, lexerActionExecutor, start_index, index, _line, charPos)
    if self.debug
        puts "ACTION #{lexerActionExecutor}"
    end

    # seek to after last char in token
    input.seek(index)
    self.line = _line
    self.column = charPos
    if input.LA(1) != Token::EOF
        self.consume(input)
    end
    if lexerActionExecutor and self.recog 
        lexerActionExecutor.execute(self.recog, input, start_index)
    end
end

#addDFAEdge(from_, tk, to = nil, cfgs = nil) ⇒ Object



504
505
506
507
508
509
510
511
512
513
514
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
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 504

def addDFAEdge(from_, tk, to=nil, cfgs=nil)

    if to.nil? and cfgs then
        # leading to this call, ATNConfigSet.hasSemanticContext is used as a
        # marker indicating dynamic predicate evaluation makes this edge
        # dependent on the specific input sequence, so the static edge in the
        # DFA should be omitted. The target DFAState is still created since
        # execATN has the ability to resynchronize with the DFA state cache
        # following the predicate evaluation step.
        #
        # TJP notes: next time through the DFA, we see a pred again and eval.
        # If that gets us to a previously created (but dangling) DFA
        # state, we can continue in pure DFA mode from there.
        #/
        suppressEdge = cfgs.hasSemanticContext
        cfgs.hasSemanticContext = false

        to = self.addDFAState(cfgs)

        if suppressEdge then
            return to
        end
    end
    # add the edge
    if tk < LexerATNSimulator::MIN_DFA_EDGE or tk > LexerATNSimulator::MAX_DFA_EDGE
        # Only track edges within the DFA bounds
        return to
    end

    if self.debug
        puts  "EDGE #{from_} -> #{to} upon #{tk.chr}"
    end

    if from_.edges.nil? 
        #  make room for tokens 1..n and -1 masquerading as index 0
        # from_.edges = [nil] * (LexerATNSimulator::MAX_DFA_EDGE -
        # LexerATNSimulator::MIN_DFA_EDGE + 1)
        from_.edges = Array.new 
    end

    from_.edges[tk - LexerATNSimulator::MIN_DFA_EDGE] = to # connect

    return to
end

#addDFAState(configs) ⇒ Object

Add a new DFA state if there isn’t one with this set of configurations already. This method also detects the first configuration containing an ATN rule stop state. Later, when traversing the DFA, we will know which rule to accept.



553
554
555
556
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
585
586
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 553

def addDFAState(configs) # -> DFAState:
    # the lexer evaluates predicates on-the-fly; by this point configs
    # should not contain any configurations with unevaluated predicates.
    # assert not configs.hasSemanticContext
    proposed = DFAState.new(nil,configs)
    firstConfigWithRuleStopState = nil
#        for c in configs.each do |c|:
    configs.each do |c|
        if c.state.kind_of? RuleStopState then
            firstConfigWithRuleStopState = c
            break
        end
    end

    if firstConfigWithRuleStopState then
        proposed.isAcceptState = true
        proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor
        proposed.prediction = self.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex]
    end

    dfa = self.decisionToDFA[self.mode]
    existing = dfa.states[proposed]
    if existing  then
        return existing
    end

    newState = proposed

    newState.stateNumber = dfa.states.length
    configs.setReadonly(true)
    newState.configs = configs
    dfa.states[newState] = newState
    return newState
end

#captureSimState(settings, input, dfaState) ⇒ Object



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

def captureSimState(settings, input, dfaState)
    settings.index = input.index
    settings.line = self.line
    settings.column = self.column
    settings.dfaState = dfaState
end

#clearDFAObject

Raises:

  • (Exception)


105
106
107
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 105

def clearDFA()
  raise Exception.new("not implemented")
end

#closure(input, config, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon) ⇒ @code true

Since the alternatives within any lexer decision are ordered by preference, this method stops pursuing the closure as soon as an accept state is reached. After the first accept state is reached by depth-first search from config, all other (potentially reachable) states for this rule would have a lower priority.

false.

Returns:

  • (@code true)

    if an accept state is reached, otherwise



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
380
381
382
383
384
385
386
387
388
389
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 338

def closure(input, config, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
    if self.debug
      puts "closure(#{config.toString(self.recog, true)})"
    end

    if config.state.kind_of? RuleStopState 
        if self.debug
            if self.recog 
              puts "closure at #{self.recog.getRuleNames[config.state.ruleIndex]} rule stop #{ config}" 
            else
              puts "closure at rule stop #{ config}" 
            end
        end

        if config.context.nil? or config.context.hasEmptyPath()
            if config.context.nil? or config.context.isEmpty()
                configs.add(config)
                return true
            else
                configs.add(LexerATNConfig.new(config.state, nil,PredictionContext.EMPTY,nil,nil,config) )
                currentAltReachedAcceptState = true
            end
        end
        if config.context and not config.context.isEmpty() then
            0.upto(config.context.length - 1) do |i| 
                if config.context.getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE
                    newContext = config.context.getParent(i) # "pop" return state
                    returnState = self.atn.states[config.context.getReturnState(i)]
                    c = LexerATNConfig.new(returnState,nil,newContext, nil, nil, config )
                    currentAltReachedAcceptState = self.closure(input, c, configs,
                                currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
                end
            end
        end
        return currentAltReachedAcceptState
    end
    # optimization
    if not config.state.epsilonOnlyTransitions then
        if not currentAltReachedAcceptState or not config.passedThroughNonGreedyDecision
            configs.add(config)
        end
    end

    #for t in config.state.transitions do
    config.state.transitions.each do |t|
      c = self.getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon)
      if c then
       currentAltReachedAcceptState = self.closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
      end
    end
    return currentAltReachedAcceptState
end

#computeStartState(input, p) ⇒ Object



319
320
321
322
323
324
325
326
327
328
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 319

def computeStartState(input, p)
    initialContext = PredictionContext.EMPTY
    configs = OrderedATNConfigSet.new()
    p.transitions.each_index do |i|
        target = p.transitions[i].target
        c = LexerATNConfig.new(target, i+1, initialContext)
        self.closure(input, c, configs, false, false, false)
    end
    return configs
end

#computeTargetState(input, s, t) ⇒ Object

Compute a target state for an edge in the DFA, and attempt to add the computed state and corresponding edge to the DFA.

t. If t does not lead to a valid DFA state, this method returns #ERROR.

Parameters:

  • input

    The input stream

  • s

    The current DFA state

  • t

    The next input symbol

Returns:

  • The computed target DFA state for the given input symbol



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 224

def computeTargetState(input, s, t)
    reach = OrderedATNConfigSet.new()

    # if we don't find an existing DFA state
    # Fill reach starting from closure, following t transitions
    self.getReachableConfigSet(input, s.configs, reach, t)

    if reach.length==0 # we got nowhere on t from s
        if not reach.hasSemanticContext
            # we got nowhere on t, don't throw out this knowledge; it'd
            # cause a failover from DFA later.
           self.addDFAEdge(s, t, ATNSimulator::ERROR)
        end
        # stop when we can't match any more char
        return ATNSimulator::ERROR
    end

    # Add an edge from s to target DFA found/created for reach
    return self.addDFAEdge(s, t, nil, reach)
end

#consume(input) ⇒ Object



595
596
597
598
599
600
601
602
603
604
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 595

def consume(input)
    curChar = input.LA(1)
    if curChar=="\n".ord then
        self.line = self.line + 1
        self.column = 0
    else
        self.column = self.column + 1
    end
    input.consume()
end

#copyState(simulator) ⇒ Object



74
75
76
77
78
79
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 74

def copyState(simulator)
    self.column = simulator.column
    self.line = simulator.line
    self.mode = simulator.mode
    self.startIndex = simulator.startIndex
end

#debugObject



41
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 41

def debug; @@debug ;end

#dfa_debugObject



42
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 42

def dfa_debug; @@dfa_debug ;end

#evaluatePredicate(input, ruleIndex, predIndex, speculative) ⇒ @code true

Evaluate a predicate specified in the lexer.

<p>If speculative is true, this method was called before #consume for the matched character. This method should call #consume before evaluating the predicate to ensure position sensitive values, including Lexer#getText, Lexer#getLine, and Lexer#getcolumn, properly reflect the current lexer state. This method should restore input and the simulator to the original state before returning (i.e. undo the actions made by the call to #consume.</p>

one character before the predicate’s location.

true. /

Parameters:

  • input

    The input stream.

  • ruleIndex

    The rule containing the predicate.

  • predIndex

    The index of the predicate within the rule.

  • speculative (@code true)

    if the current index in input is

Returns:

  • (@code true)

    if the specified predicate evaluates to



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 475

def evaluatePredicate(input, ruleIndex, predIndex, speculative)
    # assume true if no recognizer was provided
    return true if self.recog.nil? 

    if not speculative then
        return self.recog.sempred(nil, ruleIndex, predIndex)
    end

    savedcolumn = self.column
    savedLine = self.line
    index = input.index
    marker = input.mark()
    begin
        self.consume(input)
        return self.recog.sempred(nil, ruleIndex, predIndex)
    ensure 
        self.column = savedcolumn
        self.line = savedLine
        input.seek(index)
        input.release(marker)
    end
end

#execATN(input, ds0) ⇒ Object

Raises:

  • (Exception)


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 133

def execATN(input, ds0)
    if self.debug then
        puts "start state closure=#{ds0.configs.to_s}"
    end

    t = input.LA(1)
    s = ds0 # s is current/from DFA state

    raise Exception.new("s is nil") if s.nil?

    while true do # while more work
        if self.debug then
            puts "execATN loop starting closure: #{s.configs}"
        end

        # As we move src->trg, src->trg, we keep track of the previous trg to
        # avoid looking up the DFA state again, which is expensive.
        # If the previous target was already part of the DFA, we might
        # be able to avoid doing a reach operation upon t. If s!=null,
        # it means that semantic predicates didn't prevent us from
        # creating a DFA state. Once we know s!=null, we check to see if
        # the DFA state has an edge already for t. If so, we can just reuse
        # it's configuration set; there's no point in re-computing it.
        # This is kind of like doing DFA simulation within the ATN
        # simulation because DFA simulation is really just a way to avoid
        # computing reach/closure sets. Technically, once we know that
        # we have a previously added DFA state, we could jump over to
        # the DFA simulator. But, that would mean popping back and forth
        # a lot and making things more complicated algorithmically.
        # This optimization makes a lot of sense for loops within DFA.
        # A character will take us back to an existing DFA state
        # that already has lots of edges out of it. e.g., .* in comments.
        # print("Target for:" + str(s) + " and:" + str(t))
        target = self.getExistingTargetState(s, t)
        # print("Existing:" + str(target))
        if target.nil? then
            target = self.computeTargetState(input, s, t)
        end
            # print("Computed:" + str(target))
        break if target.equal? ATNSimulator::ERROR

        if target.isAcceptState
            self.captureSimState(self.prevAccept, input, target)
            if t == Token::EOF
                break
            end
        end

        if t != Token::EOF
            self.consume(input)
            t = input.LA(1)
        end

        s = target # flip; current DFA target becomes new src/from state
    end

    return self.failOrAccept(self.prevAccept, input, s.configs, t)
end

#failOrAccept(prevAccept, input, reach, t) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 244

def failOrAccept(prevAccept, input, reach, t)
    if not self.prevAccept.dfaState.nil?
        lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
        self.accept(input, lexerActionExecutor, self.startIndex, prevAccept.index, prevAccept.line, prevAccept.column)
        return prevAccept.dfaState.prediction
    else
        # if no accept and EOF is first char, return EOF
        if t==Token::EOF and input.index==self.startIndex
            return Token::EOF
        end
        raise LexerNoViableAltException.new(self.recog, input, self.startIndex, reach)
    end
end

#getDFA(mode) ⇒ Object



587
588
589
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 587

def getDFA(mode)
    return self.decisionToDFA[mode]
end

#getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon) ⇒ Object

side-effect: can alter configs.hasSemanticContext



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
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
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 391

def getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon)
    c = nil
    if t.serializationType==Transition::RULE then
       newContext = SingletonPredictionContext.create(config.context, t.followState.stateNumber)
       c = LexerATNConfig.new(t.target, nil, newContext, nil,nil, config)
    elsif t.serializationType==Transition::PRECEDENCE
        raise UnsupportedOperationException.new("Precedence predicates are not supported in lexers.")
    elsif t.serializationType==Transition::PREDICATE
            #  Track traversing semantic predicates. If we traverse,
            # we cannot add a DFA state for this "reach" computation
            # because the DFA would not test the predicate again in the
            # future. Rather than creating collections of semantic predicates
            # like v3 and testing them on prediction, v4 will test them on the
            # fly all the time using the ATN not the DFA. This is slower but
            # semantically it's not used that often. One of the key elements to
            # this predicate mechanism is not adding DFA states that see
            # predicates immediately afterwards in the ATN. For example,

            # a : ID {p1}? | ID {p2}? ;

            # should create the start state for rule 'a' (to save start state
            # competition), but should not create target of ID state. The
            # collection of ATN states the following ID references includes
            # states reached by traversing predicates. Since this is when we
            # test them, we cannot cash the DFA state target of ID.
            if self.debug
                print "EVAL rule #{t.ruleIndex}:#{t.predIndex}"
            end
            configs.hasSemanticContext = true
            if self.evaluatePredicate(input, t.ruleIndex, t.predIndex, speculative)
                c = LexerATNConfig(t.target,nil,nil,nil,nil, config)
            end
    elsif t.serializationType==Transition::ACTION
            if config.context.nil? or config.context.hasEmptyPath()
                # execute actions anywhere in the start rule for a token.
                #
                # TODO: if the entry rule is invoked recursively, some
                # actions may be executed during the recursive call. The
                # problem can appear when hasEmptyPath() is true but
                # isEmpty() is false. In this case, the config needs to be
                # split into two contexts - one with just the empty path
                # and another with everything but the empty path.
                # Unfortunately, the current algorithm does not allow
                # getEpsilonTarget to return two configurations, so
                # additional modifications are needed before we can support
                # the split operation.
                lexerActionExecutor = LexerActionExecutor.append(config.lexerActionExecutor,
                                self.atn.lexerActions[t.actionIndex])
                c = LexerATNConfig.new(t.target,nil,nil,nil, lexerActionExecutor, config)
            else
                # ignore actions in referenced rules
                c = LexerATNConfig.new(t.target,nil,nil,nil,nil, config)
            end
    elsif t.serializationType==Transition::EPSILON
          c = LexerATNConfig.new(t.target,nil,nil,nil,nil, config)
    elsif [ Transition::ATOM, Transition::RANGE, Transition::SET ].member? t.serializationType 
        if treatEofAsEpsilon
            if t.matches(Token::EOF, 0, 0xFFFF)
                c = LexerATNConfig.new(t.target,nil,nil,nil,nil, config)
            end
        end
    end
    return c
end

#getExistingTargetState(s, t) ⇒ Object

Get an existing target state for an edge in the DFA. If the target state for the edge has not yet been computed or is otherwise not available, this method returns null.

t, or null if the target state for this edge is not already cached

Parameters:

  • s

    The current DFA state

  • t

    The next input symbol

Returns:

  • The existing target DFA state for the given input symbol



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 201

def getExistingTargetState(s, t)
    if s.edges.nil?  or t < LexerATNSimulator::MIN_DFA_EDGE or t > LexerATNSimulator::MAX_DFA_EDGE
        return nil
    end

    target = s.edges[t - LexerATNSimulator::MIN_DFA_EDGE]
    if self.debug and not target.nil? 
        puts  "reuse state #{s.stateNumber} edge to #{target.stateNumber}"
    end

    return target
end

#getReachableConfigSet(input, closure, reach, t) ⇒ Object

Given a starting configuration set, figure out all ATN configurations

we can reach upon input {@code t}. Parameter {@code reach} is a return
parameter.


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 260

def getReachableConfigSet(input, closure, reach, t)
    # this is used to skip processing for configs which have a lower priority
    # than a config that already reached an accept state for the same rule
    skipAlt = ATN::INVALID_ALT_NUMBER
    for cfg in closure do
        currentAltReachedAcceptState = ( cfg.alt == skipAlt )
        if currentAltReachedAcceptState and cfg.passedThroughNonGreedyDecision
            next 
        end

        if self.debug
            puts "testing #{self.getTokenName(t)} at #{cfg.toString(self.recog, true)}"
        end

        for trans in cfg.state.transitions do        # for each transition
            target = self.getReachableTarget(trans, t)
            if target
                lexerActionExecutor = cfg.lexerActionExecutor
                if lexerActionExecutor 
                    lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index - self.startIndex)
                end
                treatEofAsEpsilon = (t == Token::EOF)
                config = LexerATNConfig.new(target, nil, nil, nil, lexerActionExecutor, cfg)
                if self.closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)
                    # any remaining configs for this alt have a lower priority than
                    # the one that just reached an accept state.
                    skipAlt = cfg.alt
                    break 
                end
           end

        end
    end
end

#getReachableTarget(trans, t) ⇒ Object



311
312
313
314
315
316
317
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 311

def getReachableTarget(trans, t)
    if trans.matches(t, 0, 0xFFFE)
        return trans.target
    else
        return nil
    end
end

#getText(input) ⇒ Object

Get the text matched so far for the current token.



591
592
593
594
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 591

def getText(input)
    # index is first lookahead char, don't include.
    return input.getText(self.startIndex, input.index-1)
end

#getTokenName(t) ⇒ Object



605
606
607
608
609
610
611
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 605

def getTokenName(t)
    if t==-1
        return "EOF"
    else
        return "'#{t.chr}'"
    end
end

#match(input, mode) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 80

def match(input, mode)
    @@match_calls =@@match_calls + 1
    self.mode = mode
    mark = input.mark()
    begin
        self.startIndex = input.index
        self.prevAccept.reset()
        dfa = self.decisionToDFA[mode]
        type_check(dfa, DFA)
        if dfa and dfa.s0.nil?  then
            return self.matchATN(input)
        else
            return self.execATN(input, dfa.s0)
        end
    ensure 
        input.release(mark)
    end
end

#match_callsObject



43
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 43

def match_calls; @@match_calls ;end

#matchATN(input) ⇒ Object



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
# File 'lib/antlr4/atn/LexerATNSimulator.rb', line 108

def matchATN(input)
    startState = self.atn.modeToStartState[self.mode]

    if self.debug then
        print "matchATN mode #{self.mode} start: #{startState}"
    end

    old_mode = self.mode
    s0_closure = self.computeStartState(input, startState)
    suppressEdge = s0_closure.hasSemanticContext
    s0_closure.hasSemanticContext = false

    nxt = self.addDFAState(s0_closure)
    if not suppressEdge then
        self.decisionToDFA[self.mode].s0 = nxt
    end

    predict = self.execATN(input, nxt)

    if self.debug then
        print  "DFA after matchATN: #{self.decisionToDFA[old_mode].toLexerString()}"
    end

    return predict
end

#resetObject



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

def reset
    self.prevAccept.reset()
    @startIndex = -1
    @line = 1
    @column = 0
    @mode = Lexer::DEFAULT_MODE
end