LexerATNSimulator.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. #
  2. # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
  3. # Use of this file is governed by the BSD 3-clause license that
  4. # can be found in the LICENSE.txt file in the project root.
  5. #/
  6. # When we hit an accept state in either the DFA or the ATN, we
  7. # have to notify the character stream to start buffering characters
  8. # via {@link IntStream#mark} and record the current state. The current sim state
  9. # includes the current index into the input, the current line,
  10. # and current character position in that line. Note that the Lexer is
  11. # tracking the starting line and characterization of the token. These
  12. # variables track the "state" of the simulator when it hits an accept state.
  13. #
  14. # <p>We track these variables separately for the DFA and ATN simulation
  15. # because the DFA simulation often has to fail over to the ATN
  16. # simulation. If the ATN simulation fails, we need the DFA to fall
  17. # back to its previously accepted state, if any. If the ATN succeeds,
  18. # then the ATN does the accept and the DFA simulator that invoked it
  19. # can simply return the predicted token type.</p>
  20. #/
  21. from antlr4.PredictionContext import PredictionContextCache, SingletonPredictionContext, PredictionContext
  22. from antlr4.InputStream import InputStream
  23. from antlr4.Token import Token
  24. from antlr4.atn.ATN import ATN
  25. from antlr4.atn.ATNConfig import LexerATNConfig
  26. from antlr4.atn.ATNSimulator import ATNSimulator
  27. from antlr4.atn.ATNConfigSet import ATNConfigSet, OrderedATNConfigSet
  28. from antlr4.atn.ATNState import RuleStopState, ATNState
  29. from antlr4.atn.LexerActionExecutor import LexerActionExecutor
  30. from antlr4.atn.Transition import Transition
  31. from antlr4.dfa.DFAState import DFAState
  32. from antlr4.error.Errors import LexerNoViableAltException, UnsupportedOperationException
  33. class SimState(object):
  34. __slots__ = ('index', 'line', 'column', 'dfaState')
  35. def __init__(self):
  36. self.reset()
  37. def reset(self):
  38. self.index = -1
  39. self.line = 0
  40. self.column = -1
  41. self.dfaState = None
  42. # need forward declaration
  43. Lexer = None
  44. LexerATNSimulator = None
  45. class LexerATNSimulator(ATNSimulator):
  46. __slots__ = (
  47. 'decisionToDFA', 'recog', 'startIndex', 'line', 'column', 'mode',
  48. 'DEFAULT_MODE', 'MAX_CHAR_VALUE', 'prevAccept'
  49. )
  50. debug = False
  51. dfa_debug = False
  52. MIN_DFA_EDGE = 0
  53. MAX_DFA_EDGE = 127 # forces unicode to stay in ATN
  54. ERROR = None
  55. def __init__(self, recog:Lexer, atn:ATN, decisionToDFA:list, sharedContextCache:PredictionContextCache):
  56. super().__init__(atn, sharedContextCache)
  57. self.decisionToDFA = decisionToDFA
  58. self.recog = recog
  59. # The current token's starting index into the character stream.
  60. # Shared across DFA to ATN simulation in case the ATN fails and the
  61. # DFA did not have a previous accept state. In this case, we use the
  62. # ATN-generated exception object.
  63. self.startIndex = -1
  64. # line number 1..n within the input#/
  65. self.line = 1
  66. # The index of the character relative to the beginning of the line 0..n-1#/
  67. self.column = 0
  68. from antlr4.Lexer import Lexer
  69. self.mode = Lexer.DEFAULT_MODE
  70. # Cache Lexer properties to avoid further imports
  71. self.DEFAULT_MODE = Lexer.DEFAULT_MODE
  72. self.MAX_CHAR_VALUE = Lexer.MAX_CHAR_VALUE
  73. # Used during DFA/ATN exec to record the most recent accept configuration info
  74. self.prevAccept = SimState()
  75. def copyState(self, simulator:LexerATNSimulator ):
  76. self.column = simulator.column
  77. self.line = simulator.line
  78. self.mode = simulator.mode
  79. self.startIndex = simulator.startIndex
  80. def match(self, input:InputStream , mode:int):
  81. self.mode = mode
  82. mark = input.mark()
  83. try:
  84. self.startIndex = input.index
  85. self.prevAccept.reset()
  86. dfa = self.decisionToDFA[mode]
  87. if dfa.s0 is None:
  88. return self.matchATN(input)
  89. else:
  90. return self.execATN(input, dfa.s0)
  91. finally:
  92. input.release(mark)
  93. def reset(self):
  94. self.prevAccept.reset()
  95. self.startIndex = -1
  96. self.line = 1
  97. self.column = 0
  98. self.mode = self.DEFAULT_MODE
  99. def matchATN(self, input:InputStream):
  100. startState = self.atn.modeToStartState[self.mode]
  101. if LexerATNSimulator.debug:
  102. print("matchATN mode " + str(self.mode) + " start: " + str(startState))
  103. old_mode = self.mode
  104. s0_closure = self.computeStartState(input, startState)
  105. suppressEdge = s0_closure.hasSemanticContext
  106. s0_closure.hasSemanticContext = False
  107. next = self.addDFAState(s0_closure)
  108. if not suppressEdge:
  109. self.decisionToDFA[self.mode].s0 = next
  110. predict = self.execATN(input, next)
  111. if LexerATNSimulator.debug:
  112. print("DFA after matchATN: " + str(self.decisionToDFA[old_mode].toLexerString()))
  113. return predict
  114. def execATN(self, input:InputStream, ds0:DFAState):
  115. if LexerATNSimulator.debug:
  116. print("start state closure=" + str(ds0.configs))
  117. if ds0.isAcceptState:
  118. # allow zero-length tokens
  119. self.captureSimState(self.prevAccept, input, ds0)
  120. t = input.LA(1)
  121. s = ds0 # s is current/from DFA state
  122. while True: # while more work
  123. if LexerATNSimulator.debug:
  124. print("execATN loop starting closure:", str(s.configs))
  125. # As we move src->trg, src->trg, we keep track of the previous trg to
  126. # avoid looking up the DFA state again, which is expensive.
  127. # If the previous target was already part of the DFA, we might
  128. # be able to avoid doing a reach operation upon t. If s!=null,
  129. # it means that semantic predicates didn't prevent us from
  130. # creating a DFA state. Once we know s!=null, we check to see if
  131. # the DFA state has an edge already for t. If so, we can just reuse
  132. # it's configuration set; there's no point in re-computing it.
  133. # This is kind of like doing DFA simulation within the ATN
  134. # simulation because DFA simulation is really just a way to avoid
  135. # computing reach/closure sets. Technically, once we know that
  136. # we have a previously added DFA state, we could jump over to
  137. # the DFA simulator. But, that would mean popping back and forth
  138. # a lot and making things more complicated algorithmically.
  139. # This optimization makes a lot of sense for loops within DFA.
  140. # A character will take us back to an existing DFA state
  141. # that already has lots of edges out of it. e.g., .* in comments.
  142. # print("Target for:" + str(s) + " and:" + str(t))
  143. target = self.getExistingTargetState(s, t)
  144. # print("Existing:" + str(target))
  145. if target is None:
  146. target = self.computeTargetState(input, s, t)
  147. # print("Computed:" + str(target))
  148. if target == self.ERROR:
  149. break
  150. # If this is a consumable input element, make sure to consume before
  151. # capturing the accept state so the input index, line, and char
  152. # position accurately reflect the state of the interpreter at the
  153. # end of the token.
  154. if t != Token.EOF:
  155. self.consume(input)
  156. if target.isAcceptState:
  157. self.captureSimState(self.prevAccept, input, target)
  158. if t == Token.EOF:
  159. break
  160. t = input.LA(1)
  161. s = target # flip; current DFA target becomes new src/from state
  162. return self.failOrAccept(self.prevAccept, input, s.configs, t)
  163. # Get an existing target state for an edge in the DFA. If the target state
  164. # for the edge has not yet been computed or is otherwise not available,
  165. # this method returns {@code null}.
  166. #
  167. # @param s The current DFA state
  168. # @param t The next input symbol
  169. # @return The existing target DFA state for the given input symbol
  170. # {@code t}, or {@code null} if the target state for this edge is not
  171. # already cached
  172. def getExistingTargetState(self, s:DFAState, t:int):
  173. if s.edges is None or t < self.MIN_DFA_EDGE or t > self.MAX_DFA_EDGE:
  174. return None
  175. target = s.edges[t - self.MIN_DFA_EDGE]
  176. if LexerATNSimulator.debug and target is not None:
  177. print("reuse state", str(s.stateNumber), "edge to", str(target.stateNumber))
  178. return target
  179. # Compute a target state for an edge in the DFA, and attempt to add the
  180. # computed state and corresponding edge to the DFA.
  181. #
  182. # @param input The input stream
  183. # @param s The current DFA state
  184. # @param t The next input symbol
  185. #
  186. # @return The computed target DFA state for the given input symbol
  187. # {@code t}. If {@code t} does not lead to a valid DFA state, this method
  188. # returns {@link #ERROR}.
  189. def computeTargetState(self, input:InputStream, s:DFAState, t:int):
  190. reach = OrderedATNConfigSet()
  191. # if we don't find an existing DFA state
  192. # Fill reach starting from closure, following t transitions
  193. self.getReachableConfigSet(input, s.configs, reach, t)
  194. if len(reach)==0: # we got nowhere on t from s
  195. if not reach.hasSemanticContext:
  196. # we got nowhere on t, don't throw out this knowledge; it'd
  197. # cause a failover from DFA later.
  198. self. addDFAEdge(s, t, self.ERROR)
  199. # stop when we can't match any more char
  200. return self.ERROR
  201. # Add an edge from s to target DFA found/created for reach
  202. return self.addDFAEdge(s, t, cfgs=reach)
  203. def failOrAccept(self, prevAccept:SimState , input:InputStream, reach:ATNConfigSet, t:int):
  204. if self.prevAccept.dfaState is not None:
  205. lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
  206. self.accept(input, lexerActionExecutor, self.startIndex, prevAccept.index, prevAccept.line, prevAccept.column)
  207. return prevAccept.dfaState.prediction
  208. else:
  209. # if no accept and EOF is first char, return EOF
  210. if t==Token.EOF and input.index==self.startIndex:
  211. return Token.EOF
  212. raise LexerNoViableAltException(self.recog, input, self.startIndex, reach)
  213. # Given a starting configuration set, figure out all ATN configurations
  214. # we can reach upon input {@code t}. Parameter {@code reach} is a return
  215. # parameter.
  216. def getReachableConfigSet(self, input:InputStream, closure:ATNConfigSet, reach:ATNConfigSet, t:int):
  217. # this is used to skip processing for configs which have a lower priority
  218. # than a config that already reached an accept state for the same rule
  219. skipAlt = ATN.INVALID_ALT_NUMBER
  220. for cfg in closure:
  221. currentAltReachedAcceptState = ( cfg.alt == skipAlt )
  222. if currentAltReachedAcceptState and cfg.passedThroughNonGreedyDecision:
  223. continue
  224. if LexerATNSimulator.debug:
  225. print("testing", self.getTokenName(t), "at", str(cfg))
  226. for trans in cfg.state.transitions: # for each transition
  227. target = self.getReachableTarget(trans, t)
  228. if target is not None:
  229. lexerActionExecutor = cfg.lexerActionExecutor
  230. if lexerActionExecutor is not None:
  231. lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index - self.startIndex)
  232. treatEofAsEpsilon = (t == Token.EOF)
  233. config = LexerATNConfig(state=target, lexerActionExecutor=lexerActionExecutor, config=cfg)
  234. if self.closure(input, config, reach, currentAltReachedAcceptState, True, treatEofAsEpsilon):
  235. # any remaining configs for this alt have a lower priority than
  236. # the one that just reached an accept state.
  237. skipAlt = cfg.alt
  238. def accept(self, input:InputStream, lexerActionExecutor:LexerActionExecutor, startIndex:int, index:int, line:int, charPos:int):
  239. if LexerATNSimulator.debug:
  240. print("ACTION", lexerActionExecutor)
  241. # seek to after last char in token
  242. input.seek(index)
  243. self.line = line
  244. self.column = charPos
  245. if lexerActionExecutor is not None and self.recog is not None:
  246. lexerActionExecutor.execute(self.recog, input, startIndex)
  247. def getReachableTarget(self, trans:Transition, t:int):
  248. if trans.matches(t, 0, self.MAX_CHAR_VALUE):
  249. return trans.target
  250. else:
  251. return None
  252. def computeStartState(self, input:InputStream, p:ATNState):
  253. initialContext = PredictionContext.EMPTY
  254. configs = OrderedATNConfigSet()
  255. for i in range(0,len(p.transitions)):
  256. target = p.transitions[i].target
  257. c = LexerATNConfig(state=target, alt=i+1, context=initialContext)
  258. self.closure(input, c, configs, False, False, False)
  259. return configs
  260. # Since the alternatives within any lexer decision are ordered by
  261. # preference, this method stops pursuing the closure as soon as an accept
  262. # state is reached. After the first accept state is reached by depth-first
  263. # search from {@code config}, all other (potentially reachable) states for
  264. # this rule would have a lower priority.
  265. #
  266. # @return {@code true} if an accept state is reached, otherwise
  267. # {@code false}.
  268. def closure(self, input:InputStream, config:LexerATNConfig, configs:ATNConfigSet, currentAltReachedAcceptState:bool,
  269. speculative:bool, treatEofAsEpsilon:bool):
  270. if LexerATNSimulator.debug:
  271. print("closure(" + str(config) + ")")
  272. if isinstance( config.state, RuleStopState ):
  273. if LexerATNSimulator.debug:
  274. if self.recog is not None:
  275. print("closure at", self.recog.symbolicNames[config.state.ruleIndex], "rule stop", str(config))
  276. else:
  277. print("closure at rule stop", str(config))
  278. if config.context is None or config.context.hasEmptyPath():
  279. if config.context is None or config.context.isEmpty():
  280. configs.add(config)
  281. return True
  282. else:
  283. configs.add(LexerATNConfig(state=config.state, config=config, context=PredictionContext.EMPTY))
  284. currentAltReachedAcceptState = True
  285. if config.context is not None and not config.context.isEmpty():
  286. for i in range(0,len(config.context)):
  287. if config.context.getReturnState(i) != PredictionContext.EMPTY_RETURN_STATE:
  288. newContext = config.context.getParent(i) # "pop" return state
  289. returnState = self.atn.states[config.context.getReturnState(i)]
  290. c = LexerATNConfig(state=returnState, config=config, context=newContext)
  291. currentAltReachedAcceptState = self.closure(input, c, configs,
  292. currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
  293. return currentAltReachedAcceptState
  294. # optimization
  295. if not config.state.epsilonOnlyTransitions:
  296. if not currentAltReachedAcceptState or not config.passedThroughNonGreedyDecision:
  297. configs.add(config)
  298. for t in config.state.transitions:
  299. c = self.getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon)
  300. if c is not None:
  301. currentAltReachedAcceptState = self.closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
  302. return currentAltReachedAcceptState
  303. # side-effect: can alter configs.hasSemanticContext
  304. def getEpsilonTarget(self, input:InputStream, config:LexerATNConfig, t:Transition, configs:ATNConfigSet,
  305. speculative:bool, treatEofAsEpsilon:bool):
  306. c = None
  307. if t.serializationType==Transition.RULE:
  308. newContext = SingletonPredictionContext.create(config.context, t.followState.stateNumber)
  309. c = LexerATNConfig(state=t.target, config=config, context=newContext)
  310. elif t.serializationType==Transition.PRECEDENCE:
  311. raise UnsupportedOperationException("Precedence predicates are not supported in lexers.")
  312. elif t.serializationType==Transition.PREDICATE:
  313. # Track traversing semantic predicates. If we traverse,
  314. # we cannot add a DFA state for this "reach" computation
  315. # because the DFA would not test the predicate again in the
  316. # future. Rather than creating collections of semantic predicates
  317. # like v3 and testing them on prediction, v4 will test them on the
  318. # fly all the time using the ATN not the DFA. This is slower but
  319. # semantically it's not used that often. One of the key elements to
  320. # this predicate mechanism is not adding DFA states that see
  321. # predicates immediately afterwards in the ATN. For example,
  322. # a : ID {p1}? | ID {p2}? ;
  323. # should create the start state for rule 'a' (to save start state
  324. # competition), but should not create target of ID state. The
  325. # collection of ATN states the following ID references includes
  326. # states reached by traversing predicates. Since this is when we
  327. # test them, we cannot cash the DFA state target of ID.
  328. if LexerATNSimulator.debug:
  329. print("EVAL rule "+ str(t.ruleIndex) + ":" + str(t.predIndex))
  330. configs.hasSemanticContext = True
  331. if self.evaluatePredicate(input, t.ruleIndex, t.predIndex, speculative):
  332. c = LexerATNConfig(state=t.target, config=config)
  333. elif t.serializationType==Transition.ACTION:
  334. if config.context is None or config.context.hasEmptyPath():
  335. # execute actions anywhere in the start rule for a token.
  336. #
  337. # TODO: if the entry rule is invoked recursively, some
  338. # actions may be executed during the recursive call. The
  339. # problem can appear when hasEmptyPath() is true but
  340. # isEmpty() is false. In this case, the config needs to be
  341. # split into two contexts - one with just the empty path
  342. # and another with everything but the empty path.
  343. # Unfortunately, the current algorithm does not allow
  344. # getEpsilonTarget to return two configurations, so
  345. # additional modifications are needed before we can support
  346. # the split operation.
  347. lexerActionExecutor = LexerActionExecutor.append(config.lexerActionExecutor,
  348. self.atn.lexerActions[t.actionIndex])
  349. c = LexerATNConfig(state=t.target, config=config, lexerActionExecutor=lexerActionExecutor)
  350. else:
  351. # ignore actions in referenced rules
  352. c = LexerATNConfig(state=t.target, config=config)
  353. elif t.serializationType==Transition.EPSILON:
  354. c = LexerATNConfig(state=t.target, config=config)
  355. elif t.serializationType in [ Transition.ATOM, Transition.RANGE, Transition.SET ]:
  356. if treatEofAsEpsilon:
  357. if t.matches(Token.EOF, 0, self.MAX_CHAR_VALUE):
  358. c = LexerATNConfig(state=t.target, config=config)
  359. return c
  360. # Evaluate a predicate specified in the lexer.
  361. #
  362. # <p>If {@code speculative} is {@code true}, this method was called before
  363. # {@link #consume} for the matched character. This method should call
  364. # {@link #consume} before evaluating the predicate to ensure position
  365. # sensitive values, including {@link Lexer#getText}, {@link Lexer#getLine},
  366. # and {@link Lexer#getcolumn}, properly reflect the current
  367. # lexer state. This method should restore {@code input} and the simulator
  368. # to the original state before returning (i.e. undo the actions made by the
  369. # call to {@link #consume}.</p>
  370. #
  371. # @param input The input stream.
  372. # @param ruleIndex The rule containing the predicate.
  373. # @param predIndex The index of the predicate within the rule.
  374. # @param speculative {@code true} if the current index in {@code input} is
  375. # one character before the predicate's location.
  376. #
  377. # @return {@code true} if the specified predicate evaluates to
  378. # {@code true}.
  379. #/
  380. def evaluatePredicate(self, input:InputStream, ruleIndex:int, predIndex:int, speculative:bool):
  381. # assume true if no recognizer was provided
  382. if self.recog is None:
  383. return True
  384. if not speculative:
  385. return self.recog.sempred(None, ruleIndex, predIndex)
  386. savedcolumn = self.column
  387. savedLine = self.line
  388. index = input.index
  389. marker = input.mark()
  390. try:
  391. self.consume(input)
  392. return self.recog.sempred(None, ruleIndex, predIndex)
  393. finally:
  394. self.column = savedcolumn
  395. self.line = savedLine
  396. input.seek(index)
  397. input.release(marker)
  398. def captureSimState(self, settings:SimState, input:InputStream, dfaState:DFAState):
  399. settings.index = input.index
  400. settings.line = self.line
  401. settings.column = self.column
  402. settings.dfaState = dfaState
  403. def addDFAEdge(self, from_:DFAState, tk:int, to:DFAState=None, cfgs:ATNConfigSet=None) -> DFAState:
  404. if to is None and cfgs is not None:
  405. # leading to this call, ATNConfigSet.hasSemanticContext is used as a
  406. # marker indicating dynamic predicate evaluation makes this edge
  407. # dependent on the specific input sequence, so the static edge in the
  408. # DFA should be omitted. The target DFAState is still created since
  409. # execATN has the ability to resynchronize with the DFA state cache
  410. # following the predicate evaluation step.
  411. #
  412. # TJP notes: next time through the DFA, we see a pred again and eval.
  413. # If that gets us to a previously created (but dangling) DFA
  414. # state, we can continue in pure DFA mode from there.
  415. #/
  416. suppressEdge = cfgs.hasSemanticContext
  417. cfgs.hasSemanticContext = False
  418. to = self.addDFAState(cfgs)
  419. if suppressEdge:
  420. return to
  421. # add the edge
  422. if tk < self.MIN_DFA_EDGE or tk > self.MAX_DFA_EDGE:
  423. # Only track edges within the DFA bounds
  424. return to
  425. if LexerATNSimulator.debug:
  426. print("EDGE " + str(from_) + " -> " + str(to) + " upon "+ chr(tk))
  427. if from_.edges is None:
  428. # make room for tokens 1..n and -1 masquerading as index 0
  429. from_.edges = [ None ] * (self.MAX_DFA_EDGE - self.MIN_DFA_EDGE + 1)
  430. from_.edges[tk - self.MIN_DFA_EDGE] = to # connect
  431. return to
  432. # Add a new DFA state if there isn't one with this set of
  433. # configurations already. This method also detects the first
  434. # configuration containing an ATN rule stop state. Later, when
  435. # traversing the DFA, we will know which rule to accept.
  436. def addDFAState(self, configs:ATNConfigSet) -> DFAState:
  437. proposed = DFAState(configs=configs)
  438. firstConfigWithRuleStopState = next((cfg for cfg in configs if isinstance(cfg.state, RuleStopState)), None)
  439. if firstConfigWithRuleStopState is not None:
  440. proposed.isAcceptState = True
  441. proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor
  442. proposed.prediction = self.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex]
  443. dfa = self.decisionToDFA[self.mode]
  444. existing = dfa.states.get(proposed, None)
  445. if existing is not None:
  446. return existing
  447. newState = proposed
  448. newState.stateNumber = len(dfa.states)
  449. configs.setReadonly(True)
  450. newState.configs = configs
  451. dfa.states[newState] = newState
  452. return newState
  453. def getDFA(self, mode:int):
  454. return self.decisionToDFA[mode]
  455. # Get the text matched so far for the current token.
  456. def getText(self, input:InputStream):
  457. # index is first lookahead char, don't include.
  458. return input.getText(self.startIndex, input.index-1)
  459. def consume(self, input:InputStream):
  460. curChar = input.LA(1)
  461. if curChar==ord('\n'):
  462. self.line += 1
  463. self.column = 0
  464. else:
  465. self.column += 1
  466. input.consume()
  467. def getTokenName(self, t:int):
  468. if t==-1:
  469. return "EOF"
  470. else:
  471. return "'" + chr(t) + "'"
  472. LexerATNSimulator.ERROR = DFAState(0x7FFFFFFF, ATNConfigSet())
  473. del Lexer