Merge pull request #2457 from khoroshilov/master

LexerATNSimulator: avoid repeatable import of Lexer
This commit is contained in:
ericvergnaud 2020-12-06 22:57:26 +08:00 committed by GitHub
commit 43d7eff27b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -219,6 +219,7 @@ YYYY/MM/DD, github id, Full name, email
2018/11/29, hannemann-tamas, Ralf Hannemann-Tamas, ralf.ht@gmail.com
2018/12/20, WalterCouto, Walter Couto, WalterCouto@users.noreply.github.com
2018/12/23, youkaichao, Kaichao You, youkaichao@gmail.com
2019/01/01, khoroshilov, Alexey Khoroshilov, khoroshilov@ispras.ru
2019/01/02, wkhemir, Wail Khemir, khemirwail@gmail.com
2019/01/16, kuegi, Markus Zancolo, markus.zancolo@roomle.com
2019/02/06, ralucado, Cristina Raluca Vijulie, ralucris.v[at]gmail[dot]com

View File

@ -75,6 +75,9 @@ class LexerATNSimulator(ATNSimulator):
self.column = 0
from antlr4.Lexer import Lexer
self.mode = Lexer.DEFAULT_MODE
# Cache Lexer properties to avoid further imports
self.DEFAULT_MODE = Lexer.DEFAULT_MODE
self.MAX_CHAR_VALUE = Lexer.MAX_CHAR_VALUE
# Used during DFA/ATN exec to record the most recent accept configuration info
self.prevAccept = SimState()
@ -105,8 +108,7 @@ class LexerATNSimulator(ATNSimulator):
self.startIndex = -1
self.line = 1
self.column = 0
from antlr4.Lexer import Lexer
self.mode = Lexer.DEFAULT_MODE
self.mode = self.DEFAULT_MODE
def matchATN(self, input:InputStream):
startState = self.atn.modeToStartState[self.mode]
@ -291,8 +293,7 @@ class LexerATNSimulator(ATNSimulator):
lexerActionExecutor.execute(self.recog, input, startIndex)
def getReachableTarget(self, trans:Transition, t:int):
from antlr4.Lexer import Lexer
if trans.matches(t, 0, Lexer.MAX_CHAR_VALUE):
if trans.matches(t, 0, self.MAX_CHAR_VALUE):
return trans.target
else:
return None
@ -420,8 +421,7 @@ class LexerATNSimulator(ATNSimulator):
elif t.serializationType in [ Transition.ATOM, Transition.RANGE, Transition.SET ]:
if treatEofAsEpsilon:
from antlr4.Lexer import Lexer
if t.matches(Token.EOF, 0, Lexer.MAX_CHAR_VALUE):
if t.matches(Token.EOF, 0, self.MAX_CHAR_VALUE):
c = LexerATNConfig(state=t.target, config=config)
return c