Skip to content

Commit 2c5cc31

Browse files
authored
Py runtime: Move to relative imports (#4705)
Signed-off-by: Phil Elson <[email protected]>
1 parent c251d2d commit 2c5cc31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+234
-232
lines changed

runtime/Python3/src/antlr4/BufferedTokenStream.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# {@link Token#HIDDEN_CHANNEL}, use a filtering token stream such a
1515
# {@link CommonTokenStream}.</p>
1616
from io import StringIO
17-
from antlr4.Token import Token
18-
from antlr4.error.Errors import IllegalStateException
17+
from .Token import Token
18+
from .error.Errors import IllegalStateException
1919

2020
# need forward declaration
2121
Lexer = None
@@ -230,7 +230,7 @@ def getHiddenTokensToRight(self, tokenIndex:int, channel:int=-1):
230230
self.lazyInit()
231231
if tokenIndex<0 or tokenIndex>=len(self.tokens):
232232
raise Exception(str(tokenIndex) + " not in 0.." + str(len(self.tokens)-1))
233-
from antlr4.Lexer import Lexer
233+
from .Lexer import Lexer
234234
nextOnChannel = self.nextTokenOnChannel(tokenIndex + 1, Lexer.DEFAULT_TOKEN_CHANNEL)
235235
from_ = tokenIndex+1
236236
# if none onchannel to right, nextOnChannel=-1 so set to = last token
@@ -245,7 +245,7 @@ def getHiddenTokensToLeft(self, tokenIndex:int, channel:int=-1):
245245
self.lazyInit()
246246
if tokenIndex<0 or tokenIndex>=len(self.tokens):
247247
raise Exception(str(tokenIndex) + " not in 0.." + str(len(self.tokens)-1))
248-
from antlr4.Lexer import Lexer
248+
from .Lexer import Lexer
249249
prevOnChannel = self.previousTokenOnChannel(tokenIndex - 1, Lexer.DEFAULT_TOKEN_CHANNEL)
250250
if prevOnChannel == tokenIndex - 1:
251251
return None
@@ -260,7 +260,7 @@ def filterForChannel(self, left:int, right:int, channel:int):
260260
for i in range(left, right+1):
261261
t = self.tokens[i]
262262
if channel==-1:
263-
from antlr4.Lexer import Lexer
263+
from .Lexer import Lexer
264264
if t.channel!= Lexer.DEFAULT_TOKEN_CHANNEL:
265265
hidden.append(t)
266266
elif t.channel==channel:

runtime/Python3/src/antlr4/CommonTokenFactory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# This default implementation of {@link TokenFactory} creates
99
# {@link CommonToken} objects.
1010
#
11-
from antlr4.Token import CommonToken
11+
from .Token import CommonToken
1212

1313
class TokenFactory(object):
1414

runtime/Python3/src/antlr4/CommonTokenStream.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
# channel.</p>
3030
#/
3131

32-
from antlr4.BufferedTokenStream import BufferedTokenStream
33-
from antlr4.Lexer import Lexer
34-
from antlr4.Token import Token
32+
from .BufferedTokenStream import BufferedTokenStream
33+
from .Lexer import Lexer
34+
from .Token import Token
3535

3636

3737
class CommonTokenStream(BufferedTokenStream):

runtime/Python3/src/antlr4/FileStream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111

1212
import codecs
13-
from antlr4.InputStream import InputStream
13+
from .InputStream import InputStream
1414

1515

1616
class FileStream(InputStream):

runtime/Python3/src/antlr4/InputStream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
# Vacuum all input from a string and then treat it like a buffer.
1010
#
11-
from antlr4.Token import Token
11+
from .Token import Token
1212

1313

1414
class InputStream (object):

runtime/Python3/src/antlr4/IntervalSet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
from io import StringIO
8-
from antlr4.Token import Token
8+
from .Token import Token
99

1010
# need forward declarations
1111
IntervalSet = None

runtime/Python3/src/antlr4/LL1Analyzer.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Use of this file is governed by the BSD 3-clause license that
44
# can be found in the LICENSE.txt file in the project root.
55
#/
6-
from antlr4.IntervalSet import IntervalSet
7-
from antlr4.Token import Token
8-
from antlr4.PredictionContext import PredictionContext, SingletonPredictionContext, PredictionContextFromRuleContext
9-
from antlr4.RuleContext import RuleContext
10-
from antlr4.atn.ATN import ATN
11-
from antlr4.atn.ATNConfig import ATNConfig
12-
from antlr4.atn.ATNState import ATNState, RuleStopState
13-
from antlr4.atn.Transition import WildcardTransition, NotSetTransition, AbstractPredicateTransition, RuleTransition
6+
from .IntervalSet import IntervalSet
7+
from .Token import Token
8+
from .PredictionContext import PredictionContext, SingletonPredictionContext, PredictionContextFromRuleContext
9+
from .RuleContext import RuleContext
10+
from .atn.ATN import ATN
11+
from .atn.ATNConfig import ATNConfig
12+
from .atn.ATNState import ATNState, RuleStopState
13+
from .atn.Transition import WildcardTransition, NotSetTransition, AbstractPredicateTransition, RuleTransition
1414

1515

1616
class LL1Analyzer (object):

runtime/Python3/src/antlr4/Lexer.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from typing import TextIO
1616
else:
1717
from typing.io import TextIO
18-
from antlr4.CommonTokenFactory import CommonTokenFactory
19-
from antlr4.atn.LexerATNSimulator import LexerATNSimulator
20-
from antlr4.InputStream import InputStream
21-
from antlr4.Recognizer import Recognizer
22-
from antlr4.Token import Token
23-
from antlr4.error.Errors import IllegalStateException, LexerNoViableAltException, RecognitionException
18+
from .CommonTokenFactory import CommonTokenFactory
19+
from .atn.LexerATNSimulator import LexerATNSimulator
20+
from .InputStream import InputStream
21+
from .Recognizer import Recognizer
22+
from .Token import Token
23+
from .error.Errors import IllegalStateException, LexerNoViableAltException, RecognitionException
2424

2525
class TokenSource(object):
2626

runtime/Python3/src/antlr4/ListTokenSource.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# as the EOF token for every call to {@link #nextToken} after the end of the
1313
# list is reached. Otherwise, an EOF token will be created.</p>
1414
#
15-
from antlr4.CommonTokenFactory import CommonTokenFactory
16-
from antlr4.Lexer import TokenSource
17-
from antlr4.Token import Token
15+
from .CommonTokenFactory import CommonTokenFactory
16+
from .Lexer import TokenSource
17+
from .Token import Token
1818

1919

2020
class ListTokenSource(TokenSource):

runtime/Python3/src/antlr4/Parser.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
from typing import TextIO
88
else:
99
from typing.io import TextIO
10-
from antlr4.BufferedTokenStream import TokenStream
11-
from antlr4.CommonTokenFactory import TokenFactory
12-
from antlr4.error.ErrorStrategy import DefaultErrorStrategy
13-
from antlr4.InputStream import InputStream
14-
from antlr4.Recognizer import Recognizer
15-
from antlr4.RuleContext import RuleContext
16-
from antlr4.ParserRuleContext import ParserRuleContext
17-
from antlr4.Token import Token
18-
from antlr4.Lexer import Lexer
19-
from antlr4.atn.ATNDeserializer import ATNDeserializer
20-
from antlr4.atn.ATNDeserializationOptions import ATNDeserializationOptions
21-
from antlr4.error.Errors import UnsupportedOperationException, RecognitionException
22-
from antlr4.tree.ParseTreePatternMatcher import ParseTreePatternMatcher
23-
from antlr4.tree.Tree import ParseTreeListener, TerminalNode, ErrorNode
10+
from .BufferedTokenStream import TokenStream
11+
from .CommonTokenFactory import TokenFactory
12+
from .error.ErrorStrategy import DefaultErrorStrategy
13+
from .InputStream import InputStream
14+
from .Recognizer import Recognizer
15+
from .RuleContext import RuleContext
16+
from .ParserRuleContext import ParserRuleContext
17+
from .Token import Token
18+
from .Lexer import Lexer
19+
from .atn.ATNDeserializer import ATNDeserializer
20+
from .atn.ATNDeserializationOptions import ATNDeserializationOptions
21+
from .error.Errors import UnsupportedOperationException, RecognitionException
22+
from .tree.ParseTreePatternMatcher import ParseTreePatternMatcher
23+
from .tree.Tree import ParseTreeListener, TerminalNode, ErrorNode
2424

2525
class TraceListener(ParseTreeListener):
2626
__slots__ = '_parser'

runtime/Python3/src/antlr4/ParserInterpreter.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
#
1818
# See TestParserInterpreter for examples.
1919
#
20-
from antlr4.dfa.DFA import DFA
21-
from antlr4.BufferedTokenStream import TokenStream
22-
from antlr4.Lexer import Lexer
23-
from antlr4.Parser import Parser
24-
from antlr4.ParserRuleContext import InterpreterRuleContext, ParserRuleContext
25-
from antlr4.Token import Token
26-
from antlr4.atn.ATN import ATN
27-
from antlr4.atn.ATNState import StarLoopEntryState, ATNState, LoopEndState
28-
from antlr4.atn.ParserATNSimulator import ParserATNSimulator
29-
from antlr4.PredictionContext import PredictionContextCache
30-
from antlr4.atn.Transition import Transition
31-
from antlr4.error.Errors import RecognitionException, UnsupportedOperationException, FailedPredicateException
20+
from .dfa.DFA import DFA
21+
from .BufferedTokenStream import TokenStream
22+
from .Lexer import Lexer
23+
from .Parser import Parser
24+
from .ParserRuleContext import InterpreterRuleContext, ParserRuleContext
25+
from .Token import Token
26+
from .atn.ATN import ATN
27+
from .atn.ATNState import StarLoopEntryState, ATNState, LoopEndState
28+
from .atn.ParserATNSimulator import ParserATNSimulator
29+
from .PredictionContext import PredictionContextCache
30+
from .atn.Transition import Transition
31+
from .error.Errors import RecognitionException, UnsupportedOperationException, FailedPredicateException
3232

3333

3434
class ParserInterpreter(Parser):

runtime/Python3/src/antlr4/ParserRuleContext.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
# group values such as this aggregate. The getters/setters are there to
2626
# satisfy the superclass interface.
2727

28-
from antlr4.RuleContext import RuleContext
29-
from antlr4.Token import Token
30-
from antlr4.tree.Tree import ParseTreeListener, ParseTree, TerminalNodeImpl, ErrorNodeImpl, TerminalNode, \
28+
from .RuleContext import RuleContext
29+
from .Token import Token
30+
from .tree.Tree import ParseTreeListener, ParseTree, TerminalNodeImpl, ErrorNodeImpl, TerminalNode, \
3131
INVALID_INTERVAL
3232

3333
# need forward declaration

runtime/Python3/src/antlr4/PredictionContext.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Use of this file is governed by the BSD 3-clause license that
44
# can be found in the LICENSE.txt file in the project root.
55
#/
6-
from antlr4.RuleContext import RuleContext
7-
from antlr4.atn.ATN import ATN
8-
from antlr4.error.Errors import IllegalStateException
6+
from .RuleContext import RuleContext
7+
from .atn.ATN import ATN
8+
from .error.Errors import IllegalStateException
99
from io import StringIO
1010

1111
# dup ParserATNSimulator class var here to avoid circular import; no idea why this can't be in PredictionContext

runtime/Python3/src/antlr4/Recognizer.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Use of this file is governed by the BSD 3-clause license that
44
# can be found in the LICENSE.txt file in the project root.
55
#
6-
from antlr4.RuleContext import RuleContext
7-
from antlr4.Token import Token
8-
from antlr4.error.ErrorListener import ProxyErrorListener, ConsoleErrorListener
6+
from .RuleContext import RuleContext
7+
from .Token import Token
8+
from .error.ErrorListener import ProxyErrorListener, ConsoleErrorListener
99

1010
# need forward delcaration
1111
RecognitionException = None
@@ -52,7 +52,7 @@ def removeErrorListeners(self):
5252
def getTokenTypeMap(self):
5353
tokenNames = self.getTokenNames()
5454
if tokenNames is None:
55-
from antlr4.error.Errors import UnsupportedOperationException
55+
from .error.Errors import UnsupportedOperationException
5656
raise UnsupportedOperationException("The current recognizer does not provide a list of token names.")
5757
result = self.tokenTypeMapCache.get(tokenNames, None)
5858
if result is None:
@@ -68,7 +68,7 @@ def getTokenTypeMap(self):
6868
def getRuleIndexMap(self):
6969
ruleNames = self.getRuleNames()
7070
if ruleNames is None:
71-
from antlr4.error.Errors import UnsupportedOperationException
71+
from .error.Errors import UnsupportedOperationException
7272
raise UnsupportedOperationException("The current recognizer does not provide a list of rule names.")
7373
result = self.ruleIndexMapCache.get(ruleNames, None)
7474
if result is None:

runtime/Python3/src/antlr4/RuleContext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
# @see ParserRuleContext
2626
#/
2727
from io import StringIO
28-
from antlr4.tree.Tree import RuleNode, INVALID_INTERVAL, ParseTreeVisitor
29-
from antlr4.tree.Trees import Trees
28+
from .tree.Tree import RuleNode, INVALID_INTERVAL, ParseTreeVisitor
29+
from .tree.Trees import Trees
3030

3131
# need forward declarations
3232
RuleContext = None

runtime/Python3/src/antlr4/StdinStream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import codecs
22
import sys
33

4-
from antlr4.InputStream import InputStream
4+
from .InputStream import InputStream
55

66

77
class StdinStream(InputStream):

runtime/Python3/src/antlr4/TokenStreamRewriter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#
66

77
from io import StringIO
8-
from antlr4.Token import Token
8+
from .Token import Token
99

10-
from antlr4.CommonTokenStream import CommonTokenStream
10+
from .CommonTokenStream import CommonTokenStream
1111

1212

1313
class TokenStreamRewriter(object):
+21-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
from antlr4.Token import Token
2-
from antlr4.InputStream import InputStream
3-
from antlr4.FileStream import FileStream
4-
from antlr4.StdinStream import StdinStream
5-
from antlr4.BufferedTokenStream import TokenStream
6-
from antlr4.CommonTokenStream import CommonTokenStream
7-
from antlr4.Lexer import Lexer
8-
from antlr4.Parser import Parser
9-
from antlr4.dfa.DFA import DFA
10-
from antlr4.atn.ATN import ATN
11-
from antlr4.atn.ATNDeserializer import ATNDeserializer
12-
from antlr4.atn.LexerATNSimulator import LexerATNSimulator
13-
from antlr4.atn.ParserATNSimulator import ParserATNSimulator
14-
from antlr4.atn.PredictionMode import PredictionMode
15-
from antlr4.PredictionContext import PredictionContextCache
16-
from antlr4.ParserRuleContext import RuleContext, ParserRuleContext
17-
from antlr4.tree.Tree import ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, TerminalNode, ErrorNode, RuleNode
18-
from antlr4.error.Errors import RecognitionException, IllegalStateException, NoViableAltException
19-
from antlr4.error.ErrorStrategy import BailErrorStrategy
20-
from antlr4.error.DiagnosticErrorListener import DiagnosticErrorListener
21-
from antlr4.Utils import str_list
1+
from .Token import Token
2+
from .InputStream import InputStream
3+
from .FileStream import FileStream
4+
from .StdinStream import StdinStream
5+
from .BufferedTokenStream import TokenStream
6+
from .CommonTokenStream import CommonTokenStream
7+
from .Lexer import Lexer
8+
from .Parser import Parser
9+
from .dfa.DFA import DFA
10+
from .atn.ATN import ATN
11+
from .atn.ATNDeserializer import ATNDeserializer
12+
from .atn.LexerATNSimulator import LexerATNSimulator
13+
from .atn.ParserATNSimulator import ParserATNSimulator
14+
from .atn.PredictionMode import PredictionMode
15+
from .PredictionContext import PredictionContextCache
16+
from .ParserRuleContext import RuleContext, ParserRuleContext
17+
from .tree.Tree import ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, TerminalNode, ErrorNode, RuleNode
18+
from .error.Errors import RecognitionException, IllegalStateException, NoViableAltException
19+
from .error.ErrorStrategy import BailErrorStrategy
20+
from .error.DiagnosticErrorListener import DiagnosticErrorListener
21+
from .Utils import str_list

runtime/Python3/src/antlr4/_pygrun.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#!python
21
__author__ = 'jszheng'
32
import optparse
43
import sys
54
import os
6-
import importlib
7-
from antlr4 import *
5+
6+
from . import *
87

98

109
# this is a python version of TestRig
@@ -165,7 +164,3 @@ def process(input_stream, class_lexer, class_parser):
165164
process(input_stream, class_lexer, class_parser)
166165
else:
167166
print("[ERROR] file {} not exist".format(os.path.normpath(file_name)))
168-
169-
170-
if __name__ == '__main__':
171-
main()

runtime/Python3/src/antlr4/atn/ATN.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Use of this file is governed by the BSD 3-clause license that
33
# can be found in the LICENSE.txt file in the project root.
44
#/
5-
from antlr4.IntervalSet import IntervalSet
5+
from ..IntervalSet import IntervalSet
66

7-
from antlr4.RuleContext import RuleContext
7+
from ..RuleContext import RuleContext
88

9-
from antlr4.Token import Token
10-
from antlr4.atn.ATNType import ATNType
11-
from antlr4.atn.ATNState import ATNState, DecisionState
9+
from ..Token import Token
10+
from ..atn.ATNType import ATNType
11+
from ..atn.ATNState import ATNState, DecisionState
1212

1313

1414
class ATN(object):
@@ -52,7 +52,7 @@ def __init__(self, grammarType:ATNType , maxTokenType:int ):
5252
# the rule surrounding {@code s}. In other words, the set will be
5353
# restricted to tokens reachable staying within {@code s}'s rule.
5454
def nextTokensInContext(self, s:ATNState, ctx:RuleContext):
55-
from antlr4.LL1Analyzer import LL1Analyzer
55+
from ..LL1Analyzer import LL1Analyzer
5656
anal = LL1Analyzer(self)
5757
return anal.LOOK(s, ctx=ctx)
5858

0 commit comments

Comments
 (0)