diff --git a/cf_units/_udunits2_parser/__init__.py b/cf_units/_udunits2_parser/__init__.py index 6041409a..63113cc5 100644 --- a/cf_units/_udunits2_parser/__init__.py +++ b/cf_units/_udunits2_parser/__init__.py @@ -10,7 +10,7 @@ CommonTokenStream, InputStream, ) -from ._antlr4_runtime.error import ( +from ._antlr4_runtime.error.ErrorListener import ( ErrorListener, ) from .parser.udunits2Lexer import udunits2Lexer diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/BufferedTokenStream.py b/cf_units/_udunits2_parser/_antlr4_runtime/BufferedTokenStream.py index 530272c3..a9b6ec4f 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/BufferedTokenStream.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/BufferedTokenStream.py @@ -15,10 +15,8 @@ # {@link CommonTokenStream}.
from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - IllegalStateException, -) -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .error.Errors import IllegalStateException +from .Token import Token # need forward declaration Lexer = None @@ -233,7 +231,7 @@ def getHiddenTokensToRight(self, tokenIndex: int, channel: int = -1): raise Exception( str(tokenIndex) + " not in 0.." + str(len(self.tokens) - 1) ) - from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer + from .Lexer import Lexer nextOnChannel = self.nextTokenOnChannel( tokenIndex + 1, Lexer.DEFAULT_TOKEN_CHANNEL @@ -252,7 +250,7 @@ def getHiddenTokensToLeft(self, tokenIndex: int, channel: int = -1): raise Exception( str(tokenIndex) + " not in 0.." + str(len(self.tokens) - 1) ) - from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer + from .Lexer import Lexer prevOnChannel = self.previousTokenOnChannel( tokenIndex - 1, Lexer.DEFAULT_TOKEN_CHANNEL @@ -269,9 +267,7 @@ def filterForChannel(self, left: int, right: int, channel: int): for i in range(left, right + 1): t = self.tokens[i] if channel == -1: - from cf_units._udunits2_parser._antlr4_runtime.Lexer import ( - Lexer, - ) + from .Lexer import Lexer if t.channel != Lexer.DEFAULT_TOKEN_CHANNEL: hidden.append(t) diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenFactory.py b/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenFactory.py index 0e5730bc..9e8d2d73 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenFactory.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenFactory.py @@ -8,7 +8,7 @@ # This default implementation of {@link TokenFactory} creates # {@link CommonToken} objects. # -from cf_units._udunits2_parser._antlr4_runtime.Token import CommonToken +from .Token import CommonToken class TokenFactory: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenStream.py b/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenStream.py index ad8a33a2..75675675 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenStream.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/CommonTokenStream.py @@ -29,11 +29,9 @@ # channel. # / -from cf_units._udunits2_parser._antlr4_runtime.BufferedTokenStream import ( - BufferedTokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .BufferedTokenStream import BufferedTokenStream +from .Lexer import Lexer +from .Token import Token class CommonTokenStream(BufferedTokenStream): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/FileStream.py b/cf_units/_udunits2_parser/_antlr4_runtime/FileStream.py index 54a8be25..a27bb0d8 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/FileStream.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/FileStream.py @@ -11,7 +11,7 @@ import codecs -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream +from .InputStream import InputStream class FileStream(InputStream): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/InputStream.py b/cf_units/_udunits2_parser/_antlr4_runtime/InputStream.py index 5c881bb7..4a816212 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/InputStream.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/InputStream.py @@ -8,7 +8,7 @@ # # Vacuum all input from a string and then treat it like a buffer. # -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .Token import Token class InputStream: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/IntervalSet.py b/cf_units/_udunits2_parser/_antlr4_runtime/IntervalSet.py index 326c297f..bc5664a6 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/IntervalSet.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/IntervalSet.py @@ -6,7 +6,7 @@ from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .Token import Token # need forward declarations IntervalSet = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/LL1Analyzer.py b/cf_units/_udunits2_parser/_antlr4_runtime/LL1Analyzer.py index 88410306..f06d1952 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/LL1Analyzer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/LL1Analyzer.py @@ -3,26 +3,23 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # / -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfig import ATNConfig -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - ATNState, - RuleStopState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import ( +from .atn.ATN import ATN +from .atn.ATNConfig import ATNConfig +from .atn.ATNState import ATNState, RuleStopState +from .atn.Transition import ( AbstractPredicateTransition, NotSetTransition, RuleTransition, WildcardTransition, ) -from cf_units._udunits2_parser._antlr4_runtime.IntervalSet import IntervalSet -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( +from .IntervalSet import IntervalSet +from .PredictionContext import ( PredictionContext, PredictionContextFromRuleContext, SingletonPredictionContext, ) -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .RuleContext import RuleContext +from .Token import Token class LL1Analyzer: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/Lexer.py b/cf_units/_udunits2_parser/_antlr4_runtime/Lexer.py index 127edbc8..d1e0c888 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/Lexer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/Lexer.py @@ -15,17 +15,15 @@ from typing import TextIO else: from typing.io import TextIO -from cf_units._udunits2_parser._antlr4_runtime.CommonTokenFactory import ( - CommonTokenFactory, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( +from .CommonTokenFactory import CommonTokenFactory +from .error.Errors import ( IllegalStateException, LexerNoViableAltException, RecognitionException, ) -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.Recognizer import Recognizer -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .InputStream import InputStream +from .Recognizer import Recognizer +from .Token import Token class TokenSource: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/ListTokenSource.py b/cf_units/_udunits2_parser/_antlr4_runtime/ListTokenSource.py index b3255bb3..05236021 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/ListTokenSource.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/ListTokenSource.py @@ -12,11 +12,9 @@ # as the EOF token for every call to {@link #nextToken} after the end of the # list is reached. Otherwise, an EOF token will be created. # -from cf_units._udunits2_parser._antlr4_runtime.CommonTokenFactory import ( - CommonTokenFactory, -) -from cf_units._udunits2_parser._antlr4_runtime.Lexer import TokenSource -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .CommonTokenFactory import CommonTokenFactory +from .Lexer import TokenSource +from .Token import Token class ListTokenSource(TokenSource): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/Parser.py b/cf_units/_udunits2_parser/_antlr4_runtime/Parser.py index e5aeaef4..d8e10ea0 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/Parser.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/Parser.py @@ -8,41 +8,20 @@ from typing import TextIO else: from typing.io import TextIO -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNDeserializationOptions import ( - ATNDeserializationOptions, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNDeserializer import ( - ATNDeserializer, -) -from cf_units._udunits2_parser._antlr4_runtime.BufferedTokenStream import ( - TokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.CommonTokenFactory import ( - TokenFactory, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - RecognitionException, - UnsupportedOperationException, -) -from cf_units._udunits2_parser._antlr4_runtime.error.ErrorStrategy import ( - DefaultErrorStrategy, -) -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer -from cf_units._udunits2_parser._antlr4_runtime.ParserRuleContext import ( - ParserRuleContext, -) -from cf_units._udunits2_parser._antlr4_runtime.Recognizer import Recognizer -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token -from cf_units._udunits2_parser._antlr4_runtime.tree.ParseTreePatternMatcher import ( - ParseTreePatternMatcher, -) -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ( - ErrorNode, - ParseTreeListener, - TerminalNode, -) +from .atn.ATNDeserializationOptions import ATNDeserializationOptions +from .atn.ATNDeserializer import ATNDeserializer +from .BufferedTokenStream import TokenStream +from .CommonTokenFactory import TokenFactory +from .error.Errors import RecognitionException, UnsupportedOperationException +from .error.ErrorStrategy import DefaultErrorStrategy +from .InputStream import InputStream +from .Lexer import Lexer +from .ParserRuleContext import ParserRuleContext +from .Recognizer import Recognizer +from .RuleContext import RuleContext +from .Token import Token +from .tree.ParseTreePatternMatcher import ParseTreePatternMatcher +from .tree.Tree import ErrorNode, ParseTreeListener, TerminalNode class TraceListener(ParseTreeListener): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/ParserInterpreter.py b/cf_units/_udunits2_parser/_antlr4_runtime/ParserInterpreter.py index f4ce5672..2298b813 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/ParserInterpreter.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/ParserInterpreter.py @@ -17,35 +17,22 @@ # # See TestParserInterpreter for examples. # -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - ATNState, - LoopEndState, - StarLoopEntryState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ParserATNSimulator import ( - ParserATNSimulator, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import Transition -from cf_units._udunits2_parser._antlr4_runtime.BufferedTokenStream import ( - TokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFA import DFA -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( +from .atn.ATN import ATN +from .atn.ATNState import ATNState, LoopEndState, StarLoopEntryState +from .atn.ParserATNSimulator import ParserATNSimulator +from .atn.Transition import Transition +from .BufferedTokenStream import TokenStream +from .dfa.DFA import DFA +from .error.Errors import ( FailedPredicateException, RecognitionException, UnsupportedOperationException, ) -from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer -from cf_units._udunits2_parser._antlr4_runtime.Parser import Parser -from cf_units._udunits2_parser._antlr4_runtime.ParserRuleContext import ( - InterpreterRuleContext, - ParserRuleContext, -) -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( - PredictionContextCache, -) -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .Lexer import Lexer +from .Parser import Parser +from .ParserRuleContext import InterpreterRuleContext, ParserRuleContext +from .PredictionContext import PredictionContextCache +from .Token import Token class ParserInterpreter(Parser): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/ParserRuleContext.py b/cf_units/_udunits2_parser/_antlr4_runtime/ParserRuleContext.py index 1f9e55fd..c71029bb 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/ParserRuleContext.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/ParserRuleContext.py @@ -25,9 +25,9 @@ # group values such as this aggregate. The getters/setters are there to # satisfy the superclass interface. -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ( +from .RuleContext import RuleContext +from .Token import Token +from .tree.Tree import ( INVALID_INTERVAL, ErrorNodeImpl, ParseTree, diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/PredictionContext.py b/cf_units/_udunits2_parser/_antlr4_runtime/PredictionContext.py index 603da8d7..96797116 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/PredictionContext.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/PredictionContext.py @@ -5,14 +5,9 @@ # / from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - IllegalStateException, -) -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext - -# dup ParserATNSimulator class var here to avoid circular import; no idea why this can't be in PredictionContext -_trace_atn_sim = False +from .atn.ATN import ATN +from .error.Errors import IllegalStateException +from .RuleContext import RuleContext class PredictionContext: @@ -488,17 +483,9 @@ def mergeArrays( if mergeCache is not None: previous = mergeCache.get((a, b), None) if previous is not None: - if _trace_atn_sim: - print( - "mergeArrays a=" + str(a) + ",b=" + str(b) + " -> previous" - ) return previous previous = mergeCache.get((b, a), None) if previous is not None: - if _trace_atn_sim: - print( - "mergeArrays a=" + str(a) + ",b=" + str(b) + " -> previous" - ) return previous # merge sorted payloads a + b => M @@ -576,23 +563,15 @@ def mergeArrays( if merged == a: if mergeCache is not None: mergeCache[(a, b)] = a - if _trace_atn_sim: - print("mergeArrays a=" + str(a) + ",b=" + str(b) + " -> a") return a if merged == b: if mergeCache is not None: mergeCache[(a, b)] = b - if _trace_atn_sim: - print("mergeArrays a=" + str(a) + ",b=" + str(b) + " -> b") return b combineCommonParents(mergedParents) if mergeCache is not None: mergeCache[(a, b)] = merged - - if _trace_atn_sim: - print("mergeArrays a=" + str(a) + ",b=" + str(b) + " -> " + str(M)) - return merged diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/Recognizer.py b/cf_units/_udunits2_parser/_antlr4_runtime/Recognizer.py index 75886836..f827ec86 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/Recognizer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/Recognizer.py @@ -3,12 +3,9 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # -from cf_units._udunits2_parser._antlr4_runtime.error.ErrorListener import ( - ConsoleErrorListener, - ProxyErrorListener, -) -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .error.ErrorListener import ConsoleErrorListener, ProxyErrorListener +from .RuleContext import RuleContext +from .Token import Token # need forward delcaration RecognitionException = None @@ -38,7 +35,7 @@ def extractVersion(self, version): return major, minor def checkVersion(self, toolVersion): - runtimeVersion = "4.13.2" + runtimeVersion = "4.11.1" rvmajor, rvminor = self.extractVersion(runtimeVersion) tvmajor, tvminor = self.extractVersion(toolVersion) if rvmajor != tvmajor or rvminor != tvminor: @@ -61,9 +58,7 @@ def removeErrorListeners(self): def getTokenTypeMap(self): tokenNames = self.getTokenNames() if tokenNames is None: - from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - UnsupportedOperationException, - ) + from .error.Errors import UnsupportedOperationException raise UnsupportedOperationException( "The current recognizer does not provide a list of token names." @@ -82,9 +77,7 @@ def getTokenTypeMap(self): def getRuleIndexMap(self): ruleNames = self.getRuleNames() if ruleNames is None: - from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - UnsupportedOperationException, - ) + from .error.Errors import UnsupportedOperationException raise UnsupportedOperationException( "The current recognizer does not provide a list of rule names." diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/RuleContext.py b/cf_units/_udunits2_parser/_antlr4_runtime/RuleContext.py index 31d83f49..ea9337c2 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/RuleContext.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/RuleContext.py @@ -26,12 +26,8 @@ # / from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ( - INVALID_INTERVAL, - ParseTreeVisitor, - RuleNode, -) -from cf_units._udunits2_parser._antlr4_runtime.tree.Trees import Trees +from .tree.Tree import INVALID_INTERVAL, ParseTreeVisitor, RuleNode +from .tree.Trees import Trees # need forward declarations RuleContext = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/StdinStream.py b/cf_units/_udunits2_parser/_antlr4_runtime/StdinStream.py index d41ae61e..05d85fc8 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/StdinStream.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/StdinStream.py @@ -1,7 +1,7 @@ import codecs import sys -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream +from .InputStream import InputStream class StdinStream(InputStream): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/TokenStreamRewriter.py b/cf_units/_udunits2_parser/_antlr4_runtime/TokenStreamRewriter.py index cf57cb30..bbca7a27 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/TokenStreamRewriter.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/TokenStreamRewriter.py @@ -6,7 +6,7 @@ from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from .Token import Token class TokenStreamRewriter: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/__init__.py b/cf_units/_udunits2_parser/_antlr4_runtime/__init__.py index e4a633f9..0691a3b1 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/__init__.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/__init__.py @@ -1,48 +1,27 @@ -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNDeserializer import ( - ATNDeserializer, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.LexerATNSimulator import ( - LexerATNSimulator, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ParserATNSimulator import ( - ParserATNSimulator, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.PredictionMode import ( - PredictionMode, -) -from cf_units._udunits2_parser._antlr4_runtime.BufferedTokenStream import ( - TokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.CommonTokenStream import ( - CommonTokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFA import DFA -from cf_units._udunits2_parser._antlr4_runtime.error.DiagnosticErrorListener import ( - DiagnosticErrorListener, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( +from .atn.ATN import ATN +from .atn.ATNDeserializer import ATNDeserializer +from .atn.LexerATNSimulator import LexerATNSimulator +from .atn.ParserATNSimulator import ParserATNSimulator +from .atn.PredictionMode import PredictionMode +from .BufferedTokenStream import TokenStream +from .CommonTokenStream import CommonTokenStream +from .dfa.DFA import DFA +from .error.DiagnosticErrorListener import DiagnosticErrorListener +from .error.Errors import ( IllegalStateException, NoViableAltException, RecognitionException, ) -from cf_units._udunits2_parser._antlr4_runtime.error.ErrorStrategy import ( - BailErrorStrategy, -) -from cf_units._udunits2_parser._antlr4_runtime.FileStream import FileStream -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer -from cf_units._udunits2_parser._antlr4_runtime.Parser import Parser -from cf_units._udunits2_parser._antlr4_runtime.ParserRuleContext import ( - ParserRuleContext, - RuleContext, -) -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( - PredictionContextCache, -) -from cf_units._udunits2_parser._antlr4_runtime.StdinStream import StdinStream -from cf_units._udunits2_parser._antlr4_runtime.Token import Token -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ( +from .error.ErrorStrategy import BailErrorStrategy +from .FileStream import FileStream +from .InputStream import InputStream +from .Lexer import Lexer +from .Parser import Parser +from .ParserRuleContext import ParserRuleContext, RuleContext +from .PredictionContext import PredictionContextCache +from .StdinStream import StdinStream +from .Token import Token +from .tree.Tree import ( ErrorNode, ParseTreeListener, ParseTreeVisitor, @@ -50,4 +29,4 @@ RuleNode, TerminalNode, ) -from cf_units._udunits2_parser._antlr4_runtime.Utils import str_list +from .Utils import str_list diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/_pygrun.py b/cf_units/_udunits2_parser/_antlr4_runtime/_pygrun.py deleted file mode 100644 index 23089137..00000000 --- a/cf_units/_udunits2_parser/_antlr4_runtime/_pygrun.py +++ /dev/null @@ -1,186 +0,0 @@ -#!python -__author__ = "jszheng" -import optparse -import os -import sys - -from cf_units._udunits2_parser._antlr4_runtime import * - - -# this is a python version of TestRig -def beautify_lisp_string(in_string): - indent_size = 3 - add_indent = " " * indent_size - out_string = in_string[0] # no indent for 1st ( - indent = "" - for i in range(1, len(in_string)): - if in_string[i] == "(" and in_string[i + 1] != " ": - indent += add_indent - out_string += "\n" + indent + "(" - elif in_string[i] == ")": - out_string += ")" - if len(indent) > 0: - indent = indent.replace(add_indent, "", 1) - else: - out_string += in_string[i] - return out_string - - -def main(): - ############################################################# - # parse options - # not support -gui -encoding -ps - ############################################################# - usage = "Usage: %prog [options] Grammar_Name Start_Rule" - parser = optparse.OptionParser(usage=usage) - # parser.add_option('-t', '--tree', - # dest="out_file", - # default="default.out", - # help='set output file name', - # ) - parser.add_option( - "-t", - "--tree", - default=False, - action="store_true", - help="Print AST tree", - ) - parser.add_option( - "-k", - "--tokens", - dest="token", - default=False, - action="store_true", - help="Show Tokens", - ) - parser.add_option( - "-s", - "--sll", - dest="sll", - default=False, - action="store_true", - help="Show SLL", - ) - parser.add_option( - "-d", - "--diagnostics", - dest="diagnostics", - default=False, - action="store_true", - help="Enable diagnostics error listener", - ) - parser.add_option( - "-a", - "--trace", - dest="trace", - default=False, - action="store_true", - help="Enable Trace", - ) - - options, remainder = parser.parse_args() - if len(remainder) < 2: - print("ERROR: You have to provide at least 2 arguments!") - parser.print_help() - exit(1) - else: - grammar = remainder.pop(0) - start_rule = remainder.pop(0) - file_list = remainder - - ############################################################# - # check and load antlr generated files - ############################################################# - # dynamic load the module and class - lexerName = grammar + "Lexer" - parserName = grammar + "Parser" - # check if the generate file exist - lexer_file = lexerName + ".py" - parser_file = parserName + ".py" - if not os.path.exists(lexer_file): - print(f"[ERROR] Can't find lexer file {lexer_file}!") - print(os.path.realpath(".")) - exit(1) - if not os.path.exists(parser_file): - print(f"[ERROR] Can't find parser file {lexer_file}!") - print(os.path.realpath(".")) - exit(1) - - # current directory is where the generated file loaded - # the script might be in different place. - sys.path.append(".") - # print(sys.path) - - # add current directory to python global namespace in case of relative imports - globals().update({"__package__": os.path.basename(os.getcwd())}) - - # print("Load Lexer {}".format(lexerName)) - module_lexer = __import__(lexerName, globals(), locals(), lexerName) - class_lexer = getattr(module_lexer, lexerName) - # print(class_lexer) - - # print("Load Parser {}".format(parserName)) - module_parser = __import__(parserName, globals(), locals(), parserName) - class_parser = getattr(module_parser, parserName) - # print(class_parser) - - ############################################################# - # main process steps. - ############################################################# - def process(input_stream, class_lexer, class_parser): - lexer = class_lexer(input_stream) - token_stream = CommonTokenStream(lexer) - token_stream.fill() - if options.token: # need to show token - for tok in token_stream.tokens: - print(tok) - if start_rule == "tokens": - return - - parser = class_parser(token_stream) - - if options.diagnostics: - parser.addErrorListener(DiagnosticErrorListener()) - parser._interp.predictionMode = ( - PredictionMode.LL_EXACT_AMBIG_DETECTION - ) - if options.tree: - parser.buildParseTrees = True - if options.sll: - parser._interp.predictionMode = PredictionMode.SLL - # parser.setTokenStream(token_stream) - parser.setTrace(options.trace) - if hasattr(parser, start_rule): - func_start_rule = getattr(parser, start_rule) - parser_ret = func_start_rule() - if options.tree: - lisp_tree_str = parser_ret.toStringTree(recog=parser) - print(beautify_lisp_string(lisp_tree_str)) - else: - print( - f"[ERROR] Can't find start rule '{start_rule}' in parser '{parserName}'" - ) - - ############################################################# - # use stdin if not provide file as input stream - ############################################################# - if len(file_list) == 0: - input_stream = InputStream(sys.stdin.read()) - process(input_stream, class_lexer, class_parser) - exit(0) - - ############################################################# - # iterate all input file - ############################################################# - for file_name in file_list: - if os.path.exists(file_name) and os.path.isfile(file_name): - input_stream = FileStream(file_name) - process(input_stream, class_lexer, class_parser) - else: - print( - f"[ERROR] file {os.path.normpath(file_name)} not exist" - ) - - -if __name__ == "__main__": - main() diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATN.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATN.py index ba7fb2b2..906adcaa 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATN.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATN.py @@ -2,14 +2,11 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # / -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - ATNState, - DecisionState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNType import ATNType -from cf_units._udunits2_parser._antlr4_runtime.IntervalSet import IntervalSet -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from ..atn.ATNState import ATNState, DecisionState +from ..atn.ATNType import ATNType +from ..IntervalSet import IntervalSet +from ..RuleContext import RuleContext +from ..Token import Token class ATN: @@ -60,9 +57,7 @@ def __init__(self, grammarType: ATNType, maxTokenType: int): # the rule surrounding {@code s}. In other words, the set will be # restricted to tokens reachable staying within {@code s}'s rule. def nextTokensInContext(self, s: ATNState, ctx: RuleContext): - from cf_units._udunits2_parser._antlr4_runtime.LL1Analyzer import ( - LL1Analyzer, - ) + from ..LL1Analyzer import LL1Analyzer anal = LL1Analyzer(self) return anal.LOOK(s, ctx=ctx) diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfig.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfig.py index 6aebaa3e..4ae5d16e 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfig.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfig.py @@ -13,19 +13,10 @@ # / from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - ATNState, - DecisionState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.LexerActionExecutor import ( - LexerActionExecutor, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - SemanticContext, -) -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( - PredictionContext, -) +from ..atn.ATNState import ATNState, DecisionState +from ..atn.LexerActionExecutor import LexerActionExecutor +from ..atn.SemanticContext import SemanticContext +from ..PredictionContext import PredictionContext # need a forward declaration ATNConfig = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfigSet.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfigSet.py index 97a9dd20..a0998a0f 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfigSet.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNConfigSet.py @@ -3,26 +3,20 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. -from functools import reduce - # # Specialized {@link Set}{@code <}{@link ATNConfig}{@code >} that can track # info about the set, with support for combining similar configurations using a # graph-structured stack. # / +from functools import reduce from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfig import ATNConfig -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - SemanticContext, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - IllegalStateException, - UnsupportedOperationException, -) -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import merge -from cf_units._udunits2_parser._antlr4_runtime.Utils import str_list +from ..atn.ATN import ATN +from ..atn.ATNConfig import ATNConfig +from ..atn.SemanticContext import SemanticContext +from ..error.Errors import IllegalStateException, UnsupportedOperationException +from ..PredictionContext import merge +from ..Utils import str_list ATNSimulator = None @@ -222,9 +216,7 @@ def __str__(self): buf.write(str_list(self.configs)) if self.hasSemanticContext: buf.write(",hasSemanticContext=") - buf.write( - str(self.hasSemanticContext).lower() - ) # lower() to conform to java output + buf.write(str(self.hasSemanticContext)) if self.uniqueAlt != ATN.INVALID_ALT_NUMBER: buf.write(",uniqueAlt=") buf.write(str(self.uniqueAlt)) diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNDeserializer.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNDeserializer.py index a8e74536..021549f3 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNDeserializer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNDeserializer.py @@ -2,15 +2,13 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # / -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNDeserializationOptions import ( - ATNDeserializationOptions, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import * -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNType import ATNType -from cf_units._udunits2_parser._antlr4_runtime.atn.LexerAction import * -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import * -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from ..atn.ATN import ATN +from ..atn.ATNDeserializationOptions import ATNDeserializationOptions +from ..atn.ATNState import * +from ..atn.ATNType import ATNType +from ..atn.LexerAction import * +from ..atn.Transition import * +from ..Token import Token SERIALIZED_VERSION = 4 @@ -23,7 +21,7 @@ def __init__(self, options: ATNDeserializationOptions = None): options = ATNDeserializationOptions.defaultOptions self.deserializationOptions = options - def deserialize(self, data: [int]): + def deserialize(self, data: int): self.data = data self.pos = 0 self.checkVersion() @@ -51,7 +49,11 @@ def checkVersion(self): version = self.readInt() if version != SERIALIZED_VERSION: raise Exception( - f"Could not deserialize ATN with version {ord(version)} (expected {SERIALIZED_VERSION})." + "Could not deserialize ATN with version " + + str(version) + + " (expected " + + str(SERIALIZED_VERSION) + + ")." ) def readATN(self): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNSimulator.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNSimulator.py index f9037583..08b68e19 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNSimulator.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNSimulator.py @@ -3,12 +3,10 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # / -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFAState import DFAState -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( +from ..atn.ATN import ATN +from ..atn.ATNConfigSet import ATNConfigSet +from ..dfa.DFAState import DFAState +from ..PredictionContext import ( PredictionContext, PredictionContextCache, getCachedPredictionContext, diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNState.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNState.py index 332b14e9..131ecbfc 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNState.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ATNState.py @@ -64,7 +64,7 @@ # # -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import Transition +from ..atn.Transition import Transition INITIAL_NUM_TRANSITIONS = 4 diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerATNSimulator.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerATNSimulator.py index a3e53f20..915b911f 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerATNSimulator.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerATNSimulator.py @@ -20,37 +20,25 @@ # can simply return the predicted token type. # / -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfig import ( - LexerATNConfig, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, - OrderedATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNSimulator import ( - ATNSimulator, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - ATNState, - RuleStopState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.LexerActionExecutor import ( - LexerActionExecutor, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import Transition -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFAState import DFAState -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( +from ..atn.ATN import ATN +from ..atn.ATNConfig import LexerATNConfig +from ..atn.ATNConfigSet import ATNConfigSet, OrderedATNConfigSet +from ..atn.ATNSimulator import ATNSimulator +from ..atn.ATNState import ATNState, RuleStopState +from ..atn.LexerActionExecutor import LexerActionExecutor +from ..atn.Transition import Transition +from ..dfa.DFAState import DFAState +from ..error.Errors import ( LexerNoViableAltException, UnsupportedOperationException, ) -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( +from ..InputStream import InputStream +from ..PredictionContext import ( PredictionContext, PredictionContextCache, SingletonPredictionContext, ) -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from ..Token import Token class SimState: @@ -111,7 +99,7 @@ def __init__( self.line = 1 # The index of the character relative to the beginning of the line 0..n-1#/ self.column = 0 - from cf_units._udunits2_parser._antlr4_runtime.Lexer import Lexer + from ..Lexer import Lexer self.mode = Lexer.DEFAULT_MODE # Cache Lexer properties to avoid further imports diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerActionExecutor.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerActionExecutor.py index 726d59a9..37945b59 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerActionExecutor.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/LexerActionExecutor.py @@ -12,11 +12,8 @@ # not cause bloating of the {@link DFA} created for the lexer. -from cf_units._udunits2_parser._antlr4_runtime.atn.LexerAction import ( - LexerAction, - LexerIndexedCustomAction, -) -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream +from ..atn.LexerAction import LexerAction, LexerIndexedCustomAction +from ..InputStream import InputStream # need a forward declaration Lexer = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ParserATNSimulator.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ParserATNSimulator.py index dff63378..60425b1d 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/ParserATNSimulator.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/ParserATNSimulator.py @@ -233,29 +233,18 @@ # import sys -from cf_units._udunits2_parser._antlr4_runtime import DFA -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfig import ATNConfig -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNSimulator import ( - ATNSimulator, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( +from ..atn.ATN import ATN +from ..atn.ATNConfig import ATNConfig +from ..atn.ATNConfigSet import ATNConfigSet +from ..atn.ATNSimulator import ATNSimulator +from ..atn.ATNState import ( ATNState, DecisionState, RuleStopState, ) -from cf_units._udunits2_parser._antlr4_runtime.atn.PredictionMode import ( - PredictionMode, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - SemanticContext, - andContext, - orContext, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import ( +from ..atn.PredictionMode import PredictionMode +from ..atn.SemanticContext import SemanticContext, andContext, orContext +from ..atn.Transition import ( ActionTransition, AtomTransition, NotSetTransition, @@ -265,29 +254,21 @@ SetTransition, Transition, ) -from cf_units._udunits2_parser._antlr4_runtime.BufferedTokenStream import ( - TokenStream, -) -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFAState import ( - DFAState, - PredPrediction, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - NoViableAltException, -) -from cf_units._udunits2_parser._antlr4_runtime.Parser import Parser -from cf_units._udunits2_parser._antlr4_runtime.ParserRuleContext import ( - ParserRuleContext, -) -from cf_units._udunits2_parser._antlr4_runtime.PredictionContext import ( +from ..BufferedTokenStream import TokenStream +from ..dfa.DFA import DFA +from ..dfa.DFAState import DFAState, PredPrediction +from ..error.Errors import NoViableAltException +from ..Parser import Parser +from ..ParserRuleContext import ParserRuleContext +from ..PredictionContext import ( PredictionContext, PredictionContextCache, PredictionContextFromRuleContext, SingletonPredictionContext, ) -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext -from cf_units._udunits2_parser._antlr4_runtime.Token import Token -from cf_units._udunits2_parser._antlr4_runtime.Utils import str_list +from ..RuleContext import RuleContext +from ..Token import Token +from ..Utils import str_list class ParserATNSimulator(ATNSimulator): @@ -303,7 +284,7 @@ class ParserATNSimulator(ATNSimulator): ) debug = False - trace_atn_sim = False + debug_list_atn_decisions = False dfa_debug = False retry_debug = False @@ -343,7 +324,10 @@ def adaptivePredict( decision: int, outerContext: ParserRuleContext, ): - if ParserATNSimulator.debug or ParserATNSimulator.trace_atn_sim: + if ( + ParserATNSimulator.debug + or ParserATNSimulator.debug_list_atn_decisions + ): print( "adaptivePredict decision " + str(decision) @@ -377,15 +361,18 @@ def adaptivePredict( if s0 is None: if outerContext is None: outerContext = ParserRuleContext.EMPTY - if ParserATNSimulator.debug: + if ( + ParserATNSimulator.debug + or ParserATNSimulator.debug_list_atn_decisions + ): print( "predictATN decision " + str(dfa.decision) + " exec LA(1)==" + self.getLookaheadName(input) + ", outerContext=" - + str(outerContext) - ) # outerContext.toString(self.parser.literalNames, None)) + + outerContext.toString(self.parser.literalNames, None) + ) fullCtx = False s0_closure = self.computeStartState( @@ -460,13 +447,14 @@ def execATN( startIndex: int, outerContext: ParserRuleContext, ): - if ParserATNSimulator.debug or ParserATNSimulator.trace_atn_sim: + if ( + ParserATNSimulator.debug + or ParserATNSimulator.debug_list_atn_decisions + ): print( "execATN decision " + str(dfa.decision) - + ", DFA state " - + str(s0) - + ", LA(1)==" + + " exec LA(1)==" + self.getLookaheadName(input) + " line " + str(input.LT(1).line) @@ -476,6 +464,9 @@ def execATN( previousD = s0 + if ParserATNSimulator.debug: + print("s0 = " + str(s0)) + t = input.LA(1) while True: # while more work @@ -694,7 +685,10 @@ def execATNWithFullContext( startIndex: int, outerContext: ParserRuleContext, ): - if ParserATNSimulator.debug or ParserATNSimulator.trace_atn_sim: + if ( + ParserATNSimulator.debug + or ParserATNSimulator.debug_list_atn_decisions + ): print("execATNWithFullContext", str(s0)) fullCtx = True foundExactAmbig = False @@ -927,10 +921,6 @@ def computeReachSet(self, closure: ATNConfigSet, t: int, fullCtx: bool): ): for c in skippedStopStates: reach.add(c, self.mergeCache) - - if ParserATNSimulator.trace_atn_sim: - print("computeReachSet", str(closure), "->", reach) - if len(reach) == 0: return None else: @@ -983,14 +973,6 @@ def computeStartState(self, p: ATNState, ctx: RuleContext, fullCtx: bool): initialContext = PredictionContextFromRuleContext(self.atn, ctx) configs = ATNConfigSet(fullCtx) - if ParserATNSimulator.trace_atn_sim: - print( - "computeStartState from ATN state " - + str(p) - + " initialContext=" - + str(initialContext) - ) - for i in range(0, len(p.transitions)): target = p.transitions[i].target c = ATNConfig(target, i + 1, initialContext) @@ -1334,7 +1316,7 @@ def closureCheckingStopState( depth: int, treatEofAsEpsilon: bool, ): - if ParserATNSimulator.trace_atn_sim: + if ParserATNSimulator.debug: print("closure(" + str(config) + ")") if isinstance(config.state, RuleStopState): @@ -1960,12 +1942,6 @@ def getTokenName(self, t: int): and t < len(self.parser.literalNames) ): return self.parser.literalNames[t] + "<" + str(t) + ">" - if ( - self.parser is not None - and self.parser.symbolicNames is not None - and t < len(self.parser.symbolicNames) - ): - return self.parser.symbolicNames[t] + "<" + str(t) + ">" else: return str(t) @@ -2085,19 +2061,15 @@ def addDFAState(self, dfa: DFA, D: DFAState): existing = dfa.states.get(D, None) if existing is not None: - if ParserATNSimulator.trace_atn_sim: - print("addDFAState", str(D), "exists") return existing D.stateNumber = len(dfa.states) if not D.configs.readonly: D.configs.optimizeConfigs(self) D.configs.setReadonly(True) - - if ParserATNSimulator.trace_atn_sim: - print("addDFAState new", str(D)) - dfa.states[D] = D + if ParserATNSimulator.debug: + print("adding new DFA state: " + str(D)) return D def reportAttemptingFullContext( diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/PredictionMode.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/PredictionMode.py index cc5a2d8b..8466e371 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/PredictionMode.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/PredictionMode.py @@ -11,17 +11,11 @@ from enum import Enum -from cf_units._udunits2_parser._antlr4_runtime.atn.ATN import ATN -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfig import ATNConfig -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - RuleStopState, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - SemanticContext, -) +from ..atn.ATN import ATN +from ..atn.ATNConfig import ATNConfig +from ..atn.ATNConfigSet import ATNConfigSet +from ..atn.ATNState import RuleStopState +from ..atn.SemanticContext import SemanticContext PredictionMode = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/SemanticContext.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/SemanticContext.py index 16d1c5cd..af7bac1a 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/SemanticContext.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/SemanticContext.py @@ -13,8 +13,8 @@ # from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.Recognizer import Recognizer -from cf_units._udunits2_parser._antlr4_runtime.RuleContext import RuleContext +from ..Recognizer import Recognizer +from ..RuleContext import RuleContext class SemanticContext: @@ -170,9 +170,6 @@ def __eq__(self, other): else: return self.precedence == other.precedence - def __str__(self): - return "{" + str(self.precedence) + ">=prec}?" - # A semantic context which is true whenever none of the contained contexts # is false. diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/atn/Transition.py b/cf_units/_udunits2_parser/_antlr4_runtime/atn/Transition.py index 271d02cf..ed5195dd 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/atn/Transition.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/atn/Transition.py @@ -17,12 +17,9 @@ # ATN transitions. # # need forward declarations -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - PrecedencePredicate, - Predicate, -) -from cf_units._udunits2_parser._antlr4_runtime.IntervalSet import IntervalSet -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from ..atn.SemanticContext import PrecedencePredicate, Predicate +from ..IntervalSet import IntervalSet +from ..Token import Token ATNState = None RuleStartState = None @@ -307,4 +304,4 @@ def __str__(self): del ATNState del RuleStartState -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import * +from ..atn.ATNState import * diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFA.py b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFA.py index e5c879a6..608814d0 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFA.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFA.py @@ -2,17 +2,10 @@ # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ( - DecisionState, - StarLoopEntryState, -) -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFAState import DFAState -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - IllegalStateException, -) +from ..atn.ATNConfigSet import ATNConfigSet +from ..atn.ATNState import DecisionState, StarLoopEntryState +from ..dfa.DFAState import DFAState +from ..error.Errors import IllegalStateException class DFA: @@ -130,9 +123,7 @@ def __str__(self): def toString(self, literalNames: list = None, symbolicNames: list = None): if self.s0 is None: return "" - from cf_units._udunits2_parser._antlr4_runtime.dfa.DFASerializer import ( - DFASerializer, - ) + from ..dfa.DFASerializer import DFASerializer serializer = DFASerializer(self, literalNames, symbolicNames) return str(serializer) @@ -140,9 +131,7 @@ def toString(self, literalNames: list = None, symbolicNames: list = None): def toLexerString(self): if self.s0 is None: return "" - from cf_units._udunits2_parser._antlr4_runtime.dfa.DFASerializer import ( - LexerDFASerializer, - ) + from ..dfa.DFASerializer import LexerDFASerializer serializer = LexerDFASerializer(self) return str(serializer) diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFASerializer.py b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFASerializer.py index c6dbc447..de4e719d 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFASerializer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFASerializer.py @@ -7,9 +7,9 @@ # A DFA walker that knows how to dump them to serialized strings.#/ from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime import DFA -from cf_units._udunits2_parser._antlr4_runtime.dfa.DFAState import DFAState -from cf_units._udunits2_parser._antlr4_runtime.Utils import str_list +from ..dfa.DFA import DFA +from ..dfa.DFAState import DFAState +from ..Utils import str_list class DFASerializer: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFAState.py b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFAState.py index 83587af9..a3a88db7 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFAState.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/dfa/DFAState.py @@ -7,12 +7,8 @@ # Map a predicate to a predicted alternative.#/ from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.atn.SemanticContext import ( - SemanticContext, -) +from ..atn.ATNConfigSet import ATNConfigSet +from ..atn.SemanticContext import SemanticContext class PredPrediction: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/error/DiagnosticErrorListener.py b/cf_units/_udunits2_parser/_antlr4_runtime/error/DiagnosticErrorListener.py index 79637385..5af9745d 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/error/DiagnosticErrorListener.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/error/DiagnosticErrorListener.py @@ -26,13 +26,10 @@ from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime import DFA, Parser -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNConfigSet import ( - ATNConfigSet, -) -from cf_units._udunits2_parser._antlr4_runtime.error.ErrorListener import ( - ErrorListener, -) +from ..atn.ATNConfigSet import ATNConfigSet +from ..dfa.DFA import DFA +from ..error.ErrorListener import ErrorListener +from ..Parser import Parser class DiagnosticErrorListener(ErrorListener): diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/error/ErrorStrategy.py b/cf_units/_udunits2_parser/_antlr4_runtime/error/ErrorStrategy.py index d9b22735..642239c2 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/error/ErrorStrategy.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/error/ErrorStrategy.py @@ -3,16 +3,16 @@ # Use of this file is governed by the BSD 3-clause license that # can be found in the LICENSE.txt file in the project root. # -from cf_units._udunits2_parser._antlr4_runtime.atn.ATNState import ATNState -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( +from ..atn.ATNState import ATNState +from ..error.Errors import ( FailedPredicateException, InputMismatchException, NoViableAltException, ParseCancellationException, RecognitionException, ) -from cf_units._udunits2_parser._antlr4_runtime.IntervalSet import IntervalSet -from cf_units._udunits2_parser._antlr4_runtime.Token import Token +from ..IntervalSet import IntervalSet +from ..Token import Token # need forward declaration Parser = None diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/error/Errors.py b/cf_units/_udunits2_parser/_antlr4_runtime/error/Errors.py index ee571b52..7a1dd586 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/error/Errors.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/error/Errors.py @@ -35,11 +35,9 @@ def __init__(self, msg: str): # in the input, where it is in the ATN, the rule invocation stack, # and what kind of problem occurred. -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.ParserRuleContext import ( - ParserRuleContext, -) -from cf_units._udunits2_parser._antlr4_runtime.Recognizer import Recognizer +from ..InputStream import InputStream +from ..ParserRuleContext import ParserRuleContext +from ..Recognizer import Recognizer class RecognitionException(Exception): @@ -100,7 +98,6 @@ def __init__( super().__init__(message=None, recognizer=lexer, input=input, ctx=None) self.startIndex = startIndex self.deadEndConfigs = deadEndConfigs - self.message = "" def __str__(self): symbol = "" @@ -175,9 +172,7 @@ def __init__( ) s = recognizer._interp.atn.states[recognizer.state] trans = s.transitions[0] - from cf_units._udunits2_parser._antlr4_runtime.atn.Transition import ( - PredicateTransition, - ) + from ..atn.Transition import PredicateTransition if isinstance(trans, PredicateTransition): self.ruleIndex = trans.ruleIndex diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreeMatch.py b/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreeMatch.py index 92d9a80d..1d029064 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreeMatch.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreeMatch.py @@ -10,10 +10,8 @@ # from io import StringIO -from cf_units._udunits2_parser._antlr4_runtime.tree.ParseTreePattern import ( - ParseTreePattern, -) -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ParseTree +from ..tree.ParseTreePattern import ParseTreePattern +from ..tree.Tree import ParseTree class ParseTreeMatch: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreePattern.py b/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreePattern.py index 00770c94..58cdeafe 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreePattern.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/tree/ParseTreePattern.py @@ -8,10 +8,8 @@ # A pattern like {@code# Whitespace is not allowed.
# -from cf_units._udunits2_parser._antlr4_runtime import ( - CommonTokenStream, - ParserRuleContext, - TerminalNode, -) -from cf_units._udunits2_parser._antlr4_runtime.error.ErrorListener import ( - ErrorListener, -) -from cf_units._udunits2_parser._antlr4_runtime.error.Errors import ( - LexerNoViableAltException, -) -from cf_units._udunits2_parser._antlr4_runtime.InputStream import InputStream -from cf_units._udunits2_parser._antlr4_runtime.Parser import Parser -from cf_units._udunits2_parser._antlr4_runtime.Token import Token -from cf_units._udunits2_parser._antlr4_runtime.tree.Tree import ParseTree -from cf_units._udunits2_parser._antlr4_runtime.tree.Trees import Trees -from cf_units._udunits2_parser._antlr4_runtime.xpath.XPathLexer import ( - XPathLexer, -) +from ..CommonTokenStream import CommonTokenStream +from ..error.ErrorListener import ErrorListener +from ..error.Errors import LexerNoViableAltException +from ..InputStream import InputStream +from ..Parser import Parser +from ..ParserRuleContext import ParserRuleContext +from ..Token import Token +from ..tree.Tree import ParseTree, TerminalNode +from ..tree.Trees import Trees +from ..xpath.XPathLexer import XPathLexer class XPath: diff --git a/cf_units/_udunits2_parser/_antlr4_runtime/xpath/XPathLexer.py b/cf_units/_udunits2_parser/_antlr4_runtime/xpath/XPathLexer.py index ca5ae82e..8a972ec7 100644 --- a/cf_units/_udunits2_parser/_antlr4_runtime/xpath/XPathLexer.py +++ b/cf_units/_udunits2_parser/_antlr4_runtime/xpath/XPathLexer.py @@ -1,7 +1,12 @@ -# Generated from XPathLexer.g4 by ANTLR 4.13.1 +# Generated from XPathLexer.g4 by ANTLR 4.9.3 import sys -from cf_units._udunits2_parser._antlr4_runtime import * +from ..atn.ATNDeserializer import ATNDeserializer +from ..atn.LexerATNSimulator import LexerATNSimulator +from ..dfa.DFA import DFA +from ..Lexer import Lexer +from ..PredictionContext import PredictionContextCache +from ..RuleContext import RuleContext if sys.version_info[1] > 5: from typing import TextIO @@ -543,7 +548,7 @@ class XPathLexer(Lexer): def __init__(self, input=None, output: TextIO = sys.stdout): super().__init__(input, output) - self.checkVersion("4.13.1") + self.checkVersion("4.9.3") self._interp = LexerATNSimulator( self, self.atn, self.decisionsToDFA, PredictionContextCache() ) diff --git a/cf_units/_udunits2_parser/compile.py b/cf_units/_udunits2_parser/compile.py index be264ac5..304fb033 100644 --- a/cf_units/_udunits2_parser/compile.py +++ b/cf_units/_udunits2_parser/compile.py @@ -14,6 +14,7 @@ You're welcome ;). """ +# ruff: noqa: E501 import collections import re @@ -68,6 +69,55 @@ def expand_lexer(source, target): fh.write(new_content) +def fixup_antlr_imports(antlr_file_path: Path, contents: str) -> str: + depth = len(antlr_file_path.parents) - 1 + + # Straighten out some wonky imports. + if antlr_file_path.name == "XPathLexer.py": + contents = contents.replace( + "from antlr4 import *", + "\n".join( + [ + "from antlr4.Lexer import Lexer", + "from antlr4.atn.ATNDeserializer import ATNDeserializer", + "from antlr4.dfa.DFA import DFA", + "from antlr4.RuleContext import RuleContext", + "from antlr4.CommonTokenStream import CommonTokenStream", + "from antlr4.ParserRuleContext import ParserRuleContext", + "from antlr4.tree.Tree import TerminalNode", + "from antlr4.atn.LexerATNSimulator import LexerATNSimulator", + "from antlr4.PredictionContext import PredictionContextCache", + ] + ), + ) + if antlr_file_path.name == "XPath.py": + contents = contents.replace( + "from antlr4 import CommonTokenStream, DFA, " + "PredictionContextCache, " + "Lexer, LexerATNSimulator, ParserRuleContext, TerminalNode", + "\n".join( + [ + "from antlr4.Lexer import Lexer", + "from antlr4.CommonTokenStream import CommonTokenStream", + "from antlr4.ParserRuleContext import ParserRuleContext", + "from antlr4.tree.Tree import TerminalNode", + "from antlr4.atn.LexerATNSimulator import LexerATNSimulator", + "from antlr4.PredictionContext import PredictionContextCache", + "from antlr4.dfa.DFA import DFA", + ] + ), + ) + contents = contents.replace( + "from antlr4 import DFA", "from antlr4.dfa.DFA import DFA" + ) + contents = contents.replace( + "from antlr4 import Parser, DFA", + "from antlr4.dfa.DFA import DFA\nfrom antlr4.Parser import Parser", + ) + contents = contents.replace("from antlr4", "from " + "." * depth) + return contents + + def vendor_antlr4_runtime(udunits2_parser_dir: Path): antlr_dest = udunits2_parser_dir / "_antlr4_runtime" version_file = antlr_dest / "_antlr4_version.txt" @@ -90,15 +140,20 @@ def vendor_antlr4_runtime(udunits2_parser_dir: Path): "install", "--quiet", f"--prefix={tmp_dest}", - "antlr4-python3-runtime", + f"antlr4-python3-runtime=={ANTLR_VERSION}", ], check=True, ) [antlr_code_dir] = tmp_dest.glob("lib/python3.*/site-packages/antlr4") for py_file in antlr_code_dir.glob("**/*.py"): - py_file_dest = antlr_dest / py_file.relative_to(antlr_code_dir) + if py_file.name == "_pygrun.py": + continue + rel_to_antrl_root = py_file.relative_to(antlr_code_dir) + contents = py_file.read_text() + contents = fixup_antlr_imports(rel_to_antrl_root, contents) + py_file_dest = antlr_dest / rel_to_antrl_root py_file_dest.parent.mkdir(exist_ok=True) - py_file_dest.write_text(py_file.read_text()) + py_file_dest.write_text(contents) shutil.rmtree(tmp_dest) version_file.write_text(ANTLR_VERSION) else: @@ -106,7 +161,7 @@ def vendor_antlr4_runtime(udunits2_parser_dir: Path): # Re-write all imports relating to the antlr4 runtime to be the # vendored location. - for py_file in Path(".").glob("**/*.py"): + for py_file in Path("parser").glob("**/*.py"): if py_file.absolute() == Path(__file__).absolute(): # Don't adapt for vendoring of this file. continue diff --git a/cf_units/tests/test_coding_standards.py b/cf_units/tests/test_coding_standards.py index e0caa0fb..f3bbe519 100644 --- a/cf_units/tests/test_coding_standards.py +++ b/cf_units/tests/test_coding_standards.py @@ -90,6 +90,7 @@ def test_license_headers(self): "dist/*", "cf_units/_version.py", "cf_units/_udunits2_parser/parser/*", + "cf_units/_udunits2_parser/_antlr4_runtime/*", ) last_change_by_fname = self.last_change_by_fname() diff --git a/cf_units/tests/test_tex.py b/cf_units/tests/test_tex.py index ffb91b6e..ce3977ad 100644 --- a/cf_units/tests/test_tex.py +++ b/cf_units/tests/test_tex.py @@ -2,10 +2,6 @@ # # This file is part of cf-units and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. -# ruff: noqa: E402 -import pytest - -antlr4 = pytest.importorskip("antlr4") from cf_units.tex import tex diff --git a/cf_units/tex.py b/cf_units/tex.py index d0898664..4d716d2e 100644 --- a/cf_units/tex.py +++ b/cf_units/tex.py @@ -3,8 +3,8 @@ # This file is part of cf-units and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. -import cf_units._udunits2_parser.graph as graph # noqa: E402 -from cf_units._udunits2_parser import parse as _parse # noqa: E402 +from ._udunits2_parser import graph +from ._udunits2_parser import parse as _parse class TeXVisitor(graph.Visitor):