From 9eaa38ffaa2647b9c1144f3c2557d4b131df4d04 Mon Sep 17 00:00:00 2001 From: Ken Domino Date: Wed, 21 Jun 2023 11:37:56 -0400 Subject: [PATCH 01/10] Fix for @4325--python2 testing not available on Github Actions. --- .github/workflows/hosted.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml index 01deeaea07..1511fbf80c 100644 --- a/.github/workflows/hosted.yml +++ b/.github/workflows/hosted.yml @@ -174,7 +174,6 @@ jobs: javascript, typescript, php, - python2, python3, # swift, ] @@ -233,13 +232,6 @@ jobs: if: startswith(matrix.os, 'windows') && (matrix.target == 'cpp') uses: microsoft/setup-msbuild@v1.1 - - name: Set up Python 2 - if: matrix.target == 'python2' - uses: actions/setup-python@v4 - with: - python-version: '2.x' - architecture: 'x64' - - name: Set up Python 3 if: matrix.target == 'python3' uses: actions/setup-python@v4 @@ -316,7 +308,6 @@ jobs: cd runtime-testsuite switch ("${{ matrix.target }}") { - python2 { mvn -X '-Dantlr-python2-exec="${{ env.pythonLocation }}\python.exe"' '-Dtest=python2.**' test } python3 { mvn -X '-Dantlr-python3-exec="${{ env.pythonLocation }}\python.exe"' '-Dtest=python3.**' test } default { mvn -X '-Dtest=${{ matrix.target }}.**' test } } @@ -331,7 +322,6 @@ jobs: cd runtime-testsuite case ${{ matrix.target }} in - python2) mvn -X '-Dantlr-python2-exec=${{ env.pythonLocation }}/bin/python' '-Dtest=python2.**' test ;; python3) mvn -X '-Dantlr-python3-exec=${{ env.pythonLocation }}/bin/python' '-Dtest=python3.**' test ;; *) mvn -X '-Dtest=${{ matrix.target }}.**' test ;; esac From 004792243472c2e0965ede320a67cea7eda882d6 Mon Sep 17 00:00:00 2001 From: Ken Domino Date: Wed, 21 Jun 2023 13:21:29 -0400 Subject: [PATCH 02/10] Removing Python2 from additional places. --- README.md | 2 +- doc/IDEs.md | 2 +- doc/antlr-project-testing.md | 1 - doc/python-target.md | 11 +- doc/releasing-antlr.md | 15 +- doc/targets.md | 8 +- pom.xml | 2 +- .../ParserErrors/ExtraneousInput.txt | 1 - .../DropLoopEntryBranchInLRRule_4.txt | 1 - .../PredFromAltTestedInLoopBack_1.txt | 1 - .../test/runtime/templates/Python2.test.stg | 286 --- .../v4/test/runtime/CustomDescriptors.java | 2 +- .../test/runtime/python2/Python2Runner.java | 33 - .../runtime/python2/Python2RuntimeTests.java | 17 - runtime/Python2/MANIFEST.in | 1 - runtime/Python2/README.txt | 4 - runtime/Python2/RELEASE-4.5.txt | 13 - runtime/Python2/setup.py | 14 - .../Python2/src/antlr4/BufferedTokenStream.py | 306 --- runtime/Python2/src/antlr4/CodePoints.py | 73 - .../Python2/src/antlr4/CommonTokenFactory.py | 59 - .../Python2/src/antlr4/CommonTokenStream.py | 85 - runtime/Python2/src/antlr4/FileStream.py | 32 - runtime/Python2/src/antlr4/InputStream.py | 108 -- runtime/Python2/src/antlr4/IntervalSet.py | 296 --- runtime/Python2/src/antlr4/LL1Analyzer.py | 170 -- runtime/Python2/src/antlr4/Lexer.py | 319 ---- runtime/Python2/src/antlr4/ListTokenSource.py | 143 -- runtime/Python2/src/antlr4/Parser.py | 563 ------ .../Python2/src/antlr4/ParserInterpreter.py | 163 -- .../Python2/src/antlr4/ParserRuleContext.py | 181 -- .../Python2/src/antlr4/PredictionContext.py | 632 ------- runtime/Python2/src/antlr4/Recognizer.py | 141 -- runtime/Python2/src/antlr4/RuleContext.py | 225 --- runtime/Python2/src/antlr4/StdinStream.py | 21 - runtime/Python2/src/antlr4/Token.py | 159 -- .../Python2/src/antlr4/TokenStreamRewriter.py | 252 --- runtime/Python2/src/antlr4/Utils.py | 39 - runtime/Python2/src/antlr4/__init__.py | 21 - runtime/Python2/src/antlr4/atn/ATN.py | 122 -- runtime/Python2/src/antlr4/atn/ATNConfig.py | 149 -- .../Python2/src/antlr4/atn/ATNConfigSet.py | 210 --- .../antlr4/atn/ATNDeserializationOptions.py | 21 - .../Python2/src/antlr4/atn/ATNDeserializer.py | 446 ----- .../Python2/src/antlr4/atn/ATNSimulator.py | 45 - runtime/Python2/src/antlr4/atn/ATNState.py | 255 --- runtime/Python2/src/antlr4/atn/ATNType.py | 12 - .../src/antlr4/atn/LexerATNSimulator.py | 554 ------ runtime/Python2/src/antlr4/atn/LexerAction.py | 291 --- .../src/antlr4/atn/LexerActionExecutor.py | 135 -- .../src/antlr4/atn/ParserATNSimulator.py | 1659 ----------------- .../Python2/src/antlr4/atn/PredictionMode.py | 495 ----- .../Python2/src/antlr4/atn/SemanticContext.py | 328 ---- runtime/Python2/src/antlr4/atn/Transition.py | 252 --- runtime/Python2/src/antlr4/atn/__init__.py | 1 - runtime/Python2/src/antlr4/dfa/DFA.py | 135 -- .../Python2/src/antlr4/dfa/DFASerializer.py | 74 - runtime/Python2/src/antlr4/dfa/DFAState.py | 124 -- runtime/Python2/src/antlr4/dfa/__init__.py | 1 - .../antlr4/error/DiagnosticErrorListener.py | 106 -- .../Python2/src/antlr4/error/ErrorListener.py | 72 - .../Python2/src/antlr4/error/ErrorStrategy.py | 702 ------- runtime/Python2/src/antlr4/error/Errors.py | 157 -- runtime/Python2/src/antlr4/error/__init__.py | 1 - runtime/Python2/src/antlr4/tree/Chunk.py | 32 - .../Python2/src/antlr4/tree/ParseTreeMatch.py | 120 -- .../src/antlr4/tree/ParseTreePattern.py | 69 - .../antlr4/tree/ParseTreePatternMatcher.py | 367 ---- .../Python2/src/antlr4/tree/RuleTagToken.py | 48 - .../Python2/src/antlr4/tree/TokenTagToken.py | 47 - runtime/Python2/src/antlr4/tree/Tree.py | 186 -- runtime/Python2/src/antlr4/tree/Trees.py | 110 -- runtime/Python2/src/antlr4/tree/__init__.py | 0 runtime/Python2/src/antlr4/xpath/XPath.py | 269 --- .../Python2/src/antlr4/xpath/XPathLexer.g4 | 45 - .../Python2/src/antlr4/xpath/XPathLexer.py | 93 - runtime/Python2/src/antlr4/xpath/__init__.py | 1 - .../Python2/tests/TestTokenStreamRewriter.py | 524 ------ runtime/Python2/tests/__init__.py | 0 runtime/Python2/tests/mocks/TestLexer.py | 101 - runtime/Python2/tests/mocks/__init__.py | 0 runtime/Python2/tests/run.py | 7 - scripts/files-to-update.txt | 3 - scripts/github_release_notes.py | 2 +- .../v4/test/tool/TestUnicodeEscapes.java | 3 - .../templates/codegen/Python2/Python2.stg | 829 -------- .../org/antlr/v4/codegen/UnicodeEscapes.java | 1 - .../v4/codegen/target/Python2Target.java | 92 - 88 files changed, 12 insertions(+), 13686 deletions(-) delete mode 100644 runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg delete mode 100644 runtime-testsuite/test/org/antlr/v4/test/runtime/python2/Python2Runner.java delete mode 100644 runtime-testsuite/test/org/antlr/v4/test/runtime/python2/Python2RuntimeTests.java delete mode 100644 runtime/Python2/MANIFEST.in delete mode 100644 runtime/Python2/README.txt delete mode 100644 runtime/Python2/RELEASE-4.5.txt delete mode 100644 runtime/Python2/setup.py delete mode 100644 runtime/Python2/src/antlr4/BufferedTokenStream.py delete mode 100644 runtime/Python2/src/antlr4/CodePoints.py delete mode 100644 runtime/Python2/src/antlr4/CommonTokenFactory.py delete mode 100644 runtime/Python2/src/antlr4/CommonTokenStream.py delete mode 100644 runtime/Python2/src/antlr4/FileStream.py delete mode 100644 runtime/Python2/src/antlr4/InputStream.py delete mode 100644 runtime/Python2/src/antlr4/IntervalSet.py delete mode 100644 runtime/Python2/src/antlr4/LL1Analyzer.py delete mode 100644 runtime/Python2/src/antlr4/Lexer.py delete mode 100644 runtime/Python2/src/antlr4/ListTokenSource.py delete mode 100644 runtime/Python2/src/antlr4/Parser.py delete mode 100644 runtime/Python2/src/antlr4/ParserInterpreter.py delete mode 100644 runtime/Python2/src/antlr4/ParserRuleContext.py delete mode 100644 runtime/Python2/src/antlr4/PredictionContext.py delete mode 100644 runtime/Python2/src/antlr4/Recognizer.py delete mode 100644 runtime/Python2/src/antlr4/RuleContext.py delete mode 100644 runtime/Python2/src/antlr4/StdinStream.py delete mode 100644 runtime/Python2/src/antlr4/Token.py delete mode 100644 runtime/Python2/src/antlr4/TokenStreamRewriter.py delete mode 100644 runtime/Python2/src/antlr4/Utils.py delete mode 100644 runtime/Python2/src/antlr4/__init__.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATN.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNConfig.py delete mode 100755 runtime/Python2/src/antlr4/atn/ATNConfigSet.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNDeserializationOptions.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNDeserializer.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNSimulator.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNState.py delete mode 100644 runtime/Python2/src/antlr4/atn/ATNType.py delete mode 100644 runtime/Python2/src/antlr4/atn/LexerATNSimulator.py delete mode 100644 runtime/Python2/src/antlr4/atn/LexerAction.py delete mode 100644 runtime/Python2/src/antlr4/atn/LexerActionExecutor.py delete mode 100755 runtime/Python2/src/antlr4/atn/ParserATNSimulator.py delete mode 100644 runtime/Python2/src/antlr4/atn/PredictionMode.py delete mode 100644 runtime/Python2/src/antlr4/atn/SemanticContext.py delete mode 100644 runtime/Python2/src/antlr4/atn/Transition.py delete mode 100644 runtime/Python2/src/antlr4/atn/__init__.py delete mode 100644 runtime/Python2/src/antlr4/dfa/DFA.py delete mode 100644 runtime/Python2/src/antlr4/dfa/DFASerializer.py delete mode 100644 runtime/Python2/src/antlr4/dfa/DFAState.py delete mode 100644 runtime/Python2/src/antlr4/dfa/__init__.py delete mode 100644 runtime/Python2/src/antlr4/error/DiagnosticErrorListener.py delete mode 100644 runtime/Python2/src/antlr4/error/ErrorListener.py delete mode 100644 runtime/Python2/src/antlr4/error/ErrorStrategy.py delete mode 100644 runtime/Python2/src/antlr4/error/Errors.py delete mode 100644 runtime/Python2/src/antlr4/error/__init__.py delete mode 100644 runtime/Python2/src/antlr4/tree/Chunk.py delete mode 100644 runtime/Python2/src/antlr4/tree/ParseTreeMatch.py delete mode 100644 runtime/Python2/src/antlr4/tree/ParseTreePattern.py delete mode 100644 runtime/Python2/src/antlr4/tree/ParseTreePatternMatcher.py delete mode 100644 runtime/Python2/src/antlr4/tree/RuleTagToken.py delete mode 100644 runtime/Python2/src/antlr4/tree/TokenTagToken.py delete mode 100644 runtime/Python2/src/antlr4/tree/Tree.py delete mode 100644 runtime/Python2/src/antlr4/tree/Trees.py delete mode 100644 runtime/Python2/src/antlr4/tree/__init__.py delete mode 100644 runtime/Python2/src/antlr4/xpath/XPath.py delete mode 100644 runtime/Python2/src/antlr4/xpath/XPathLexer.g4 delete mode 100644 runtime/Python2/src/antlr4/xpath/XPathLexer.py delete mode 100644 runtime/Python2/src/antlr4/xpath/__init__.py delete mode 100644 runtime/Python2/tests/TestTokenStreamRewriter.py delete mode 100644 runtime/Python2/tests/__init__.py delete mode 100644 runtime/Python2/tests/mocks/TestLexer.py delete mode 100644 runtime/Python2/tests/mocks/__init__.py delete mode 100644 runtime/Python2/tests/run.py delete mode 100644 tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg delete mode 100644 tool/src/org/antlr/v4/codegen/target/Python2Target.java diff --git a/README.md b/README.md index c05b3f8c0b..c6675582ed 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ ANTLR project lead and supreme dictator for life * [Official site](http://www.antlr.org/) * [Documentation](https://github.com/antlr/antlr4/blob/master/doc/index.md) * [FAQ](https://github.com/antlr/antlr4/blob/master/doc/faq/index.md) -* [ANTLR code generation targets](https://github.com/antlr/antlr4/blob/master/doc/targets.md)
(Currently: Java, C#, Python2|3, JavaScript, Go, C++, Swift, Dart, PHP) +* [ANTLR code generation targets](https://github.com/antlr/antlr4/blob/master/doc/targets.md)
(Currently: Java, C#, Python3, JavaScript, Go, C++, Swift, Dart, PHP) * [Java API](http://www.antlr.org/api/Java/index.html) * [ANTLR v3](http://www.antlr3.org/) * [v3 to v4 Migration, differences](https://github.com/antlr/antlr4/blob/master/doc/faq/general.md) diff --git a/doc/IDEs.md b/doc/IDEs.md index 7c21e8af01..9e98503d3c 100644 --- a/doc/IDEs.md +++ b/doc/IDEs.md @@ -1,5 +1,5 @@ # Integrating ANTLR into Development Systems -The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of December 2016, we have Java, C#, Python 2, Python 3, JavaScript, Go, C++, and Swift targets. +The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of December 2016, we have Java, C#, Python 3, JavaScript, Go, C++, and Swift targets. The easiest thing is probably just to use an [ANTLR plug-in](http://www.antlr.org/tools.html) for your favorite development environment. diff --git a/doc/antlr-project-testing.md b/doc/antlr-project-testing.md index fc93c7c9a4..8968a4bdfb 100644 --- a/doc/antlr-project-testing.md +++ b/doc/antlr-project-testing.md @@ -56,7 +56,6 @@ In order to perform the tests on all target languages, the following tools shoul * dotnet * Node.js -* Python 2 * Python 3 * Go * Swift diff --git a/doc/python-target.md b/doc/python-target.md index 6f7f6a84a9..b4f5c2bca4 100644 --- a/doc/python-target.md +++ b/doc/python-target.md @@ -2,17 +2,11 @@ The examples from the ANTLR 4 book converted to Python are [here](https://github.com/jszheng/py3antlr4book). -There are 2 Python targets: `Python2` and `Python3`. This is because there is only limited compatibility between those 2 versions of the language. Please refer to the [Python documentation](https://wiki.python.org/moin/Python2orPython3) for full details. +There is ONE Python target: `Python3`. This is because there is only limited compatibility between those 2 versions of the language. Please refer to the [Python documentation](https://wiki.python.org/moin/Python3) for full details. How to create a Python lexer or parser? This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example: -``` -$ antlr4 -Dlanguage=Python2 MyGrammar.g4 -``` - -or - ``` $ antlr4 -Dlanguage=Python3 MyGrammar.g4 ``` @@ -21,9 +15,8 @@ For a full list of antlr4 tool options, please visit the tool documentation page ## Where can I get the runtime? -Once you've generated the lexer and/or parser code, you need to download the runtime. The Python runtimes are available from PyPI: +Once you've generated the lexer and/or parser code, you need to download the runtime. The Python runtime are available from PyPI: -* https://pypi.python.org/pypi/antlr4-python2-runtime/ * https://pypi.python.org/pypi/antlr4-python3-runtime/ The runtimes are provided in the form of source code, so no additional installation is required. diff --git a/doc/releasing-antlr.md b/doc/releasing-antlr.md index fde3cbe5f9..80fc4e36cd 100644 --- a/doc/releasing-antlr.md +++ b/doc/releasing-antlr.md @@ -103,9 +103,6 @@ java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.13.0-SNAPSHOT/antlr4-4 cd ~/antlr/code/antlr4/runtime/CSharp/src/Tree/Xpath java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.13-0-SNAPSHOT/antlr4-4.13-0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=CSharp XPathLexer.g4 -cd ~/antlr/code/antlr4/runtime/Python2/src/antlr4/xpath -java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.13-0-SNAPSHOT/antlr4-4.13-0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python2 XPathLexer.g4 - cd ~/antlr/code/antlr4/runtime/Python3/tests/expr java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.13-0-SNAPSHOT/antlr4-4.13-0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python3 Expr.g4 cd ~/antlr/code/antlr4/runtime/Python3/src/antlr4/xpath @@ -317,7 +314,7 @@ nuget push Antlr4.Runtime.Standard..nupkg -Source https://ww ### Python -The Python targets get deployed with `twine` for Python 2 and 3. +The Python target gets deployed with `twine` for Python 3. First, set up `~/.pypirc` with tight privileges: @@ -343,16 +340,6 @@ password: xxx Then run the python build and upload: -```bash -cd ~/antlr/code/antlr4/runtime/Python2 -# assume you have ~/.pypirc set up -pip install build twine -python -m build -twine upload dist/antlr4-python2-runtime-4.13.0.tar.gz -``` - -For Python 3 target, do - ```bash cd ~/antlr/code/antlr4/runtime/Python3 python -m build diff --git a/doc/targets.md b/doc/targets.md index 74dae819c0..296caf6f74 100644 --- a/doc/targets.md +++ b/doc/targets.md @@ -4,7 +4,7 @@ This page lists the available and upcoming ANTLR runtimes. Please note that you * [Java](java-target.md). The [ANTLR v4 book](http://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference) has a decent summary of the runtime library. We have added a useful XPath feature since the book was printed that lets you select bits of parse trees. See [Runtime API](http://www.antlr.org/api/Java/index.html) and [Getting Started with ANTLR v4](getting-started.md) * [C#](csharp-target.md) -* [Python](python-target.md) (2 and 3) +* [Python](python-target.md) (3) * [JavaScript](javascript-target.md) * [TypeScript](typescript-target.md) * [Go](go-target.md) @@ -17,7 +17,7 @@ This page lists the available and upcoming ANTLR runtimes. Please note that you New features generally appear in the Java target and then migrate to the other targets, but these other targets don't always get updated in the same overall tool release. This section tries to identify features added to Java that have not been added to the other targets. -|Feature|Java|C♯|Python2|Python3|JavaScript|Go|C++|Swift|PHP|Dart -|---|---|---|---|---|---|---|---|---|---|---| -|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|-|-|-| +|Feature|Java|C♯|Python3|JavaScript|Go|C++|Swift|PHP|Dart +|---|---|---|---|---|---|---|---|---|---| +|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|-|-| diff --git a/pom.xml b/pom.xml index d19006770f..3e0feb1abe 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ Eric Vergnaud - Developer - JavaScript, C#, Python 2, Python 3 + Developer - JavaScript, C#, Python 3 diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ExtraneousInput.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ExtraneousInput.txt index 4b0f7232a9..3d76cf6d5e 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ExtraneousInput.txt +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ExtraneousInput.txt @@ -28,5 +28,4 @@ Go JavaScript TypeScript PHP -Python2 Python3 diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/Performance/DropLoopEntryBranchInLRRule_4.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/Performance/DropLoopEntryBranchInLRRule_4.txt index 8bf8b21bc0..a6f4b3d966 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/Performance/DropLoopEntryBranchInLRRule_4.txt +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/Performance/DropLoopEntryBranchInLRRule_4.txt @@ -51,7 +51,6 @@ between X1 and X2 or between X3 and X4 ; [skip] -Python2 Python3 JavaScript TypeScript diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/SemPredEvalParser/PredFromAltTestedInLoopBack_1.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/SemPredEvalParser/PredFromAltTestedInLoopBack_1.txt index 740ed05198..ca2fa6b9a1 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/SemPredEvalParser/PredFromAltTestedInLoopBack_1.txt +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/SemPredEvalParser/PredFromAltTestedInLoopBack_1.txt @@ -41,5 +41,4 @@ Go JavaScript TypeScript PHP -Python2 Python3 diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg deleted file mode 100644 index d13e88507e..0000000000 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg +++ /dev/null @@ -1,286 +0,0 @@ -writeln(s) ::= <, file=self._output)>> -write(s) ::= <,end='', file=self._output)>> -writeList(s) ::= <)}; separator="+">, file=self._output)>> - -False() ::= "False" - -True() ::= "True" - -Not(v) ::= "not " - -Assert(s) ::= "" - -Cast(t,v) ::= "" - -Append(a,b) ::= " + str()" - -AppendStr(a,b) ::= " + " - -Concat(a,b) ::= "" - -AssertIsList(v) ::= "assert isinstance(, (list, tuple))" - -AssignLocal(s,v) ::= " = " - -InitIntMember(n,v) ::= <% = %> - -InitBooleanMember(n,v) ::= <% = %> - -InitIntVar(n,v) ::= <%%> - -IntArg(n) ::= "" - -VarRef(n) ::= "" - -GetMember(n) ::= <%self.%> - -SetMember(n,v) ::= <%self. = %> - -AddMember(n,v) ::= <%self. += %> - -MemberEquals(n,v) ::= <%self. == %> - -ModMemberEquals(n,m,v) ::= <%self. % == %> - -ModMemberNotEquals(n,m,v) ::= <%self. % != %> - -DumpDFA() ::= "self.dumpDFA()" - -Pass() ::= "pass" - -StringList() ::= "" - -BuildParseTrees() ::= "self._buildParseTrees = True" - -BailErrorStrategy() ::= <%self._errHandler = BailErrorStrategy()%> - -ToStringTree(s) ::= <%.toStringTree(recog=self)%> - -Column() ::= "self.column" - -Text() ::= "self.text" - -ValEquals(a,b) ::= <%==%> - -TextEquals(a) ::= <%self.text==""%> - -PlusText(a) ::= <%"" + self.text%> - -InputText() ::= "self._input.getText()" - -LTEquals(i, v) ::= <%self._input.LT().text==%> - -LANotEquals(i, v) ::= <%self._input.LA()!=%> - -TokenStartColumnEquals(i) ::= <%self._tokenStartColumn==%> - -ImportListener(X) ::= "" - -GetExpectedTokenNames() ::= "self.getExpectedTokens().toString(self.literalNames, self.symbolicNames)" - -ImportRuleInvocationStack() ::= "" - -RuleInvocationStack() ::= "str_list(self.getRuleInvocationStack())" - -LL_EXACT_AMBIG_DETECTION() ::= <> - -ParserToken(parser, token) ::= <%.%> - -Production(p) ::= <%

%> - -Result(r) ::= <%%> - -ParserPropertyMember() ::= << -@members { -def Property(self): - return True - -} ->> - -ParserPropertyCall(p, call) ::= "

." - -PositionAdjustingLexerDef() ::= "" - -PositionAdjustingLexer() ::= << - -def resetAcceptPosition(self, index, line, column): - self._input.seek(index) - self.line = line - self.column = column - self._interp.consume(self._input) - -def nextToken(self): - if self._interp.__dict__.get("resetAcceptPosition", None) is None: - self._interp.__dict__["resetAcceptPosition"] = self.resetAcceptPosition - return super(type(self),self).nextToken() - -def emit(self): - if self._type==PositionAdjustingLexer.TOKENS: - self.handleAcceptPositionForKeyword("tokens") - elif self._type==PositionAdjustingLexer.LABEL: - self.handleAcceptPositionForIdentifier() - return super(type(self),self).emit() - -def handleAcceptPositionForIdentifier(self): - tokenText = self.text - identifierLength = 0 - while identifierLength \< len(tokenText) and self.isIdentifierChar(tokenText[identifierLength]): - identifierLength += 1 - - if self._input.index > self._tokenStartCharIndex + identifierLength: - offset = identifierLength - 1 - self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset, - self._tokenStartLine, self._tokenStartColumn + offset) - return True - else: - return False - - -def handleAcceptPositionForKeyword(self, keyword): - if self._input.index > self._tokenStartCharIndex + len(keyword): - offset = len(keyword) - 1 - self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset, - self._tokenStartLine, self._tokenStartColumn + offset) - return True - else: - return False - -@staticmethod -def isIdentifierChar(c): - return c.isalnum() or c == '_' - ->> - -BasicListener(X) ::= << -@parser::members { -if __name__ is not None and "." in __name__: - from .Listener import Listener -else: - from Listener import Listener - -class LeafListener(TListener): - def __init__(self, output): - self._output = output - def visitTerminal(self, node): - print(node.symbol.text, file=self._output) -} ->> - -WalkListener(s) ::= << -walker = ParseTreeWalker() -walker.walk(TParser.LeafListener(self._output), ) ->> - -TreeNodeWithAltNumField(X) ::= << -@parser::members { -class MyRuleNode(ParserRuleContext): - def __init__(self, parent = None, invokingStateNumber = None ): - super(Parser.MyRuleNode, self).__init__(parent, invokingStateNumber) - self.altNum = 0; - def getAltNumber(self): - return self.altNum - def setAltNumber(self, altNum): - self.altNum = altNum -} ->> - -TokenGetterListener(X) ::= << -@parser::members { -if __name__ is not None and "." in __name__: - from .Listener import Listener -else: - from Listener import Listener - -class LeafListener(TListener): - def __init__(self, output): - self._output = output - def exitA(self, ctx): - if ctx.getChildCount()==2: - print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()), file=self._output) - else: - print(str(ctx.ID().symbol), file=self._output) -} ->> - -RuleGetterListener(X) ::= << -@parser::members { -if __name__ is not None and "." in __name__: - from .Listener import Listener -else: - from Listener import Listener - -class LeafListener(TListener): - def __init__(self, output): - self._output = output - def exitA(self, ctx): - if ctx.getChildCount()==2: - print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text, file=self._output) - else: - print(ctx.b(0).start.text, file=self._output) -} ->> - - -LRListener(X) ::= << -@parser::members { -if __name__ is not None and "." in __name__: - from .Listener import Listener -else: - from Listener import Listener - -class LeafListener(TListener): - def __init__(self, output): - self._output = output - def exitE(self, ctx): - if ctx.getChildCount()==3: - print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text, file=self._output) - else: - print(ctx.INT().symbol.text, file=self._output) -} ->> - -LRWithLabelsListener(X) ::= << -@parser::members { -if __name__ is not None and "." in __name__: - from .Listener import Listener -else: - from Listener import Listener - -class LeafListener(TListener): - def __init__(self, output): - self._output = output - def exitCall(self, ctx): - print(ctx.e().start.text + ' ' + str(ctx.eList()), file=self._output) - def exitInt(self, ctx): - print(ctx.INT().symbol.text, file=self._output) -} ->> - -DeclareContextListGettersFunction() ::= << -def foo(): - s = SContext() - a = s.a() - b = s.b() ->> - -Declare_foo() ::= <> - -Invoke_foo() ::= "self.foo()" - -Declare_pred() ::= < -# This token stream ignores the value of {@link Token#getChannel}. If your -# parser requires the token stream filter tokens to only those on a particular -# channel, such as {@link Token#DEFAULT_CHANNEL} or -# {@link Token#HIDDEN_CHANNEL}, use a filtering token stream such a -# {@link CommonTokenStream}.

-from io import StringIO - -from antlr4.Token import Token -from antlr4.error.Errors import IllegalStateException - -# this is just to keep meaningful parameter types to Parser -class TokenStream(object): - - pass - - -class BufferedTokenStream(TokenStream): - - def __init__(self, tokenSource): - # The {@link TokenSource} from which tokens for this stream are fetched. - self.tokenSource = tokenSource - - # A collection of all tokens fetched from the token source. The list is - # considered a complete view of the input once {@link #fetchedEOF} is set - # to {@code true}. - self.tokens = [] - - # The index into {@link #tokens} of the current token (next token to - # {@link #consume}). {@link #tokens}{@code [}{@link #p}{@code ]} should be - # {@link #LT LT(1)}. - # - #

This field is set to -1 when the stream is first constructed or when - # {@link #setTokenSource} is called, indicating that the first token has - # not yet been fetched from the token source. For additional information, - # see the documentation of {@link IntStream} for a description of - # Initializing Methods.

- self.index = -1 - - # Indicates whether the {@link Token#EOF} token has been fetched from - # {@link #tokenSource} and added to {@link #tokens}. This field improves - # performance for the following cases: - # - #