diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 5a01544e01..0000000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,64 +0,0 @@
-version: 2.1
-
-jobs:
- test_tool_and_runtime_java:
- docker:
- - image: cimg/openjdk:11.0
- steps:
- - checkout
- - run:
- name: build tool
- command: mvn -B -V -DskipTests=true -Dmaven.javadoc.skip=true install
- - run:
- name: test runtime
- command: |
- cd runtime-testsuite
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=java.** test
- cd ..
- - run:
- name: test tool
- command: |
- cd tool-testsuite
- mvn -Dparallel=classes -DthreadCount=4 test
- cd ..
- test_runtime:
- parameters:
- test-group:
- description: The section
- type: string
- default: ALL
- target:
- description: The target
- type: string
- default: java
- docker:
- - image: cimg/openjdk:11.0
- environment:
- MAVEN_OPTS: -Xmx512m
- parallelism: 4
- resource_class: large
- environment:
- TARGET: << parameters.target >>
- GROUP: << parameters.test-group >>
- steps:
- - checkout
- - run:
- name: Install << parameters.target >> pre-requisites
- command: |
- f=".circleci/scripts/install-linux-<< parameters.target >>.sh"; ! [ -x "$f" ] || "$f"
- - run:
- name: Build ANTLR4 tool
- command: mvn -B -V -DskipTests=true -Dmaven.javadoc.skip=true install
- - run:
- name: Test << parameters.target >> runtime
- command: |
- .circleci/scripts/run-tests-<< parameters.target >>.sh
-
-workflows:
- build:
- jobs:
- - test_tool_and_runtime_java
- - test_runtime:
- matrix:
- parameters:
- target: [ dart, go, python2, python3, javascript, php, cpp, dotnet ]
diff --git a/.circleci/scripts/install-linux-cpp.sh b/.circleci/scripts/install-linux-cpp.sh
deleted file mode 100755
index 8e3b003a0d..0000000000
--- a/.circleci/scripts/install-linux-cpp.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing cpp SDK..."
-
-sudo apt-get update -y
-sudo apt-get install -y clang
-sudo apt-get install -y cmake
-sudo apt-get install -y pkg-config
-sudo apt-get install -y uuid-dev
-
-echo "done installing cpp SDK"
-
-clang++ --version
-cmake --version
-
-echo "building cpp runtime..."
-
-pushd "runtime/Cpp/"
- echo $PWD
- rc=0
- if [ $rc == 0 ]; then
- cmake . -DCMAKE_BUILD_TYPE=release
- rc=$?
- fi
- if [ $rc == 0 ]; then
- make -j 8
- rc=$?
- fi
-popd
-
-
-echo "done building cpp runtime"
-
diff --git a/.circleci/scripts/install-linux-dart.sh b/.circleci/scripts/install-linux-dart.sh
deleted file mode 100755
index 25e857606b..0000000000
--- a/.circleci/scripts/install-linux-dart.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing dart SDK..."
-sudo apt-get update
-sudo apt-get install apt-transport-https
-sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
-sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
-sudo apt-get update
-sudo apt-get install dart=2.12.1-1
-export PATH="$PATH:/usr/lib/dart/bin"
-echo "done installing dart SDK"
-sudo apt-get install -f
diff --git a/.circleci/scripts/install-linux-dotnet.sh b/.circleci/scripts/install-linux-dotnet.sh
deleted file mode 100755
index 1e23257e42..0000000000
--- a/.circleci/scripts/install-linux-dotnet.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing .Net SDK..."
-wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
-sudo dpkg -i packages-microsoft-prod.deb
-sudo apt-get update; \
- sudo apt-get install -y apt-transport-https && \
- sudo apt-get update && \
- sudo apt-get install -y dotnet-sdk-3.1
-export PATH=$PATH:~/.dotnet
-echo "done installing .Net SDK"
-
-# we need to build the runtime before test run, since we used "--no-dependencies"
-# when we call dotnet cli for restore and build, in order to speed up
-echo "building runtime..."
-dotnet build -c Release -f netstandard2.0 runtime/CSharp/src/Antlr4.csproj
-echo "done building runtime"
diff --git a/.circleci/scripts/install-linux-go.sh b/.circleci/scripts/install-linux-go.sh
deleted file mode 100755
index a3d0937eca..0000000000
--- a/.circleci/scripts/install-linux-go.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing go SDK..."
-sudo apt update
-curl -OL https://go.dev/dl/go1.19.linux-amd64.tar.gz
-sudo tar -C /usr/local -xf go1.19.linux-amd64.tar.gz
-export PATH=$PATH:/usr/local/go/bin
-echo -n "go bin: "; ls -l /usr/local/go/bin
-go version
-echo "done installing go SDK"
diff --git a/.circleci/scripts/install-linux-javascript.sh b/.circleci/scripts/install-linux-javascript.sh
deleted file mode 100755
index 2b8c8912a1..0000000000
--- a/.circleci/scripts/install-linux-javascript.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-# use v14 and check
-echo "installing nodejs..."
-curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
-sudo apt-get install -y nodejs
-echo node version: $(node --version)
-echo "done installing nodejs"
-
-echo "packaging javascript runtime..."
-pushd runtime/JavaScript
- sudo npm install
- sudo npm link
-popd
-echo "done packaging javascript runtime"
diff --git a/.circleci/scripts/install-linux-libcurl3.sh b/.circleci/scripts/install-linux-libcurl3.sh
deleted file mode 100755
index 6fe59bafac..0000000000
--- a/.circleci/scripts/install-linux-libcurl3.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-
-echo "before patching"
-ls -all /lib/x86_64-linux-gnu/ | grep libcurl
-
-# This would fix missing CURL_OPENSSL_3
-# use a dedicated temp dir in the user space
-mkdir ~/libcurl3
-cd ~/libcurl3
-# fetch latest libcurl3
-wget http://archive.ubuntu.com/ubuntu/pool/main/c/curl/libcurl3_7.47.0-1ubuntu2_amd64.deb
-# extract data.tar.xz
-ar x libcurl3* data.tar.xz
-# extract all from data.tar.xz
-tar xf data.tar.xz
-# copy libcurl.so.3 where required
-sudo cp -L ~/libcurl3/usr/lib/x86_64-linux-gnu/libcurl.so.4.4.0 /lib/x86_64-linux-gnu/libcurl.so.4.4.0
-sudo ln -sf libcurl.so.4.4.0 /lib/x86_64-linux-gnu/libcurl.so.4
-cd ..
-# drop dedicated temp dir
-sudo rm -rf ~/libcurl3
-
-echo "after patching"
-ls -all /lib/x86_64-linux-gnu/ | grep libcurl
diff --git a/.circleci/scripts/install-linux-php.sh b/.circleci/scripts/install-linux-php.sh
deleted file mode 100755
index 4127d1ce61..0000000000
--- a/.circleci/scripts/install-linux-php.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-sudo apt install software-properties-common
-sudo add-apt-repository ppa:ondrej/php
-sudo apt update
-
-sudo apt install wget php8.0-cli php8.0-zip unzip
-wget -O composer-setup.php https://getcomposer.org/installer
-sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
-
-sudo apt install php8.0
-sudo apt install php8.0-mbstring
-sudo apt install php8.0-xml
-php -v
-
-
-git clone https://github.com/antlr/antlr-php-runtime.git runtime/PHP
-composer install -d runtime/PHP
-
-mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
\ No newline at end of file
diff --git a/.circleci/scripts/install-linux-python2.sh b/.circleci/scripts/install-linux-python2.sh
deleted file mode 100755
index 5549c1b9c3..0000000000
--- a/.circleci/scripts/install-linux-python2.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing python 2..."
-sudo apt-get update -y
-sudo apt-get install python2
-echo "done installing python 2"
diff --git a/.circleci/scripts/install-linux-python3.sh b/.circleci/scripts/install-linux-python3.sh
deleted file mode 100755
index 4c90f519ca..0000000000
--- a/.circleci/scripts/install-linux-python3.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing python 3..."
-sudo apt-get update -y
-sudo apt-get install python3
-echo "done installing python 3"
diff --git a/.circleci/scripts/install-linux-swift.sh b/.circleci/scripts/install-linux-swift.sh
deleted file mode 100755
index 7390175657..0000000000
--- a/.circleci/scripts/install-linux-swift.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-echo "installing swift SDK..."
-
-.circleci/scripts/install-linux-libcurl3.sh
-
-# see https://tecadmin.net/install-swift-ubuntu-1604-xenial/
-sudo apt-get update -y
-sudo apt-get install clang libicu-dev
-sudo apt-get install libpython2.7 libpython2.7-dev
-
-export SWIFT_VERSION=swift-5.3.2
-echo "installing gpg key..."
-wget -q -O - https://swift.org/keys/all-keys.asc | sudo gpg --import -
-echo "downloading SDK gpg key..."
-SWIFT_SDK=https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1604/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu16.04.tar.gz
-echo $SWIFT_SDK
-wget -q $SWIFT_SDK
-sudo tar xzf $SWIFT_VERSION-RELEASE-ubuntu16.04.tar.gz
-mv $SWIFT_VERSION-RELEASE-ubuntu16.04 $PWD/swift
-
-export SWIFT_HOME=$PWD/swift/$SWIFT_VERSION-RELEASE-ubuntu16.04/usr/bin/
-export PATH=$PWD/swift/usr/bin:$PATH
-
-# This would fix a know linker issue mentioned in: # https://bugs.swift.org/browse/SR-2299
-sudo ln -sf ld.gold /usr/bin/ld
-# This would fix missing libtinfo.so.5
-sudo apt install libncurses5
-
-echo "done installing swift SDK..."
-
-# check swift
-swift --version
-swift build --version
diff --git a/.circleci/scripts/run-tests-cpp.sh b/.circleci/scripts/run-tests-cpp.sh
deleted file mode 100755
index 58b59ff283..0000000000
--- a/.circleci/scripts/run-tests-cpp.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-pushd runtime-testsuite
-export MAVEN_OPTS="-Xmx8g"
-mvn -Dparallel=classes -DthreadCount=4 -Dtest=cpp.** test
-popd
diff --git a/.circleci/scripts/run-tests-dart.sh b/.circleci/scripts/run-tests-dart.sh
deleted file mode 100755
index 2f9015df6c..0000000000
--- a/.circleci/scripts/run-tests-dart.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-dart --version
-
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=dart.** test
-popd
diff --git a/.circleci/scripts/run-tests-dotnet.sh b/.circleci/scripts/run-tests-dotnet.sh
deleted file mode 100755
index c0e6eeef6f..0000000000
--- a/.circleci/scripts/run-tests-dotnet.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-pushd runtime-testsuite
-export MAVEN_OPTS="-Xmx8g"
-mvn -Dparallel=classes -DthreadCount=4 -Dtest=csharp.** test
-popd
diff --git a/.circleci/scripts/run-tests-go.sh b/.circleci/scripts/run-tests-go.sh
deleted file mode 100755
index 4bf8ef67bd..0000000000
--- a/.circleci/scripts/run-tests-go.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-export PATH=$PATH:/usr/local/go/bin # for use on linux
-go version
-
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=go.** test
-popd
diff --git a/.circleci/scripts/run-tests-javascript.sh b/.circleci/scripts/run-tests-javascript.sh
deleted file mode 100755
index b0b461fce0..0000000000
--- a/.circleci/scripts/run-tests-javascript.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-declare -i RESULT=0
-
-pushd runtime/JavaScript
-
- echo "running jasmine tests..."
- npm test
- RESULT+=$?
-
-popd
-
-pushd runtime-testsuite
-
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dtest=javascript.** test
- RESULT+=$?
-
-popd
-
-exit $RESULT
diff --git a/.circleci/scripts/run-tests-php.sh b/.circleci/scripts/run-tests-php.sh
deleted file mode 100755
index e46ebb3d66..0000000000
--- a/.circleci/scripts/run-tests-php.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-php -v
-
-php_path=$(which php)
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -DPHP_PATH="${php_path}" -Dparallel=classes -DthreadCount=4 -Dtest=php.** test
-popd
diff --git a/.circleci/scripts/run-tests-python2.sh b/.circleci/scripts/run-tests-python2.sh
deleted file mode 100755
index 772009ac3d..0000000000
--- a/.circleci/scripts/run-tests-python2.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-python2 --version
-
-# TODO: https://github.com/antlr/antlr4/issues/3521
-#
-# pushd runtime/Python2/tests
-# echo "running native tests..."
-# python2 run.py
-# rc=$?
-# if [ $rc != 0 ]; then
-# echo "failed running native tests"
-# fi
-# popd
-
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=python2.** test
-popd
\ No newline at end of file
diff --git a/.circleci/scripts/run-tests-python3.sh b/.circleci/scripts/run-tests-python3.sh
deleted file mode 100755
index 2be5773a1c..0000000000
--- a/.circleci/scripts/run-tests-python3.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-python3 --version
-
-# TODO: https://github.com/antlr/antlr4/issues/3521
-#
-# pushd runtime/Python3/tests
-# echo "running native tests..."
-# python3 run.py
-# rc=$?
-# if [ $rc != 0 ]; then
-# echo "failed running native tests"
-# fi
-# popd
-
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=python3.** test
-popd
diff --git a/.circleci/scripts/run-tests-swift.sh b/.circleci/scripts/run-tests-swift.sh
deleted file mode 100755
index bc68f84735..0000000000
--- a/.circleci/scripts/run-tests-swift.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-# Appears to be unused
-
-set -euo pipefail
-
-# TODO: https://github.com/antlr/antlr4/issues/3521
-#
-# pushd runtime/Swift
-# echo "running native tests..."
-# ./boot.py --test
-# rc=$?
-# if [ $rc != 0 ]; then
-# echo "failed running native tests"
-# fi
-# popd
-
-pushd runtime-testsuite
- echo "running maven tests..."
- export MAVEN_OPTS="-Xmx8g"
- mvn -Dparallel=classes -DthreadCount=4 -Dtest=swift.** test
-popd
diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml
index af41ed511e..fd8570b958 100644
--- a/.github/workflows/hosted.yml
+++ b/.github/workflows/hosted.yml
@@ -22,8 +22,6 @@ jobs:
exclude:
- os: windows-latest
compiler: gcc
- - os: windows-latest
- compiler: clang
include:
- os: windows-latest
compiler: cl
@@ -158,6 +156,7 @@ jobs:
windows-latest
]
target: [
+ tool,
cpp,
csharp,
dart,
@@ -170,30 +169,6 @@ jobs:
swift,
]
exclude:
- - os: macos-latest
- target: dart
- - os: macos-latest
- target: python3
- - os: macos-latest
- target: swift
-
- - os: ubuntu-latest
- target: csharp
- - os: ubuntu-latest
- target: dart
-
- - os: windows-latest
- target: cpp
- - os: windows-latest
- target: csharp
- - os: windows-latest
- target: dart
- - os: windows-latest
- target: php
- - os: windows-latest
- target: python2
- - os: windows-latest
- target: python3
- os: windows-latest
target: swift
@@ -234,7 +209,7 @@ jobs:
if: steps.setup-java.outputs.cache-hit != 'true'
uses: stCarolas/setup-maven@v4.4
with:
- maven-version: 3.5.4
+ maven-version: 3.8.5
- name: Add msbuild to PATH
if: startswith(matrix.os, 'windows') && (matrix.target == 'cpp')
@@ -306,17 +281,17 @@ jobs:
if: startswith(matrix.os, 'macos') && (matrix.target == 'cpp')
run: echo "PATH=$(brew --prefix)/opt/ccache/libexec:$PATH" >> $GITHUB_ENV
- - name: Build tool with Maven
+ - name: Build ANTLR with Maven
run: mvn install -DskipTests=true -Darguments="-Dmaven.javadoc.skip=true" -B -V
- name: Test tool
- if: matrix.target == 'java'
+ if: matrix.target == 'tool'
run: |
cd tool-testsuite
mvn test
- name: Test runtime (Windows)
- if: startsWith(matrix.os, 'windows')
+ if: startsWith(matrix.os, 'windows') && (matrix.target != 'tool')
run: |
gci env:* | sort-object name
@@ -332,7 +307,7 @@ jobs:
CMAKE_GENERATOR: Ninja
- name: Test runtime (non-Windows)
- if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
+ if: (startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')) && (matrix.target != 'tool')
run: |
env
diff --git a/.gitignore b/.gitignore
index 5c99ef58d6..f517fa3f88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# Nuget packages
+*.nupkg
+
# Maven build folders
target/
# ... but not code generation targets
@@ -29,9 +32,8 @@ __pycache__/
*.userosscache
*.sln.docstates
-# User-specific files (MonoDevelop/Xamarin Studio)
+# User-specific files (MonoDevelop/Xamarin Studio/Visual Studio)
*.userprefs
-*.user
.vs/
project.lock.json
@@ -47,9 +49,6 @@ bld/
[Oo]bj/
[Ll]og/
-# Visual Studio 2015 cache/options directory
-.vs/
-
# NetBeans user configuration files
nbactions*.xml
/nbproject/private/
@@ -102,3 +101,26 @@ javac-services.0.log.lck
!runtime/Python3/test/
Antlr4.sln
runtime/PHP
+
+# Swift binaries
+.build/
+
+# Cpp generated build files
+runtime/Cpp/CMakeCache.txt
+runtime/Cpp/CMakeFiles/
+runtime/Cpp/CPackConfig.cmake
+runtime/Cpp/CPackSourceConfig.cmake
+runtime/Cpp/CTestTestfile.cmake
+runtime/Cpp/Makefile
+runtime/Cpp/_deps/
+runtime/Cpp/cmake_install.cmake
+runtime/Cpp/runtime/CMakeFiles/
+runtime/Cpp/runtime/CTestTestfile.cmake
+runtime/Cpp/runtime/Makefile
+runtime/Cpp/runtime/antlr4_tests
+runtime/Cpp/runtime/antlr4_tests\[1]_include.cmake
+runtime/Cpp/runtime/antlr4_tests\[1]_tests.cmake
+runtime/Cpp/runtime/cmake_install.cmake
+runtime/Cpp/runtime/libantlr4-runtime.4.10.1.dylib
+runtime/Cpp/runtime/libantlr4-runtime.a
+runtime/Cpp/runtime/libantlr4-runtime.dylib
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 33db1610db..0000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-sudo: true
-
-language: java
-
-before_cache:
- - rm -rf $HOME/.m2/repository/org/antlr
-cache:
- timeout: 600
- directories:
- - $HOME/.m2
- - $HOME/Library/Caches/Antlr4
- - $HOME/Library/Caches/Homebrew
-
-stages:
-# - smoke-test
-# - main-test
- - extended-test
-
-matrix:
- include:
- - os: linux
- dist: xenial
- compiler: clang
- env:
- - TARGET=swift
- - GROUP=ALL
- stage: extended-test
-
-before_install:
- - f="./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh"; ! [ -x "$f" ] || "$f"
-
-script:
- - |
- cd runtime-testsuite;
- travis_wait 40 ../.travis/run-tests-$TARGET.sh
- rc=$?
- cat target/surefire-reports/*.dumpstream || true
- exit $rc
diff --git a/LICENSE.txt b/LICENSE.txt
index 2042d1bda6..5d27694155 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,52 +1,28 @@
-[The "BSD 3-clause license"]
-Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+Copyright (c) 2012-2022 The ANTLR Project. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-=====
-
-MIT License for codepointat.js from https://git.io/codepointat
-MIT License for fromcodepoint.js from https://git.io/vDW1m
-
-Copyright Mathias Bynens
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. Neither name of copyright holders nor the names of its contributors
+may be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/THIRD-PARTY-NOTICES.txt b/THIRD-PARTY-NOTICES.txt
new file mode 100644
index 0000000000..defb29eba5
--- /dev/null
+++ b/THIRD-PARTY-NOTICES.txt
@@ -0,0 +1,26 @@
+"antlr4" uses third-party libraries or other resources that may be distributed under licenses different than "antlr4".
+
+1. String.prototype.codePointAt (https://github.com/mathiasbynens/String.prototype.codePointAt)
+
+%% License notice for String.prototype.codePointAt
+==================================================
+Copyright Mathias Bynens
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/antlr4-maven-plugin/pom.xml b/antlr4-maven-plugin/pom.xml
index 57768a8a4b..9ddf63ccd7 100644
--- a/antlr4-maven-plugin/pom.xml
+++ b/antlr4-maven-plugin/pom.xml
@@ -8,18 +8,18 @@
org.antlrantlr4-master
- 4.10.2-SNAPSHOT
+ 4.11.0-SNAPSHOTantlr4-maven-pluginmaven-pluginANTLR 4 Maven pluginMaven plugin for ANTLR 4 grammars
-
+
2009
- 3.8.4
+ 3.8.5
@@ -34,13 +34,13 @@
org.apache.mavenmaven-plugin-api
- 3.8.4
+ ${mavenVersion}providedorg.codehaus.plexusplexus-compiler-api
- 2.9.0
+ 2.12.1org.sonatype.plexus
@@ -65,7 +65,7 @@
org.apache.maven.plugin-toolsmaven-plugin-annotations
- 3.6.2
+ 3.6.4provided
@@ -89,18 +89,18 @@
org.codehaus.plexusplexus-utils
- 3.4.1
+ 3.4.2providedorg.slf4jslf4j-api
- 1.7.32
+ 2.0.0org.slf4jslf4j-simple
- 1.7.32
+ 2.0.0
@@ -166,11 +166,6 @@
-
- org.apache.maven.plugins
- maven-plugin-plugin
- 3.3
- org.apache.maven.pluginsmaven-javadoc-plugin
@@ -179,11 +174,6 @@
true
-
- org.apache.maven.plugins
- maven-jxr-plugin
- 3.1.1
-
-
\ No newline at end of file
+
diff --git a/doc/actions.md b/doc/actions.md
index 35455cb2f2..cb0e0be8d0 100644
--- a/doc/actions.md
+++ b/doc/actions.md
@@ -98,6 +98,7 @@ returnStat : 'return' expr {System.out.println("first token "+$start.getText());
|start|Token|The first token to be potentially matched by the rule that is on the main token channel; in other words, this attribute is never a hidden token. For rules that end up matching no tokens, this attribute points at the first token that could have been matched by this rule. When referring to the current rule, this attribute is available to any action within the rule.|
|stop|Token|The last nonhidden channel token to be matched by the rule. When referring to the current rule, this attribute is available only to the after and finally actions.|
|ctx|ParserRuleContext|The rule context object associated with a rule invocation. All of the other attributes are available through this attribute. For example, `$ctx.start` accesses the start field within the current rules context object. It’s the same as `$start`.|
+|parser|Parser|The parser itself. This attribute can be used, for example, to invoke a method defined in the parser's `@members` section from a semantic predicate.|
## Dynamically-Scoped Attributes
diff --git a/doc/antlr-project-testing.md b/doc/antlr-project-testing.md
index 2cb11938ca..840921ebe4 100644
--- a/doc/antlr-project-testing.md
+++ b/doc/antlr-project-testing.md
@@ -2,11 +2,21 @@
## Introduction
-Because ANTLR supports multiple target languages, the unit tests are broken into two groups: the unit tests that test the tool itself (in `tool-testsuite`) and the unit tests that test the parser runtimes (in `antlr4/runtime-testsuite`). The tool tests are straightforward because they are Java code testing Java code; see the section at the bottom of this file.
+Because ANTLR supports multiple target languages, the unit tests are broken into two groups:
+the unit tests that test the tool itself (in `tool-testsuite`) and the unit tests that test the parser runtimes (in `antlr4/runtime-testsuite`).
+The tool tests are straightforward because they are Java code testing Java code; see the section at the bottom of this file.
-The runtime tests must be specified in a generic fashion to work across language targets. Furthermore, we must test the various targets from Java. This usually means Java launching processes to compile, say, C++ and run parsers.
+The runtime tests must be specified in a generic fashion to work across language targets.
+Furthermore, the various targets from Java must be tested.
-As of 4.10, we use a Java descriptor file held as an [UniversalRuntimeTestDescriptor.java object](https://github.com/antlr/antlr4/blob/master/runtime-testsuite/test/org/antlr/v4/test/runtime/UniversalRuntimeTestDescriptor.java) to represent each runtime test. Each test is described with a text file with various sections and resides in a group directory; see [directories under descriptors dir](https://github.com/antlr/antlr4/blob/master/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors). Here is a sample test descriptor:
+This usually means Java launching processes to compile, say, C++ and run parsers.
+
+As of 4.10, a Java descriptor file held as an [RuntimeTestDescriptor.java](../runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTestDescriptor.java)
+is used to represent each runtime test.
+
+Each test is described with a text file with various sections and resides in a group directory;
+see [directories under descriptors' dir](../runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors).
+Here is a sample test descriptor:
```
[notes]
@@ -34,22 +44,25 @@ a b c
"""
```
-The grammars are strings representing StringTemplates (`ST` objects) so `` will get replace when the unit test file is generated (`Test.java`, `Test.cs`, ...). The `writeln` template must be defined per target. Here are all of the
-[Target templates for runtime tests](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates). Use triple-quotes `"""` when whitespace matters (usually input/output sections).
+The grammars are strings representing StringTemplates (`ST` objects) so `` will get replace when the unit test file is generated (`Test.java`, `Test.cs`, ...).
+The `writeln` template must be defined per target.
+Here are all the
+[Target templates for runtime tests](../runtime-testsuite/resources/org/antlr/v4/test/runtime/templates).
+Use triple-quotes `"""` when whitespace matters (usually input/output sections).
## Requirements
-*out of date, at least for mono*
-
-In order to perform the tests on all target languages, you need to have the following languages installed:
+In order to perform the tests on all target languages, the following tools should be installed:
-* `mono` (e.g., `brew install mono`) on non-Windows boxes (on Windows it uses the Microsoft .net stack). Also must [`xbuild` the runtime](https://github.com/antlr/antlr4/blob/master/doc/releasing-antlr.md) before tests will run; see below
-* `nodejs`
-* Python 2.7
-* Python 3.6
+* dotnet
+* Node.js
+* Python 2
+* Python 3
* Go
-* Swift (via XCode) tested currently only osx
-* clang (for C++ target)
+* Swift
+* Clang (Linux, Mac) or MSBuild (Windows) for C++
+* Dart
+* PHP
To **install into local repository** `~/.m2/repository/org/antlr`, do this:
@@ -58,115 +71,53 @@ $ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
$ mvn install -DskipTests # make sure all artifacts are visible on this machine
```
-Now, make sure C# runtime is built and installed locally.
-
-```bash
-cd ~/antlr/code/antlr4/runtime/CSharp/src
-rm -rf `find . -name '{obj,bin}'`
-dotnet build -c Release runtime/CSharp/src/Antlr4.csproj
-```
-
-C++ test rig automatically builds C++ runtime during tests. Others don't need a prebuilt lib.
-
-
## Running the runtime tests
-A single test rig is sufficient to test all targets against all descriptors using the [junit parameterized tests](https://github.com/junit-team/junit4/wiki/parameterized-tests) mechanism. But, that is inconvenient because we often want to test just a single target or perhaps even just a single test within a single group of a single target. I have automatically generated a bunch of
-[Target runtime test rigs](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/test/org/antlr/v4/test/runtime) that allow developers such flexibility. For example, here are the Python3 test rigs in intellij:
+A single test rig is sufficient to test all targets against all descriptors using the [junit dynamic tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests) mechanism.
+But it's often convenient to test just a single target or perhaps even just a single test within a single group of a single target.
+IntelliJ automatically generates a bunch of
+[Target runtime test rigs](../runtime-testsuite/test/org/antlr/v4/test/runtime) that allows developers such flexibility.
+For example, here are the Python3 test rigs in IntelliJ:
-
+![testrigs](images/testrigs.png)
And the result of testing the entire subdirectory:
-
-
-## Running test subsets
-
-*From the `runtime-testsuite` dir*
+![python3-tests](images/python3-tests.png)
-### Run one test group across targets
+All test are run in parallel both via maven and via IDE.
-```bash
-$ cd runtime-testsuite
-$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
-$ mvn -Dtest=TestParserExec test
--------------------------------------------------------
- T E S T S
--------------------------------------------------------
-Running org.antlr.v4.test.runtime.cpp.TestParserExec
-...
-Tests run: 32, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 114.283 sec
-Running org.antlr.v4.test.runtime.csharp.TestParserExec
-...
-```
+In IntelliJ, it's very easy to go to source by right-clicking on any test and pressing `Jump to source` (F4).
-Or run all lexer related tests:
+## Running test subsets
-```
-$ cd runtime-testsuite
-$ mvn -Dtest=Test*Lexer* test
--------------------------------------------------------
- T E S T S
--------------------------------------------------------
-Running org.antlr.v4.test.runtime.cpp.TestCompositeLexers
-...
-```
+From the `runtime-testsuite` dir
### Run all tests for a single target
```bash
$ cd runtime-testsuite
+$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
$ mvn -Dtest=java.** test
-...
-```
-
-Or run all lexer related tests in Java target only:
-
-```bash
-$ cd runtime-testsuite
-$ mvn -Dtest=java.*Lexer* test
-...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
-Running org.antlr.v4.test.runtime.java.TestCompositeLexers
-Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.277 sec
-Running org.antlr.v4.test.runtime.java.TestLexerErrors
-Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.376 sec
-Running org.antlr.v4.test.runtime.java.TestLexerExec
-Tests run: 38, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.07 sec
-Running org.antlr.v4.test.runtime.java.TestSemPredEvalLexer
-Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.255 sec
-
-Results :
-
-Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
-```
-
-## Testing in parallel
-
-Use this to run tests in parallel:
-
-```bash
-$ export MAVEN_OPTS="-Xmx1G"
-$ mvn -Dparallel=classes -DthreadCount=4 test
+[INFO] Running org.antlr.v4.test.runtime.java.TestIntegerList
+[INFO] Running org.antlr.v4.test.runtime.java.JavaRuntimeTests
...
--------------------------------------------------------
- T E S T S
--------------------------------------------------------
-Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
+[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 s - in org.antlr.v4.test.runtime.java.TestIntegerList
+[INFO] Tests run: 348, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.269 s - in org.antlr.v4.test.runtime.java.JavaRuntimeTests
...
```
-This can be combined with other `-D` above.
-
## Adding a runtime test
-To add a new runtime test, first determine which [group (dir) of tests](https://github.com/antlr/antlr4/blob/master/runtime-testsuite/descriptors/org/antlr/v4/test/runtime/descriptors) it belongs to. Then, add a new descriptor file implementation by filling in one of these (omitting unused sections):
+To add a new runtime test, first determine which [group (dir) of tests](../runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors) it belongs to.
+Then, add a new descriptor file implementation by filling in one of these (omitting unused sections):
```
[notes]
-
+
[type]
[grammar]
@@ -186,12 +137,13 @@ To add a new runtime test, first determine which [group (dir) of tests](https://
[skip]
```
-
-Your best bet is to find a similar test in the appropriate group and then copy and paste the descriptor file, creating a new file within the test group dir. Modify the sections to suit your new problem.
+Your best bet is to find a similar test in the appropriate group and then copy and paste the descriptor file, creating a new file within the test group dir.
+Modify the sections to suit your new problem.
### Ignoring tests
-In order to turn off a test for a particular target, we need to use the `skip` section in the descriptor file. For example, the following skips PHP and Dart targets:
+In order to turn off a test for a particular target, the `skip` section in the descriptor file should be used.
+For example, the following skips PHP and Dart targets:
```
[skip]
@@ -201,11 +153,12 @@ Dart
### Target API/library testing
-Some parts of the runtime API need to be tested with code written specifically in the target language. For example, you can see all of the Java runtime API tests here:
+Some parts of the runtime API need to be tested with code written specifically in the target language.
+For example, all the Java runtime API tests are placed here:
-[https://github.com/antlr/antlr4/tree/master/runtime-testsuite/test/org/antlr/v4/test/runtime/java/api](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/test/org/antlr/v4/test/runtime/java/api)
+[runtime-testsuite/test/org/antlr/v4/test/runtime/java/api](../runtime-testsuite/test/org/antlr/v4/test/runtime/java/api)
-Notice that it is under an `api` dir. The directory above is where all of the `Test*` files go.
+Notice that it is under an `api` dir. The directory above is where all of the `*Test*` files go.
### Cross-language actions embedded within grammars
@@ -221,7 +174,7 @@ Use instead the language-neutral:
```
-Template file [runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Java.test.stg](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Java.test.stg) has templates like:
+Template file [Java.test.stg](../runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Java.test.stg) has templates like:
```
writeln(s) ::= <);>>
@@ -231,6 +184,6 @@ that translate generic operations to target-specific language statements or expr
## Adding an ANTLR tool unit test
-Just go into the appropriate Java test class in dir [antlr4/tool-testsuite/test/org/antlr/v4/test/tool](https://github.com/antlr/antlr4/tree/master/tool-testsuite/test/org/antlr/v4/test/tool) and add your unit test.
+Just go into the appropriate Java test class in dir [antlr4/tool-testsuite/test/org/antlr/v4/test/tool](../tool-testsuite/test/org/antlr/v4/test/tool) and add your unit test.
diff --git a/doc/building-antlr.md b/doc/building-antlr.md
index 17091f9d76..76bdbcd0b6 100644
--- a/doc/building-antlr.md
+++ b/doc/building-antlr.md
@@ -46,7 +46,7 @@ $ if [[ "$?" != "0" ]]; then sudo apt install -y maven; fi
The current maven build seems complicated to me because there is a dependency of the project on itself. The runtime tests naturally depend on the current version being available but it won't compile without the current version. Once you have the generated/installed jar, mvn builds but otherwise there's a dependency on what you are going to build. You will get this error when you try to clean but you can ignore it:
```
-[INFO] ANTLR 4 Runtime Tests (3rd generation) ............. FAILURE [ 0.073 s]
+[INFO] ANTLR 4 Runtime Tests (4th generation) ............. FAILURE [ 0.073 s]
...
[ERROR] Plugin org.antlr:antlr4-maven-plugin:4.10-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact org.antlr:antlr4-maven-plugin:jar:4.10-SNAPSHOT -> [Help 1]
```
diff --git a/doc/creating-a-language-target.md b/doc/creating-a-language-target.md
index dd06208ea6..d658cf4437 100644
--- a/doc/creating-a-language-target.md
+++ b/doc/creating-a-language-target.md
@@ -6,19 +6,42 @@ This document describes how to make ANTLR generate parsers in a new language, *X
Creating a new target involves the following key elements:
-1. For the tool, create class *X*Target as a subclass of class `Target` in package `org.antlr.v4.codegen.target`. This class describes language specific details about escape characters and strings and so on. There is very little to do here typically.
-1. Create *X*.stg in directory tool/resources/org/antlr/v4/tool/templates/codegen/*X*/*X*.stg. This is a [StringTemplate](http://www.stringtemplate.org/) group file (`.stg`) that tells ANTLR how to express all of the parsing elements needed to generate code. You will see templates called `ParserFile`, `Parser`, `Lexer`, `CodeBlockForAlt`, `AltBlock`, etc... Each of these must be described how to build the indicated chunk of code. Your best bet is to find the closest existing target, copy that template file, and tweak to suit.
-1. Create a runtime library to support the parsers generated by ANTLR. Under directory runtime/*X*, you are in complete control of the directory structure as dictated by common usage of that target language. For example, Java has: `runtime/Java/lib` and `runtime/Java/src` directories. Under `src`, you will find a directory structure for package `org.antlr.v4.runtime` and below.
-1. Create a template file for runtime tests. All you have to do is provide a few templates that indicate how to print values and declare variables. Our runtime test mechanism in dir `runtime-testsuite` will automatically generate code using these templates for each target and check the test results. It needs to know how to define various class fields, compare members and so on. You must create a *X*.test.stg file underneath [runtime-testsuite/resources/org/antlr/v4/test/runtime](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/resources/org/antlr/v4/test/runtime). Again, your best bet is to copy the templates from the closest language to your target and tweak it to suit.
-1. Create test files under [/runtime-testsuite/test/org/antlr/v4/test/runtime](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/test/org/antlr/v4/test/runtime). They will load defined test cases in each test descriptor. Also add the `/runtime-testsuite/test/org/antlr/v4/test/runtime/X/BaseXTest.java` which defines how test cases will execute and output.
-1. Create/edit shell scripts in [/.travis](https://github.com/antlr/antlr4/blob/master/.travis) and [/appveyor.yml](https://github.com/antlr/antlr4/blob/master/appveyor.yml) to run tests in CI pipelines.
+1. For the tool, create class *X*Target as a subclass of class `Target` in package `org.antlr.v4.codegen.target`.
+ This class describes language specific details about escape characters and strings and so on.
+ There is very little to do here typically.
+2. Create `*X*.stg` in directory `tool/resources/org/antlr/v4/tool/templates/codegen/*X*/*X*.stg`.
+ This is a [StringTemplate](http://www.stringtemplate.org/) group file (`.stg`) that tells ANTLR how to express
+ all the parsing elements needed to generate code.
+ You will see templates called `ParserFile`, `Parser`, `Lexer`, `CodeBlockForAlt`, `AltBlock`, etc...
+ Each of these must be described how to build the indicated chunk of code.
+ Your best bet is to find the closest existing target, copy that template file, and tweak to suit.
+3. Create a runtime library to support the parsers generated by ANTLR.
+ Under directory `runtime/*X*`, you are in complete control of the directory structure as dictated by common usage of that target language.
+ For example, Java has: `runtime/Java/lib` and `runtime/Java/src` directories.
+ Under `src`, you will find a directory structure for package `org.antlr.v4.runtime` and below.
+4. Create a template file for runtime tests.
+ All you have to do is provide a few templates that indicate how to print values and declare variables.
+ Our runtime test mechanism in dir `runtime-testsuite` will automatically generate code using these templates for each target and check the test results.
+ It needs to know how to define various class fields, compare members and so on.
+ You must create a `*X*.test.stg` file underneath [runtime-testsuite/resources/org/antlr/v4/test/runtime](../runtime-testsuite/resources/org/antlr/v4/test/runtime)
+ and `Test.*x*.stg` underneath [runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers](../runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers).
+ Again, your best bet is to copy the templates from the closest language to your target and tweak it to suit.
+6. Create test files under [/runtime-testsuite/test/org/antlr/v4/test/runtime](../runtime-testsuite/test/org/antlr/v4/test/runtime).
+ They will load defined test cases in each test descriptor.
+ Also add the `/runtime-testsuite/test/org/antlr/v4/test/runtime/X/BaseXTest.java` which defines how test cases will execute and output.
+7. Create/edit shell scripts in [/.github](../.github) to run tests in CI pipelines.
## Getting started
-1. Fork the `antlr/antlr4` repository at github to your own user so that you have repository `username/antlr4`.
-2. Clone `username/antlr4`, the forked repository, to your local disk. Your remote `origin` will be the forked repository on GitHub. Add a remote `upstream` to the original `antlr/antlr4` repository (URL `https://github.com/antlr/antlr4.git`). Changes that you would like to contribute back to the project are done with [pull requests](https://help.github.com/articles/using-pull-requests/).
+1. Fork the `antlr/antlr4` repository at GitHub to your own user so that you have repository `username/antlr4`.
+2. Clone `username/antlr4`, the forked repository, to your local disk.
+ Your remote `origin` will be the forked repository on GitHub.
+ Add a remote `upstream` to the original `antlr/antlr4` repository (URL `https://github.com/antlr/antlr4.git`).
+ Changes that you would like to contribute back to the project are done with [pull requests](https://help.github.com/articles/using-pull-requests/).
3. Try to build it before doing anything
+
```bash
$ mvn compile
```
+
That should proceed with success. See [Building ANTLR](building-antlr.md) for more details.
diff --git a/doc/getting-started.md b/doc/getting-started.md
index 2a98019450..a6d415a0ed 100644
--- a/doc/getting-started.md
+++ b/doc/getting-started.md
@@ -6,7 +6,7 @@ Hi and welcome to the version 4 release of ANTLR! It's named after the fearless
ANTLR is really two things: a tool that translates your grammar to a parser/lexer in Java (or other target language) and the runtime needed by the generated parsers/lexers. Even if you are using the ANTLR Intellij plug-in or ANTLRWorks to run the ANTLR tool, the generated code will still need the runtime library.
-The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.10.1-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
+The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.11.0-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
If you are going to integrate ANTLR into your existing build system using mvn, ant, or want to get ANTLR into your IDE such as eclipse or intellij, see [Integrating ANTLR into Development Systems](https://github.com/antlr/antlr4/blob/master/doc/IDEs.md).
@@ -16,24 +16,24 @@ If you are going to integrate ANTLR into your existing build system using mvn, a
1. Download
```
$ cd /usr/local/lib
-$ curl -O https://www.antlr.org/download/antlr-4.10.1-complete.jar
+$ curl -O https://www.antlr.org/download/antlr-4.11.0-complete.jar
```
Or just download in browser from website:
[https://www.antlr.org/download.html](https://www.antlr.org/download.html)
and put it somewhere rational like `/usr/local/lib`.
-if you are using lower version jdk, just download from [website download](https://github.com/antlr/website-antlr4/tree/gh-pages/download) for previous version, and antlr version before 4.10.1 support jdk 1.8
+if you are using lower version jdk, just download from [website download](https://github.com/antlr/website-antlr4/tree/gh-pages/download) for previous version, and antlr version before 4.11.0 support jdk 1.8
-2. Add `antlr-4.10.1-complete.jar` to your `CLASSPATH`:
+2. Add `antlr-4.11.0-complete.jar` to your `CLASSPATH`:
```
-$ export CLASSPATH=".:/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH"
+$ export CLASSPATH=".:/usr/local/lib/antlr-4.11.0-complete.jar:$CLASSPATH"
```
It's also a good idea to put this in your `.bash_profile` or whatever your startup script is.
3. Create aliases for the ANTLR Tool, and `TestRig`.
```
-$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
-$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
+$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.11.0-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
+$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.11.0-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
```
### WINDOWS
@@ -41,13 +41,13 @@ $ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.10.1-complete.jar:$CLASS
(*Thanks to Graham Wideman*)
0. Install Java (version 1.7 or higher)
-1. Download antlr-4.10.1-complete.jar (or whatever version) from [https://www.antlr.org/download.html](https://www.antlr.org/download.html)
+1. Download antlr-4.11.0-complete.jar (or whatever version) from [https://www.antlr.org/download.html](https://www.antlr.org/download.html)
Save to your directory for 3rd party Java libraries, say `C:\Javalib`
-2. Add `antlr-4.10.1-complete.jar` to CLASSPATH, either:
+2. Add `antlr-4.11.0-complete.jar` to CLASSPATH, either:
* Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable
* Temporarily, at command line:
```
-SET CLASSPATH=.;C:\Javalib\antlr-4.10.1-complete.jar;%CLASSPATH%
+SET CLASSPATH=.;C:\Javalib\antlr-4.11.0-complete.jar;%CLASSPATH%
```
3. Create short convenient commands for the ANTLR Tool, and TestRig, using batch files or doskey commands:
* Batch files (in directory in system PATH) antlr4.bat and grun.bat
@@ -73,7 +73,7 @@ Either launch org.antlr.v4.Tool directly:
```
$ java org.antlr.v4.Tool
-ANTLR Parser Generator Version 4.10.1
+ANTLR Parser Generator Version 4.11.0
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
@@ -82,8 +82,8 @@ ANTLR Parser Generator Version 4.10.1
or use -jar option on java:
```
-$ java -jar /usr/local/lib/antlr-4.10.1-complete.jar
-ANTLR Parser Generator Version 4.10.1
+$ java -jar /usr/local/lib/antlr-4.11.0-complete.jar
+ANTLR Parser Generator Version 4.11.0
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
diff --git a/doc/go-target.md b/doc/go-target.md
index 6bdac133b3..b85c39cc65 100644
--- a/doc/go-target.md
+++ b/doc/go-target.md
@@ -8,32 +8,102 @@
#### 2. Get the Go ANTLR runtime
-Each target language for ANTLR has a runtime package for running parser generated by ANTLR4. The runtime provides a common set of tools for using your parser.
+Each target language for ANTLR has a runtime package for running parser generated by ANTLR4.
+The runtime provides a common set of tools for using your parser. Note that if you have existing projects and have
+yet to replace the `v1.x.x` modules with the `v4` modules, then you can skip ahead to the section *Upgrading to v4
+from earlier versions*
-Get the runtime and install it on your GOPATH:
+The Go runtime uses modules and has a version path of `/v4` to stay in sync with the runtime versions of all the other runtimes.
+Setup is the same as any other module based project:
```bash
-go get github.com/antlr/antlr4/runtime/Go/antlr
+$ cd mymodproject
+$ go mod init mymodproject
```
-#### 3. Set the release tag (optional)
+After which, you can use go get, to get the latest release version of the ANTLR v4 runtime using:
-`go get` has no native way to specify a branch or commit. So, when you run it, you'll download the latest commits. This may or may not be your preference.
+```bash
+go get github.com/antlr/antlr4/runtime/Go/antlr/v4
+```
-You'll need to use git to set the release. For example, to set the release tag for release 4.9.3:
+If your project is already using the v4 runtime, then you can upgrade to the latest release using the usual:
```bash
-cd $GOPATH/src/github.com/antlr/antlr4 # enter the antlr4 source directory
-git checkout tags/4.9.3 # the go runtime was added in release 4.9.3
+go get -u github.com/antlr/antlr4/runtime/Go/antlr/v4
+```
+If you have not yet upgraded existing projects to the `/v4` module path, consult the section *Upgrading to v4
+from earlier versions*
+
+The ANTLR runtime has only one external dependency, and that is part of the go system itself:
+
+```
+golang.org/x/exp
+```
+
+A complete list of releases can be found on [the release page](https://github.com/antlr/antlr4/releases). The Go
+runtime will be tagged using standard Go tags, so release 4.11.0 will be tagged with `v4.11.0` and go get will pick
+that up from the ANTLR repo.
+
+#### 3. Configuring `go generate` in your project
+
+In order to promote the use of repeatable builds, it is often useful to add the latest tool jar to your project's
+repo and configure a `generate.sh` and `generate.go` file. You can of course globally alias the java command required to run the
+tool. Your own CI and dev environment will guide you.
+
+Here is how you can configure `go generate` for your project, assuming that you follow the general recommendation to
+place the ANTLR grammar files in their own package in your project structure. Here is a general template as a starting point:
+
+```
+ .
+ ├── myproject
+ ├── parser
+ │ ├── mygrammar.g4
+ │ ├── antlr-4.11.0-complete.jar
+ │ ├── error_listeners.go
+ │ ├── generate.go
+ │ ├── generate.sh
+ ├── go.mod
+ ├── go.sum
+ ├── main.go
+ └── main_test.go
+```
+
+Make sure that the package statement in your grammar file(s) reflects the go package they exist in.
+The `generate.go` file then looks like this:
+
+```golang
+ package parser
+
+ //go:generate ./generate.sh
+```
+
+And the `generate.sh` file will look similar to this:
+
+```shell
+
+ #!/bin/sh
+
+ alias antlr4='java -Xmx500M -cp "./antlr4-4.11.0-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
+ antlr4 -Dlanguage=Go -no-visitor -package parser *.g4
+```
+
+From the command line at the root of your package “myproject” you can then simply issue the command:
+
+```shell
+ go generate ./...
```
-A complete list of releases can be found on [the release page](https://github.com/antlr/antlr4/releases).
+If you have not yet run a `go get`, you can now run `go mod tidy` and update your
-#### 4. Generate your parser
+#### 4. Generate your parser manually
You use the ANTLR4 "tool" to generate a parser. These will reference the ANTLR runtime, installed above.
-Suppose you're using a UNIX system and have set up an alias for the ANTLR4 tool as described in [the getting started guide](getting-started.md). To generate your go parser, you'll need to invoke:
+Suppose you're using a UNIX system and have set up an alias for the ANTLR4 tool as described in
+[the getting started guide](getting-started.md).
+
+To generate your go parser, you'll need to invoke:
```bash
antlr4 -Dlanguage=Go MyGrammar.g4
@@ -41,17 +111,59 @@ antlr4 -Dlanguage=Go MyGrammar.g4
For a full list of antlr4 tool options, please visit the [tool documentation page](tool-options.md).
+### Upgrading to `/v4` from the default path
+
+*NB: While switch to new module path would normally imply that the public interface for the runtime has changed, this is
+not actually the case - you will not need to change your existing code to upgrade. The main point of the path change is so
+that git tagging works with the ANTLR Go runtime.*
+
+Prior to release v4.11.0 the Go runtime shipped with a module but the module had no version path. This meant that
+the tags in the ANTLR repo did not work, as any tag above `v1` must refer to a matching module path.
+So the command `go get github.com/antlr/antlr4/runtime/Go/antlr` would just bring in
+whatever was the `HEAD` of the master branch. While this *kind of* worked, it is obviously subject to problems and does
+not fit properly with the idiomatic ways of Go.
+
+As of v4.11.0 the module path for the Go runtime is properly in sync with the repo tags. However, this means you need to
+perform a few simple actions in order to upgrade to the `/v4` path.
+
+ - Firstly, make sure that you are using an ANTLR tool jar with a version number of 4.11.0 or greater.
+ - Next you replace any mention of the old (default) path to ANTLR in your go source files. Don't worry that this will
+modify your generated files as...
+ - Now regenerate your grammar files either manually or using `go generate ./...` (see above)
+
+A quick way to replace original module path references is to use this script from your module's base directory:
+
+```shell
+find . -type f \
+ -name '*.go' \
+ -exec sed -i -e 's,github.com/antlr/antlr4/runtime/Go/antlr,github.com/antlr/antlr4/runtime/Go/antlr/v4,g' {} \;
+```
+After performing the steps above, issuing:
+
+```shell
+go mod tidy
+```
+Should fix up your `go.mod` file to reference only the `v4` version of the ANTLR Go runtime:
+
+```shell
+require github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.11.0-xxxxxx-xxxxxxxxx
+```
+
+From this point on, your go mod commands will work correctly with the ANTLR repo and upgrades and downgrades will work
+as you expect. As will branch version such as @dev
+
### Referencing the Go ANTLR runtime
You can reference the go ANTLR runtime package like this:
-```go
-import "github.com/antlr/antlr4/runtime/Go/antlr"
+```golang
+import "github.com/antlr/antlr4/runtime/Go/antlr/v4"
```
### Complete example
-Suppose you're using the JSON grammar from https://github.com/antlr/grammars-v4/tree/master/json.
+Suppose you're using the JSON grammar from https://github.com/antlr/grammars-v4/tree/master/json placed in the parser
+directory and have initialized your `go mod` file.
Then, invoke `antlr4 -Dlanguage=Go JSON.g4`. The result of this is a collection of .go files in the `parser` directory including:
```
@@ -61,15 +173,17 @@ json_lexer.go
json_listener.go
```
-Another common option to the ANTLR tool is `-visitor`, which generates a parse tree visitor, but we won't be doing that here. For a full list of antlr4 tool options, please visit the [tool documentation page](tool-options.md).
+Another common option to the ANTLR tool is `-visitor`, which generates a parse tree visitor, but we won't be doing that here.
+For a full list of antlr4 tool options, please visit the [tool documentation page](tool-options.md).
-We'll write a small main func to call the generated parser/lexer (assuming they are separate). This one writes out the encountered `ParseTreeContext`'s. Suppose the gen'ed parser code is in the `parser` directory relative to this code:
+We'll write a small main func to call the generated parser/lexer (assuming they are separate). This one writes out the
+encountered `ParseTreeContext`'s. Assuming the generated parser code is in the `parser` directory relative to this code:
```golang
package main
import (
- "github.com/antlr/antlr4/runtime/Go/antlr"
+ "github.com/antlr/antlr4/runtime/Go/antlr/v4"
"./parser"
"os"
"fmt"
diff --git a/doc/grammars.md b/doc/grammars.md
index 5f88bf20ac..97ad2659ec 100644
--- a/doc/grammars.md
+++ b/doc/grammars.md
@@ -98,7 +98,7 @@ Not every kind of grammar can import every other kind of grammar:
* Parsers can import parsers.
* Combined grammars can import parsers or lexers without modes.
-ANTLR adds imported rules to the end of the rule list in a main lexer grammar. That means lexer rules in the main grammar get precedence over imported rules. For example, if a main grammar defines rule `IF : ’if’ ;` and an imported grammar defines rule `ID : [a-z]+ ;` (which also recognizes `if`), the imported `ID` won’t hide the main grammar’s `IF` token definition.
+ANTLR adds imported rules to the end of the rule list in a main lexer grammar. That means lexer rules in the main grammar get precedence over imported rules. For example, if a main grammar defines rule `IF : 'if' ;` and an imported grammar defines rule `ID : [a-z]+ ;` (which also recognizes `if`), the imported `ID` won’t hide the main grammar’s `IF` token definition.
## Tokens Section
diff --git a/doc/images/python3-tests.png b/doc/images/python3-tests.png
index 3f278e30e4..9d8a9c079e 100644
Binary files a/doc/images/python3-tests.png and b/doc/images/python3-tests.png differ
diff --git a/doc/images/testrigs.png b/doc/images/testrigs.png
index 00e05b7cef..a9fc04a822 100644
Binary files a/doc/images/testrigs.png and b/doc/images/testrigs.png differ
diff --git a/doc/lexer-rules.md b/doc/lexer-rules.md
index e446bfbf33..08fe7e5d1e 100644
--- a/doc/lexer-rules.md
+++ b/doc/lexer-rules.md
@@ -52,8 +52,8 @@ Match token T at the current input position. Tokens always begin with a capital
-
’literal’
-Match that character or sequence of characters. E.g., ’while’ or ’=’.
+
'literal'
+Match that character or sequence of characters. E.g., 'while' or '='.
@@ -97,8 +97,8 @@ DASH : [---] ; // match a single -, i.e., "any character" between - and - (note
-
’x’..’y’
-Match any single character between range x and y, inclusively. E.g., ’a’..’z’. ’a’..’z’ is identical to [a-z].
+
'x'..'y'
+Match any single character between range x and y, inclusively. E.g., 'a'..'z'. 'a'..'z' is identical to [a-z].
@@ -143,7 +143,7 @@ Evaluate semantic predicate «p». If «p» evaluates to false at runtime, the s
~x
-Match any single character not in the set described by x. Set x can be a single character literal, a range, or a subrule set like ~(’x’|’y’|’z’) or ~[xyz]. Here is a rule that uses ~ to match any character other than characters using ~[\r\n]*:
+Match any single character not in the set described by x. Set x can be a single character literal, a range, or a subrule set like ~('x'|'y'|'z') or ~[xyz]. Here is a rule that uses ~ to match any character other than characters using ~[\r\n]*:
COMMENT : '#' ~[\r\n]* '\r'? '\n' -> skip ;
@@ -176,7 +176,7 @@ mode STR;
MASK : '&' ;
```
-A parser grammar cannot reference literal ’&’, but it can reference the name of the tokens:
+A parser grammar cannot reference literal '&', but it can reference the name of the tokens:
```
parser grammar P;
@@ -320,4 +320,4 @@ The option rewrites `caseInsensitive` grammar option value if it's defined.
```g4
options { caseInsensitive=true; }
STRING options { caseInsensitive=false; } : 'N'? '\'' (~'\'' | '\'\'')* '\''; // lower n is not allowed
-```
\ No newline at end of file
+```
diff --git a/doc/lexicon.md b/doc/lexicon.md
index b99940b1f2..a8f0427606 100644
--- a/doc/lexicon.md
+++ b/doc/lexicon.md
@@ -79,13 +79,13 @@ These more or less correspond to `isJavaIdentifierPart` and `isJavaIdentifierSta
## Literals
-ANTLR does not distinguish between character and string literals as most languages do. All literal strings one or more characters in length are enclosed in single quotes such as `’;’`, `’if’`, `’>=’`, and `’\’’` (refers to the one-character string containing the single quote character). Literals never contain regular expressions.
+ANTLR does not distinguish between character and string literals as most languages do. All literal strings one or more characters in length are enclosed in single quotes such as `';'`, `'if'`, `'>='`, and `'\''` (refers to the one-character string containing the single quote character). Literals never contain regular expressions.
-Literals can contain Unicode escape sequences of the form `’\uXXXX’` (for Unicode code points up to `’U+FFFF’`) or `’\u{XXXXXX}’` (for all Unicode code points), where `’XXXX’` is the hexadecimal Unicode code point value.
+Literals can contain Unicode escape sequences of the form `'\uXXXX'` (for Unicode code points up to `'U+FFFF'`) or `'\u{XXXXXX}'` (for all Unicode code points), where `'XXXX'` is the hexadecimal Unicode code point value.
-For example, `’\u00E8’` is the French letter with a grave accent: `’è’`, and `’\u{1F4A9}’` is the famous emoji: `’💩’`.
+For example, `'\u00E8'` is the French letter with a grave accent: `'è'`, and `'\u{1F4A9}'` is the famous emoji: `'💩'`.
-ANTLR also understands the usual special escape sequences: `’\n’` (newline), `’\r’` (carriage return), `’\t’` (tab), `’\b’` (backspace), and `’\f’` (form feed). You can use Unicode code points directly within literals or use the Unicode escape sequences:
+ANTLR also understands the usual special escape sequences: `'\n'` (newline), `'\r'` (carriage return), `'\t'` (tab), `'\b'` (backspace), and `'\f'` (form feed). You can use Unicode code points directly within literals or use the Unicode escape sequences:
```
grammar Foreign;
diff --git a/doc/parser-rules.md b/doc/parser-rules.md
index 73c363b990..e1a32fe736 100644
--- a/doc/parser-rules.md
+++ b/doc/parser-rules.md
@@ -196,7 +196,7 @@ ANTLR generates a field holding the list of context objects:
## Rule Elements
-Rule elements specify what the parser should do at a given moment just like statements in a programming language. The elements can be rule, token, string literal like expression, ID, and ’return’. Here’s a complete list of the rule elements (we’ll look at actions and predicates in more detail later):
+Rule elements specify what the parser should do at a given moment just like statements in a programming language. The elements can be rule, token, string literal like expression, ID, and 'return'. Here’s a complete list of the rule elements (we’ll look at actions and predicates in more detail later):
@@ -207,7 +207,7 @@ Rule elements specify what the parser should do at a given moment just like stat
Match token T at the current input position. Tokens always begin with a capital letter.
-
’literal’
+
'literal'
Match the string literal at the current input position. A string literal is simply a token with a fixed string.
@@ -232,7 +232,7 @@ Match any single token except for the end of file token. The “dot” operator
-When you want to match everything but a particular token or set of tokens, use the `~` “not” operator. This operator is rarely used in the parser but is available. `~INT` matches any token except the `INT` token. `~’,’` matches any token except the comma. `~(INT|ID)` matches any token except an INT or an ID.
+When you want to match everything but a particular token or set of tokens, use the `~` “not” operator. This operator is rarely used in the parser but is available. `~INT` matches any token except the `INT` token. `~','` matches any token except the comma. `~(INT|ID)` matches any token except an INT or an ID.
Token, string literal, and semantic predicate rule elements can take options. See Rule Element Options.
@@ -486,4 +486,4 @@ Invalid input would cause `config` to return immediately without matching any in
```
file : element* EOF; // don't stop early. must match all input
-```
\ No newline at end of file
+```
diff --git a/doc/python-target.md b/doc/python-target.md
index 7ed73c281e..6f7f6a84a9 100644
--- a/doc/python-target.md
+++ b/doc/python-target.md
@@ -116,14 +116,39 @@ If your grammar is targeted to Python only, you may ignore the following. But if
ID {$text.equals("test")}?
```
-Unfortunately, this is not portable, but you can work around it. The trick involves:
+Unfortunately, this is not portable, as Java and Python (and other target languages) have different syntaxes for all but the simplest language elements. But you can work around it. The trick involves:
* deriving your parser from a parser you provide, such as BaseParser
-* implementing utility methods in this BaseParser, such as "isEqualText"
-* adding a "self" field to the Java/C# BaseParser, and initialize it with "this"
+* implementing utility methods, such as "isEqualText", in this BaseParser, in different files for each target language
+* invoking your utility methods in the semantic predicate from the `$parser` object
Thanks to the above, you should be able to rewrite the above semantic predicate as follows:
+File `MyGrammarParser.g4`:
```
-ID {$self.isEqualText($text,"test")}?
+options { superClass = MyGrammarBaseParser; }
+...
+ID {$parser.isEqualText($text,"test")}?
+```
+
+File `MyGrammarBaseParser.py`:
+```python
+from antlr4 import *
+
+class MyGrammarBaseParser(Parser):
+
+ def isEqualText(a, b):
+ return a is b
+```
+
+File `MyGrammarBaseParser.java`:
+```java
+import org.antlr.v4.runtime.*;
+
+public abstract class MyGrammarBaseParser extends Parser {
+
+ public static boolean isEqualText(a, b) {
+ return a.equals(b);
+ }
+}
```
diff --git a/doc/releasing-antlr.md b/doc/releasing-antlr.md
index 0946880cec..1a677aa14f 100644
--- a/doc/releasing-antlr.md
+++ b/doc/releasing-antlr.md
@@ -25,14 +25,20 @@ Make sure this feature is turned on for the `antlr4` repo upon release.
Wack any existing tag as mvn will create one and it fails if already there.
```
-$ git tag -d 4.10.1
-$ git push origin :refs/tags/4.10.1
-$ git push upstream :refs/tags/4.10.1
+$ git tag -d 4.11.0
+$ git push origin :refs/tags/4.11.0
+$ git push upstream :refs/tags/4.11.0
```
### Go release tags
-It seems that [Go needs a `v` in the release git tag](https://go.dev/ref/mod#glos-version) so make sure that we double up with 4.10.1 and v4.10.1.
+It seems that [Go needs a `v` in the release git tag](https://go.dev/ref/mod#glos-version) so make sure that we double up with 4.11.0 and v4.11.0.
+
+```
+$ git tag -a runtime/Go/antlr/v4/v4.11.0 -m "Go runtime module only"
+$ git push upstream runtime/Go/antlr/v4/v4.11.0
+$ git push origin runtime/Go/antlr/v4/v4.11.0
+```
## Bump version in code and other files
@@ -40,11 +46,11 @@ It seems that [Go needs a `v` in the release git tag](https://go.dev/ref/mod#glo
There are a number of files that require inversion number be updated.
-(In a `pred-4.10.1` branch) Here is a simple script to display any line from the critical files with, say, `4.10.1` in it. Here's an example run of the script:
+Here is a simple script to display any line from the critical files with, say, `4.11.0` in it. Here's an example run of the script:
```bash
-~/antlr/code/antlr4 $ python scripts/update_antlr_version.py 4.10 4.10.1
-Updating ANTLR version from 4.10 to 4.10.1
+~/antlr/code/antlr4 $ python scripts/update_antlr_version.py 4.10 4.11.0
+Updating ANTLR version from 4.10 to 4.11.0
Set ANTLR repo root (default ~/antlr/code/antlr4):
Perform antlr4 `mvn clean` and wipe build dirs Y/N? (default no):
Ok, not cleaning antlr4 dir
@@ -56,14 +62,14 @@ It's also worth doing a quick check to see if you find any other references to a
```bash
mvn clean
-find . -type f -exec grep -l '4\.9' {} \; | grep -v -E '\.o|\.a|\.jar|\.dylib|node_modules/|\.class|tests/|CHANGELOG|\.zip|\.gz|.iml|.svg'
+find . -type f -exec grep -l '4\.10.1' {} \; | grep -v -E '\.o|\.a|\.jar|\.dylib|node_modules/|\.class|tests/|CHANGELOG|\.zip|\.gz|.iml|.svg'
```
Commit to repository.
### PHP runtime
-We only have to copy the PHP runtime into the ANTLR repository to run the unittests. But, we still need to bump the version to 4.10.1 in `~/antlr/code/antlr-php-runtime/src/RuntimeMetaData.php` in the separate repository, commit, and push.
+We only have to copy the PHP runtime into the ANTLR repository to run the unittests. But, we still need to bump the version to 4.11.0 in `~/antlr/code/antlr-php-runtime/src/RuntimeMetaData.php` in the separate repository, commit, and push.
```
cd ~/antlr/code/antlr-php-runtime/src
@@ -74,19 +80,19 @@ git commit -a -m "Update PHP Runtime to latest version"
## Build XPath parsers
-This section addresses a [circular dependency regarding XPath](https://github.com/antlr/antlr4/issues/3600). In the java target I avoided a circular dependency (gen 4.10.1 parser for XPath using 4.10.1 which needs it to build) by hand building the parser: runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java. Probably we won't have to rerun this for the patch releases, just major ones that alter the ATN serialization.
+This section addresses a [circular dependency regarding XPath](https://github.com/antlr/antlr4/issues/3600). In the java target I avoided a circular dependency (gen 4.11.0 parser for XPath using 4.11.0 which needs it to build) by hand building the parser: runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java. Probably we won't have to rerun this for the patch releases, just major ones that alter the ATN serialization.
```
cd ~/antlr/code/antlr4/runtime/CSharp/src/Tree/Xpath
-java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.10.1-SNAPSHOT/antlr4-4.10.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=CSharp XPathLexer.g4
+java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.0-SNAPSHOT/antlr4-4.11.0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=CSharp XPathLexer.g4
cd ~/antlr/code/antlr4/runtime/Python3/tests/expr
-java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.10.1-SNAPSHOT/antlr4-4.10.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python2 Expr.g4
-java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.10.1-SNAPSHOT/antlr4-4.10.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python2 XPathLexer.g4
+java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.0-SNAPSHOT/antlr4-4.11.0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python2 Expr.g4
+java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.0-SNAPSHOT/antlr4-4.11.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.10.1-SNAPSHOT/antlr4-4.10.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python3 Expr.g4
-java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.10.1-SNAPSHOT/antlr4-4.10.1-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python3 XPathLexer.g4
+java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.0-SNAPSHOT/antlr4-4.11.0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python3 Expr.g4
+java -cp ":/Users/parrt/.m2/repository/org/antlr/antlr4/4.11.0-SNAPSHOT/antlr4-4.11.0-SNAPSHOT-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Python3 XPathLexer.g4
```
## Maven Repository Settings
@@ -136,7 +142,7 @@ Here is the file template
## Maven deploy snapshot
-The goal is to get a snapshot, such as `4.10.1-SNAPSHOT`, to the staging server: [antlr4 tool](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4/4.10.1-SNAPSHOT/) and [antlr4 java runtime](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-runtime/4.10.1-SNAPSHOT/).
+The goal is to get a snapshot, such as `4.11.0-SNAPSHOT`, to the staging server: [antlr4 tool](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4/4.11.0-SNAPSHOT/) and [antlr4 java runtime](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-runtime/4.11.0-SNAPSHOT/).
Do this:
@@ -144,16 +150,6 @@ Do this:
$ mvn install -DskipTests # seems required to get the jar files visible to maven
$ mvn deploy -DskipTests
...
-[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ antlr4-tool-testsuite ---
-Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/maven-metadata.xml
-Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/antlr4-tool-testsuite-4.10.1-20161211.173752-1.jar
-Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/antlr4-tool-testsuite-4.10.1-20161211.173752-1.jar (3 KB at 3.4 KB/sec)
-Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/antlr4-tool-testsuite-4.10.1-20161211.173752-1.pom
-Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/antlr4-tool-testsuite-4.10.1-20161211.173752-1.pom (3 KB at 6.5 KB/sec)
-Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
-Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (371 B at 1.4 KB/sec)
-Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/maven-metadata.xml
-Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.10.1-SNAPSHOT/maven-metadata.xml (774 B at 1.8 KB/sec)
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (388 B at 0.9 KB/sec)
[INFO] ------------------------------------------------------------------------
@@ -165,7 +161,7 @@ Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antl
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 6.547 s]
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 2.519 s]
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 2.385 s]
-[INFO] ANTLR 4 Runtime Tests (3rd generation) ............. SUCCESS [ 15.276 s]
+[INFO] ANTLR 4 Runtime Tests (4th generation) ............. SUCCESS [ 15.276 s]
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 2.233 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
@@ -217,18 +213,18 @@ It will start out by asking you the version number:
```
...
-What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.10.1: : 4.10.1
-What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.10.1: :
-What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.10.1: :
-What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.10.1: :
-What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.10.1: :
-What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.10.1: :
-What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.10.1: : 4.10.1
-What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.10.2-SNAPSHOT:
+What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.11.0: : 4.11.0
+What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.11.0: :
+What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.11.0: :
+What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.11.0: :
+What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.11.0: :
+What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.11.0: :
+What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.11.0: : 4.11.0
+What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.11.1-SNAPSHOT:
...
```
-Maven will go through your pom.xml files to update versions from 4.10.1-SNAPSHOT to 4.10.1 for release and then to 4.10.2-SNAPSHOT after release, which is done with:
+Maven will go through your pom.xml files to update versions from 4.11.0-SNAPSHOT to 4.11.0 for release and then to 4.11.1-SNAPSHOT after release, which is done with:
```bash
mvn release:perform -Darguments="-DskipTests"
@@ -242,7 +238,7 @@ Now, go here:
and on the left click "Staging Repositories". You click the staging repo and close it, then you refresh, click it and release it. It's done when you see it here:
- [https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.10.1/antlr4-runtime-4.10.1.jar](https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.10.1/antlr4-runtime-4.10.1.jar)
+ [https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.11.0/antlr4-runtime-4.11.0.jar](https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.11.0/antlr4-runtime-4.11.0.jar)
All releases should be here: [https://repo1.maven.org/maven2/org/antlr/antlr4-runtime](https://repo1.maven.org/maven2/org/antlr/antlr4-runtime).
@@ -265,7 +261,7 @@ Move (and zip) target to website:
```bash
cd src
-zip -r ~/antlr/sites/website-antlr4/download/antlr-javascript-runtime-4.10.1.zip .
+zip -r ~/antlr/sites/website-antlr4/download/antlr-javascript-runtime-4.11.0.zip .
```
### CSharp
@@ -295,7 +291,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/Antlr4.csproj (in 340 ms).
Antlr4 -> /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll
- Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/Antlr4.Runtime.Standard.4.10.1.0.nupkg'.
+ Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/Antlr4.Runtime.Standard.4.11.0.0.nupkg'.
Build succeeded.
0 Warning(s)
@@ -316,7 +312,7 @@ Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD license
Assembly bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll is strongnamed.
$ tree /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/
/Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/
-├── Antlr4.Runtime.Standard.4.10.1.0.nupkg
+├── Antlr4.Runtime.Standard.4.11.0.0.nupkg
└── netstandard2.0
├── Antlr4.Runtime.Standard.deps.json
├── Antlr4.Runtime.Standard.dll
@@ -400,7 +396,7 @@ On a Mac (with XCode 7+ installed):
```bash
cd ~/antlr/code/antlr4/runtime/Cpp
./deploy-macos.sh
-cp antlr4-cpp-runtime-macos.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.10.1-macos.zip
+cp antlr4-cpp-runtime-macos.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.11.0-macos.zip
```
On any Mac or Linux machine:
@@ -408,7 +404,7 @@ On any Mac or Linux machine:
```bash
cd ~/antlr/code/antlr4/runtime/Cpp
./deploy-source.sh
-cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.10.1-source.zip
+cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.11.0-source.zip
```
On a Windows machine the build scripts checks if VS 2017 and/or VS 2019 are installed and builds binaries for each, if found. This script requires 7z to be installed (http://7-zip.org then do `set PATH=%PATH%;C:\Program Files\7-Zip\` from DOS not powershell).
@@ -416,16 +412,16 @@ On a Windows machine the build scripts checks if VS 2017 and/or VS 2019 are inst
```bash
cd ~/antlr/code/antlr4/runtime/Cpp
deploy-windows.cmd Community
-cp antlr4-cpp-runtime-vs2019.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.10.1-vs2019.zip
+cp antlr4-cpp-runtime-vs2019.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.11.0-vs2019.zip
```
Move target to website (**_rename to a specific ANTLR version first if needed_**):
```bash
pushd ~/antlr/sites/website-antlr4/download
-git add antlr4-cpp-runtime-4.10.1-macos.zip
-git add antlr4-cpp-runtime-4.10.1-windows.zip
-git add antlr4-cpp-runtime-4.10.1-source.zip
+git add antlr4-cpp-runtime-4.11.0-macos.zip
+git add antlr4-cpp-runtime-4.11.0-windows.zip
+git add antlr4-cpp-runtime-4.11.0-source.zip
git commit -a -m 'update C++ runtime'
git push origin gh-pages
popd
@@ -457,7 +453,7 @@ mvn -DskipTests javadoc:jar -q install # get lots of errors but works
Jars are in:
```
-~/.m2/repository/org/antlr/antlr4-runtime/4.10.1/antlr4-runtime-4.10.1
+~/.m2/repository/org/antlr/antlr4-runtime/4.11.0/antlr4-runtime-4.11.0
```
### Update version and copy jars / api
@@ -466,36 +462,36 @@ Copy javadoc and java jars to website using this script:
```bash
cd ~/antlr/code/antlr4
-python scripts/deploy_to_website.py 4.10 4.10.1
+python scripts/deploy_to_website.py 4.10.1 4.11.0
```
Output:
```bash
-Updating ANTLR version from 4.10 to 4.10.1
+Updating ANTLR version from 4.10.1 to 4.11.0
Set ANTLR website root (default /Users/parrt/antlr/sites/website-antlr4):
Version string updated. Please commit/push:
Javadoc copied:
- api/Java updated from antlr4-runtime-4.10.1-javadoc.jar
- api/JavaTool updated from antlr4-4.10.1-javadoc.jar
+ api/Java updated from antlr4-runtime-4.11.0-javadoc.jar
+ api/JavaTool updated from antlr4-4.11.0-javadoc.jar
Jars copied:
- antlr-4.10.1-complete.jar
- antlr-runtime-4.10.1.jar
+ antlr-4.11.0-complete.jar
+ antlr-runtime-4.11.0.jar
Please look for and add new api files!!
Then MANUALLY commit/push:
-git commit -a -m 'Update website, javadoc, jars to 4.10.1'
+git commit -a -m 'Update website, javadoc, jars to 4.11.0'
git push origin gh-pages
```
@@ -503,7 +499,7 @@ Once it's done, you must do the following manually:
```
cd ~/antlr/sites/website-antlr4
-git commit -a -m 'Update website, javadoc, jars to 4.10.1'
+git commit -a -m 'Update website, javadoc, jars to 4.11.0'
git push origin gh-pages
```
@@ -515,9 +511,9 @@ cd ~/antlr/sites/website-antlr4/api
git checkout gh-pages
git pull origin gh-pages
cd Java
-jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.10.1/antlr4-runtime-4.10.1-javadoc.jar
+jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.11.0/antlr4-runtime-4.11.0-javadoc.jar
cd ../JavaTool
-jar xvf ~/.m2/repository/org/antlr/antlr4/4.10.1/antlr4-4.10.1-javadoc.jar
+jar xvf ~/.m2/repository/org/antlr/antlr4/4.11.0/antlr4-4.11.0-javadoc.jar
git commit -a -m 'freshen api doc'
git push origin gh-pages
```
diff --git a/doc/swift-target.md b/doc/swift-target.md
index 4c11faad1d..2514fc7c9d 100644
--- a/doc/swift-target.md
+++ b/doc/swift-target.md
@@ -131,7 +131,7 @@ Add Antlr4 as a dependency to your `Package.swift` file. For more information, p
```swift
-.package(name: "Antlr4", url: "https://github.com/antlr/antlr4", from: "4.10.1"
+.package(name: "Antlr4", url: "https://github.com/antlr/antlr4", from: "4.11.0"
```
## Swift access levels
diff --git a/doc/wildcard.md b/doc/wildcard.md
index f3d1c3a0b5..a597c649c9 100644
--- a/doc/wildcard.md
+++ b/doc/wildcard.md
@@ -61,7 +61,7 @@ END : '>>' ;
After crossing through a nongreedy subrule within a lexical rule, all decision-making from then on is "first match wins."
-For example, literal `ab` in rule right-hand side (grammar fragment) `.*? (’a’|’ab’)` is dead code and can never be matched. If the input is ab, the first alternative, ’a’, matches the first character and therefore succeeds. (’a’|’ab’) by itself on the right-hand side of a rule properly matches the second alternative for input ab. This quirk arises from a nongreedy design decision that’s too complicated to go into here.
+For example, literal `ab` in rule right-hand side (grammar fragment) `.*? ('a'|'ab')` is dead code and can never be matched. If the input is ab, the first alternative, 'a', matches the first character and therefore succeeds. ('a'|'ab') by itself on the right-hand side of a rule properly matches the second alternative for input ab. This quirk arises from a nongreedy design decision that’s too complicated to go into here.
@@ -74,7 +74,7 @@ ACTION3 : '<' ( STRING | ~[">] )* '>' ; // Doesn't allow <"foo>; greedy *
STRING : '"' ( '\\"' | . )*? '"' ;
```
-Rule `ACTION1` allows unterminated strings, such as `"foo`, because input `"foo` matches to the wildcard part of the loop. It doesn’t have to go into rule `STRING` to match a quote. To fix that, rule `ACTION2` uses `~’"’` to match any character but the quote. Expression `~’"’` is still ambiguous with the `’]’` that ends the rule, but the fact that the subrule is nongreedy means that the lexer will exit the loop upon a right square bracket. To avoid a nongreedy subrule, make the alternatives explicit. Expression `~[">]` matches anything but the quote and right angle bracket. Here’s a sample run:
+Rule `ACTION1` allows unterminated strings, such as `"foo`, because input `"foo` matches to the wildcard part of the loop. It doesn’t have to go into rule `STRING` to match a quote. To fix that, rule `ACTION2` uses `~'"'` to match any character but the quote. Expression `~'"'` is still ambiguous with the `']'` that ends the rule, but the fact that the subrule is nongreedy means that the lexer will exit the loop upon a right square bracket. To avoid a nongreedy subrule, make the alternatives explicit. Expression `~[">]` matches anything but the quote and right angle bracket. Here’s a sample run:
```bash
$ antlr4 Actions.g4
@@ -225,4 +225,4 @@ ANY : . ;
You get:
-
\ No newline at end of file
+
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 9bbd338f93..919dd1df52 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -2,7 +2,7 @@ FROM adoptopenjdk/openjdk11:alpine AS builder
WORKDIR /opt/antlr4
-ARG ANTLR_VERSION="4.10.1"
+ARG ANTLR_VERSION="4.11.0"
ARG MAVEN_OPTS="-Xmx1G"
diff --git a/docker/README.md b/docker/README.md
index 53743347b3..05a19a7aa5 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -13,7 +13,7 @@ You can build docker image from source code locally.
git clone https://github.com/antlr/antlr4.git
cd antlr4/docker
- docker build -t antlr/antlr4 .
+ docker build -t antlr/antlr4 --platfort linux/amd64 .
## Run
diff --git a/pom.xml b/pom.xml
index 2b5939695f..b0989b628a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,16 +13,16 @@
org.antlrantlr4-master
- 4.10.2-SNAPSHOT
+ 4.11.0-SNAPSHOTpomANTLR 4ANTLR 4 Master Build POM
- http://www.antlr.org
+ https://www.antlr.org/1992ANTLR
- http://www.antlr.org
+ https://www.antlr.org/
@@ -31,8 +31,8 @@
- The BSD License
- http://www.antlr.org/license.html
+ BSD-3-Clause
+ https://www.antlr.org/license.htmlrepo
@@ -40,7 +40,7 @@
Terence Parr
- http://parrt.cs.usfca.edu
+ https://github.com/parrtProject lead - ANTLR
@@ -67,9 +67,10 @@
Jim Idlejimi@idle.ws
- http://www.linkedin.com/in/jimidle
+ https://www.linkedin.com/in/jimidle/Developer - Maven Plugin
+ Developer - Go runtime
diff --git a/runtime-testsuite/pom.xml b/runtime-testsuite/pom.xml
index fbd9ec3958..1ad8e1686e 100644
--- a/runtime-testsuite/pom.xml
+++ b/runtime-testsuite/pom.xml
@@ -10,10 +10,10 @@
org.antlrantlr4-master
- 4.10.2-SNAPSHOT
+ 4.11.0-SNAPSHOTantlr4-runtime-testsuite
- ANTLR 4 Runtime Tests (3rd generation)
+ ANTLR 4 Runtime Tests (4th generation)A collection of tests for ANTLR 4 Runtime libraries.
@@ -22,11 +22,15 @@
2009
+
+ 5.9.0
+
+
org.antlrST4
- 4.3.1
+ 4.3.4test
@@ -42,9 +46,15 @@
test
- junit
- junit
- 4.13.2
+ org.junit.jupiter
+ junit-jupiter-api
+ ${jUnitVersion}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${jUnitVersion}test
@@ -62,19 +72,6 @@
test
-
-
- resources
-
-
- ../runtime
-
- **/.build/**
- **/target/**
- Swift/*.xcodeproj/**
-
-
- org.apache.maven.plugins
@@ -83,18 +80,6 @@
-Dfile.encoding=UTF-8
-
- **/csharp/Test*.java
- **/java/Test*.java
- **/java/api/Test*.java
- **/go/Test*.java
- **/javascript/Test*.java
- **/python2/Test*.java
- **/python3/Test*.java
- **/php/Test*.java
- **/dart/Test*.java
- ${antlr.tests.swift}
-
@@ -138,18 +123,4 @@
-
-
-
- includeSwiftTests
-
-
- mac
-
-
-
- **/swift/Test*.java
-
-
-
diff --git a/runtime-testsuite/resources/junit-platform.properties b/runtime-testsuite/resources/junit-platform.properties
new file mode 100644
index 0000000000..ad19ea833b
--- /dev/null
+++ b/runtime-testsuite/resources/junit-platform.properties
@@ -0,0 +1,3 @@
+junit.jupiter.execution.parallel.enabled = true
+junit.jupiter.execution.parallel.mode.default = concurrent
+junit.jupiter.execution.parallel.mode.classes.default = concurrent
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/BringInLiteralsFromDelegate.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/BringInLiteralsFromDelegate.txt
index 43b6e62243..fa198f3065 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/BringInLiteralsFromDelegate.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/BringInLiteralsFromDelegate.txt
@@ -18,6 +18,4 @@ s
=a
[output]
-"""S.a
-"""
-
+"""S.a"""
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorInvokesDelegateRuleWithReturnStruct.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorInvokesDelegateRuleWithReturnStruct.txt
index 82ba1aec11..339a3f4740 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorInvokesDelegateRuleWithReturnStruct.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorInvokesDelegateRuleWithReturnStruct.txt
@@ -19,6 +19,5 @@ s
b
[output]
-"""S.ab
-"""
+"""S.ab"""
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorRuleOverridesDelegate.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorRuleOverridesDelegate.txt
index 74d90f55bc..d25532f56e 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorRuleOverridesDelegate.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/CompositeParsers/DelegatorRuleOverridesDelegate.txt
@@ -19,6 +19,4 @@ a
c
[output]
-"""S.a
-"""
-
+"""S.a"""
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ContextListGetters.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ContextListGetters.txt
index ce9f4ab7fb..1db5baad56 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ContextListGetters.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserErrors/ContextListGetters.txt
@@ -21,6 +21,4 @@ s
abab
[output]
-"""abab
-"""
-
+"""abab"""
\ No newline at end of file
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 7db6198596..d1cc7624a4 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
@@ -25,7 +25,7 @@ baa
Cpp
CSharp
Go
-Node
+JavaScript
PHP
Python2
Python3
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt
index 6b964f0a9c..e6c01d50a2 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt
@@ -33,3 +33,5 @@ expression
[input]
a
+[skip]
+Go
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt
new file mode 100644
index 0000000000..ac6963e588
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt
@@ -0,0 +1,33 @@
+[notes]
+Checks that this compiles; see https://github.com/antlr/antlr4/issues/2016
+
+[type]
+Parser
+
+[grammar]
+grammar Test;
+
+expression
+@after {
+
+}
+ : op=NOT args+=expression
+ | args+=expression (op=AND args+=expression)+
+ | args+=expression (op=OR args+=expression)+
+ | IDENTIFIER
+ ;
+
+AND : 'and' ;
+OR : 'or' ;
+NOT : 'not' ;
+IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]* ;
+WS : [ \t\r\n]+ -> skip ;
+
+[start]
+expression
+
+[input]
+a and b
+
+[skip]
+Cpp
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ReservedWordsEscaping.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ReservedWordsEscaping.txt
index 7ae27a5233..15e8d6c4aa 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ReservedWordsEscaping.txt
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ReservedWordsEscaping.txt
@@ -35,5 +35,4 @@ root
for for break break for if if for continue
[output]
-"""for for break break for if if for continue
-"""
\ No newline at end of file
+"""for for break break for if if for continue"""
\ No newline at end of file
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 7736c7a467..25775e96e6 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,6 +51,6 @@ between X1 and X2 or between X3 and X4
Go
Python2
Python3
-Node
+JavaScript
PHP
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 70ee58e5cd..7c13488fdf 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
@@ -38,7 +38,7 @@ Cpp
CSharp
Dart
Go
-Node
+JavaScript
PHP
Python2
Python3
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Antlr4.Test.csproj.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Antlr4.Test.csproj.stg
new file mode 100644
index 0000000000..aa1073c574
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Antlr4.Test.csproj.stg
@@ -0,0 +1,25 @@
+\
+
+ \
+ \net6.0\
+ \$(NoWarn);CS3021\
+ \Test\
+ \Exe\
+ \.\
+ \Antlr4.Test\
+ \false\
+ \false\
+ \false\
+ \false\
+ \false\
+ \false\
+ \false\
+ \
+
+ \
+ \
+ \\
+ \
+ \
+
+\
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Package.swift.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Package.swift.stg
new file mode 100644
index 0000000000..43ad150307
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Package.swift.stg
@@ -0,0 +1,11 @@
+// swift-tools-version: 5.6
+
+import PackageDescription
+
+let package = Package(
+ name: "Test",
+ targets: [
+ .executableTarget(name: "Test", path: ".",
+ exclude:[ "}; separator = ", ", wrap> ]),
+ ]
+)
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestLexer.java b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestLexer.java
new file mode 100644
index 0000000000..d1cb77866f
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestLexer.java
@@ -0,0 +1,10 @@
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.Lexer;
+
+public abstract class RuntimeTestLexer extends Lexer {
+ protected java.io.PrintStream outStream = System.out;
+
+ public RuntimeTestLexer(CharStream input) { super(input); }
+
+ public void setOutStream(java.io.PrintStream outStream) { this.outStream = outStream; }
+}
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestParser.java b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestParser.java
new file mode 100644
index 0000000000..1ed38f4959
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/RuntimeTestParser.java
@@ -0,0 +1,14 @@
+import org.antlr.v4.runtime.Parser;
+import org.antlr.v4.runtime.TokenStream;
+
+public abstract class RuntimeTestParser extends Parser {
+ protected java.io.PrintStream outStream = System.out;
+
+ public RuntimeTestParser(TokenStream input) {
+ super(input);
+ }
+
+ public void setOutStream(java.io.PrintStream outStream) {
+ this.outStream = outStream;
+ }
+}
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cpp.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cpp.stg
new file mode 100644
index 0000000000..7afd8c8750
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cpp.stg
@@ -0,0 +1,52 @@
+#include \
+
+#include "antlr4-runtime.h"
+#include ".h"
+
+#include ".h"
+
+
+using namespace antlr4;
+
+
+class TreeShapeListener : public tree::ParseTreeListener {
+public:
+ void visitTerminal(tree::TerminalNode *) override {}
+ void visitErrorNode(tree::ErrorNode *) override {}
+ void exitEveryRule(ParserRuleContext *) override {}
+ void enterEveryRule(ParserRuleContext *ctx) override {
+ for (auto child : ctx->children) {
+ tree::ParseTree *parent = child->parent;
+ ParserRuleContext *rule = dynamic_cast\(parent);
+ if (rule != ctx) {
+ throw "Invalid parse tree shape detected.";
+ }
+ }
+ }
+};
+
+
+int main(int argc, const char* argv[]) {
+ ANTLRFileStream input;
+ input.loadFromFile(argv[1]);
+ lexer(&input);
+ CommonTokenStream tokens(&lexer);
+
+ parser(&tokens);
+
+ DiagnosticErrorListener errorListener;
+ parser.addErrorListener(&errorListener);
+
+ tree::ParseTree *tree = parser.();
+ TreeShapeListener listener;
+ tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
+
+ tokens.fill();
+ for (auto token : tokens.getTokens())
+ std::cout \<\< token->toString() \<\< std::endl;
+
+ std::cout \<\< lexer.getInterpreter\()->getDFA(Lexer::DEFAULT_MODE).toLexerString();
+
+
+ return 0;
+}
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cs.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cs.stg
new file mode 100644
index 0000000000..d9ec86b6c5
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.cs.stg
@@ -0,0 +1,47 @@
+using System;
+using Antlr4.Runtime;
+using Antlr4.Runtime.Tree;
+using System.Text;
+
+public class Test {
+ public static void Main(string[] args) {
+ Console.OutputEncoding = Encoding.UTF8;
+ Console.InputEncoding = Encoding.UTF8;
+ var input = CharStreams.fromPath(args[0]);
+ var lex = new (input);
+ var tokens = new CommonTokenStream(lex);
+
+ var parser = new (tokens);
+
+ parser.AddErrorListener(new DiagnosticErrorListener());
+
+ parser.BuildParseTree = true;
+ var tree = parser.();
+ ParseTreeWalker.Default.Walk(new TreeShapeListener(), tree);
+
+ tokens.Fill();
+ foreach (object t in tokens.GetTokens())
+ Console.Out.WriteLine(t);
+
+ Console.Out.Write(lex.Interpreter.GetDFA(Lexer.DEFAULT_MODE).ToLexerString());
+
+
+ }
+}
+
+
+class TreeShapeListener : IParseTreeListener {
+ public void VisitTerminal(ITerminalNode node) { }
+ public void VisitErrorNode(IErrorNode node) { }
+ public void ExitEveryRule(ParserRuleContext ctx) { }
+
+ public void EnterEveryRule(ParserRuleContext ctx) {
+ for (int i = 0; i \< ctx.ChildCount; i++) {
+ IParseTree parent = ctx.GetChild(i).Parent;
+ if (!(parent is IRuleNode) || ((IRuleNode)parent).RuleContext != ctx) {
+ throw new Exception("Invalid parse tree shape detected.");
+ }
+ }
+ }
+}
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.dart.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.dart.stg
new file mode 100644
index 0000000000..e645baa4d5
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.dart.stg
@@ -0,0 +1,60 @@
+import 'dart:io';
+import 'package:antlr4/antlr4.dart';
+
+import '.dart';
+
+import '.dart';
+
+
+void main(List\ args) async {
+ CharStream input = await InputStream.fromPath(args[0]);
+ final lex = (input);
+ final tokens = CommonTokenStream(lex);
+
+ final parser = (tokens);
+
+ parser.addErrorListener(new DiagnosticErrorListener());
+
+
+ ProfilingATNSimulator profiler = ProfilingATNSimulator(parser);
+ parser.setInterpreter(profiler);
+
+ parser.buildParseTree = true;
+
+ ProfilingATNSimulator profiler = ProfilingATNSimulator(parser);
+ parser.setInterpreter(profiler);
+
+ ParserRuleContext tree = parser.();
+
+ print('[${profiler.getDecisionInfo().join(', ')}]');
+
+ ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree);
+
+ tokens.fill();
+ for (Object t in tokens.getTokens()!)
+ print(t);
+
+ stdout.write(lex.interpreter!.getDFA(Lexer.DEFAULT_MODE).toLexerString());
+
+
+}
+
+
+class TreeShapeListener implements ParseTreeListener {
+ @override void visitTerminal(TerminalNode node) {}
+
+ @override void visitErrorNode(ErrorNode node) {}
+
+ @override void exitEveryRule(ParserRuleContext ctx) {}
+
+ @override
+ void enterEveryRule(ParserRuleContext ctx) {
+ for (var i = 0; i \< ctx.childCount; i++) {
+ final parent = ctx.getChild(i)?.parent;
+ if (!(parent is RuleNode) || (parent as RuleNode).ruleContext != ctx) {
+ throw StateError('Invalid parse tree shape detected.');
+ }
+ }
+ }
+}
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.go.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.go.stg
new file mode 100644
index 0000000000..d8b479b977
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.go.stg
@@ -0,0 +1,54 @@
+package main
+import (
+ "test/parser"
+ "github.com/antlr/antlr4/runtime/Go/antlr/v4"
+ "fmt"
+ "os"
+)
+
+
+type TreeShapeListener struct {
+ *parser.BaseListener
+}
+
+func NewTreeShapeListener() *TreeShapeListener {
+ return new(TreeShapeListener)
+}
+
+func (this *TreeShapeListener) EnterEveryRule(ctx antlr.ParserRuleContext) {
+ for i := 0; i\
+
+func main() {
+ input, err := antlr.NewFileStream(os.Args[1])
+ if err != nil {
+ fmt.Printf("Failed to find file: %v", err)
+ return
+ }
+ lexer := parser.New(input)
+ stream := antlr.NewCommonTokenStream(lexer,0)
+
+ p := parser.New(stream)
+
+ p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
+
+ p.BuildParseTrees = true
+ tree := p.()
+ antlr.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)
+
+ stream.Fill()
+ for _, t := range stream.GetAllTokens() {
+ fmt.Println(t)
+ }
+
+ fmt.Print(lexer.GetInterpreter().DecisionToDFA()[antlr.LexerDefaultMode].ToLexerString())
+
+
+}
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.java.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.java.stg
new file mode 100644
index 0000000000..76eae4e316
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.java.stg
@@ -0,0 +1,89 @@
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.tree.*;
+import org.antlr.v4.runtime.atn.*;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.file.Paths;
+import java.util.Arrays;
+
+public class Test {
+ public static void main(String[] args) throws Exception {
+ recognize(args[0], System.out, System.err);
+ }
+
+ public static void recognize(String inputFile, PrintStream outStream, PrintStream errorStream) throws IOException {
+ CustomStreamErrorListener errorListener = new CustomStreamErrorListener(errorStream);
+
+ CharStream input = CharStreams.fromPath(Paths.get(inputFile));
+ lexer = new (input);
+ lexer.setOutStream(outStream);
+ lexer.removeErrorListeners();
+ lexer.addErrorListener(errorListener);
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+
+ CommonTokenStream tokens = null; // It's required for compilation
+
+
+ parser = new (tokens);
+ parser.setOutStream(outStream);
+ parser.removeErrorListeners();
+ parser.addErrorListener(errorListener);
+
+ parser.addErrorListener(new DiagnosticErrorListener());
+
+ parser.setBuildParseTree(true);
+
+ ProfilingATNSimulator profiler = new ProfilingATNSimulator(parser);
+ parser.setInterpreter(profiler);
+
+ ParserRuleContext tree = parser.();
+
+ outStream.println(Arrays.toString(profiler.getDecisionInfo()));
+
+ ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);
+
+ tokens.fill();
+ for (Object t : tokens.getTokens()) outStream.println(t);
+
+ outStream.print(lexer.getInterpreter().getDFA(Lexer.DEFAULT_MODE).toLexerString());
+
+
+ }
+
+ static class CustomStreamErrorListener extends BaseErrorListener {
+ private final PrintStream printStream;
+
+ public CustomStreamErrorListener(PrintStream printStream){
+ this.printStream = printStream;
+ }
+
+ @Override
+ public void syntaxError(Recognizer\, ?> recognizer,
+ Object offendingSymbol,
+ int line,
+ int charPositionInLine,
+ String msg,
+ RecognitionException e) {
+ printStream.println("line " + line + ":" + charPositionInLine + " " + msg);
+ }
+ }
+
+
+ static class TreeShapeListener implements ParseTreeListener {
+ @Override public void visitTerminal(TerminalNode node) { }
+ @Override public void visitErrorNode(ErrorNode node) { }
+ @Override public void exitEveryRule(ParserRuleContext ctx) { }
+
+ @Override
+ public void enterEveryRule(ParserRuleContext ctx) {
+ for (int i = 0; i \< ctx.getChildCount(); i++) {
+ ParseTree parent = ctx.getChild(i).getParent();
+ if (!(parent instanceof RuleNode) || ((RuleNode)parent).getRuleContext() != ctx) {
+ throw new IllegalStateException("Invalid parse tree shape detected.");
+ }
+ }
+ }
+ }
+
+}
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.js.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.js.stg
new file mode 100644
index 0000000000..f82782bd28
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.js.stg
@@ -0,0 +1,55 @@
+import antlr4 from 'file:///src/antlr4/index.js'
+import from './.js';
+
+import from './.js';
+
+import Listener from './Listener.js';
+
+
+import Visitor from './Visitor.js';
+
+
+class TreeShapeListener extends antlr4.tree.ParseTreeListener {
+ enterEveryRule(ctx) {
+ for (let i = 0; i \< ctx.getChildCount; i++) {
+ const child = ctx.getChild(i)
+ const parent = child.parentCtx
+ if (parent.getRuleContext() !== ctx || !(parent instanceof antlr4.tree.RuleNode)) {
+ throw `Invalid parse tree shape detected.`
+ }
+ }
+ }
+}
+
+
+function main(argv) {
+ var input = new antlr4.FileStream(argv[2], true);
+ var lexer = new (input);
+ var stream = new antlr4.CommonTokenStream(lexer);
+
+ var parser = new (stream);
+
+ parser.addErrorListener(new antlr4.error.DiagnosticErrorListener());
+
+ parser.buildParseTrees = true;
+ const printer = function() {
+ this.println = function(s) { console.log(s); }
+ this.print = function(s) { process.stdout.write(s); }
+ return this;
+ };
+ parser.printer = new printer();
+ var tree = parser.();
+ antlr4.tree.ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);
+
+ stream.fill();
+ for(var i=0; i\
+ process.stdout.write(lexer._interp.decisionToDFA[antlr4.Lexer.DEFAULT_MODE].toLexerString());
+
+
+}
+
+main(process.argv);
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.php.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.php.stg
new file mode 100644
index 0000000000..a806e591c0
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.php.stg
@@ -0,0 +1,68 @@
+\
+final class TreeShapeListener implements ParseTreeListener {
+ public function visitTerminal(TerminalNode $node) : void {}
+ public function visitErrorNode(ErrorNode $node) : void {}
+ public function exitEveryRule(ParserRuleContext $ctx) : void {}
+
+ public function enterEveryRule(ParserRuleContext $ctx) : void {
+ for ($i = 0, $count = $ctx->getChildCount(); $i \< $count; $i++) {
+ $parent = $ctx->getChild($i)->getParent();
+
+ if (!($parent instanceof RuleNode) || $parent->getRuleContext() !== $ctx) {
+ throw new RuntimeException('Invalid parse tree shape detected.');
+ }
+ }
+ }
+}
+
+
+$input = InputStream::fromPath($argv[1]);
+$lexer = new ($input);
+$lexer->addErrorListener(new ConsoleErrorListener());
+$tokens = new CommonTokenStream($lexer);
+
+$parser = new ($tokens);
+
+$parser->addErrorListener(new DiagnosticErrorListener());
+
+$parser->addErrorListener(new ConsoleErrorListener());
+$parser->setBuildParseTree(true);
+$tree = $parser->();
+
+ParseTreeWalker::default()->walk(new TreeShapeListener(), $tree);
+
+$tokens->fill();
+
+foreach ($tokens->getAllTokens() as $token) {
+ echo $token . \PHP_EOL;
+}
+
+echo $lexer->getInterpreter()->getDFA(Lexer::DEFAULT_MODE)->toLexerString();
+
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.py.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.py.stg
new file mode 100644
index 0000000000..e09e2a1169
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.py.stg
@@ -0,0 +1,51 @@
+from __future__ import print_function
+import sys
+import codecs
+from antlr4 import *
+from import
+
+from import
+from Listener import Listener
+from Visitor import Visitor
+
+class TreeShapeListener(ParseTreeListener):
+
+ def visitTerminal(self, node:TerminalNode):
+ pass
+
+ def visitErrorNode(self, node:ErrorNode):
+ pass
+
+ def exitEveryRule(self, ctx:ParserRuleContext):
+ pass
+
+ def enterEveryRule(self, ctx:ParserRuleContext):
+ for child in ctx.getChildren():
+ parent = child.parentCtx
+ if not isinstance(parent, RuleNode) or parent.getRuleContext() != ctx:
+ raise IllegalStateException("Invalid parse tree shape detected.")
+
+
+def main(argv):
+ input = FileStream(argv[1], encoding='utf-8', errors='replace')
+ lexer = (input)
+ stream = CommonTokenStream(lexer)
+
+ parser = (stream)
+
+ parser.addErrorListener(DiagnosticErrorListener())
+
+ parser.buildParseTrees = True
+ tree = parser.()
+ ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree)
+
+ stream.fill()
+ [ print(tunicode(t)) for t in stream.tokens ]
+
+ print(lexer._interp.decisionToDFA[Lexer.DEFAULT_MODE].toLexerString(), end='')
+
+
+
+if __name__ == '__main__':
+ main(sys.argv)
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.vcxproj.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.vcxproj.stg
new file mode 100644
index 0000000000..aefd731b6d
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/Test.vcxproj.stg
@@ -0,0 +1,85 @@
+\
+\
+ \
+ \
+ \Release\
+ \x64\
+ \
+ \
+ \
+ \16.0\
+ \Win32Proj\
+ \{f3708606-c8fb-45ca-ae36-b729f91e972b}\
+ \Test\
+ \10.0\
+ \
+ \
+
+ \
+ \Application\
+ \false\
+ \v143\
+ \false\ \
+ \Unicode\
+ \
+
+ \
+ \
+ \
+ \
+
+ \
+ \false\
+ \;$(IncludePath)\
+ \$(VC_ReferencesPath_x64);\
+ \$(SolutionDir)\
+ \
+
+ \
+ \
+ \TurnOffAllWarnings\
+ \false\
+ \false\
+ \false\
+ \NDEBUG;_CONSOLE;%(PreprocessorDefinitions)\
+ \true\
+ \stdcpp17\
+ \None\
+ \
+ \
+ \Console\
+ \true\
+ \false\
+ \false\
+ \"\\antlr4-runtime.lib";%(AdditionalDependencies)\
+ \
+ \
+
+ \
+ \
+ \
+
+
+ \
+ \
+
+
+
+ \
+ \
+ \
+ \
+
+
+
+ \
+ \
+ \
+ \
+
+
+ \
+ \
+
+ \
+\
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/main.swift.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/main.swift.stg
new file mode 100644
index 0000000000..3d43f33640
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/main.swift.stg
@@ -0,0 +1,47 @@
+import Antlr4
+import Foundation
+
+
+class TreeShapeListener: ParseTreeListener{
+ func visitTerminal(_ node: TerminalNode){ }
+ func visitErrorNode(_ node: ErrorNode){ }
+ func enterEveryRule(_ ctx: ParserRuleContext) throws { }
+ func exitEveryRule(_ ctx: ParserRuleContext) throws {
+ for i in 0..\
+
+let args = CommandLine.arguments
+let input = try ANTLRFileStream(args[1])
+let lex = (input)
+let tokens = CommonTokenStream(lex)
+
+let parser = try (tokens)
+
+parser.addErrorListener(DiagnosticErrorListener())
+
+parser.setBuildParseTree(true)
+
+let profiler = ProfilingATNSimulator(parser)
+parser.setInterpreter(profiler)
+
+let tree = try parser.()
+
+print(profiler.getDecisionInfo().description)
+
+try ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree)
+
+try tokens.fill()
+for t in tokens.getTokens() {
+ print(t)
+}
+
+print(lex.getInterpreter().getDFA(Lexer.DEFAULT_MODE).toLexerString(), terminator: "")
+
+
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/package.json b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/package.json
new file mode 100644
index 0000000000..1632c2c4df
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/package.json
@@ -0,0 +1 @@
+{"type": "module"}
\ No newline at end of file
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/pubspec.yaml.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/pubspec.yaml.stg
new file mode 100644
index 0000000000..16e3c769e5
--- /dev/null
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/helpers/pubspec.yaml.stg
@@ -0,0 +1,6 @@
+name: "test"
+dependencies:
+ antlr4:
+ path:
+environment:
+ sdk: ">=2.12.0 \<3.0.0"
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg
index cd9270286c..5d9cb986fc 100644
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg
+++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg
@@ -18,7 +18,7 @@ AppendStr(a,b) ::= <%%>
Concat(a,b) ::= ""
-AssertIsList(v) ::= "System.Collections.IList __ttt__ = ;" // just use static type system
+AssertIsList(v) ::= "System.Collections.IList __ttt__ = (System.Collections.IList);" // just use static type system
AssignLocal(s,v) ::= " = ;"
@@ -232,7 +232,7 @@ public class LeafListener : TBaseListener {
}
sb.Length = sb.Length - 2;
sb.Append ("]");
- Output.Write ("{0} {1} {2}", ctx.INT (0).Symbol.Text,
+ Output.Write ("{0} {1} {2}\n", ctx.INT (0).Symbol.Text,
ctx.INT (1).Symbol.Text, sb.ToString());
}
else
@@ -253,7 +253,7 @@ public class LeafListener : TBaseListener {
public override void ExitA(TParser.AContext ctx) {
if (ctx.ChildCount==2) {
- Output.Write("{0} {1} {2}",ctx.b(0).Start.Text,
+ Output.Write("{0} {1} {2}\n",ctx.b(0).Start.Text,
ctx.b(1).Start.Text,ctx.b()[0].Start.Text);
} else
Output.WriteLine(ctx.b(0).Start.Text);
@@ -293,7 +293,7 @@ public class LeafListener : TBaseListener {
}
public override void ExitCall(TParser.CallContext ctx) {
- Output.Write("{0} {1}",ctx.e().Start.Text,ctx.eList());
+ Output.Write("{0} {1}\n",ctx.e().Start.Text,ctx.eList());
}
public override void ExitInt(TParser.IntContext ctx) {
Output.WriteLine(ctx.INT().Symbol.Text);
diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Chrome.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Chrome.test.stg
deleted file mode 100644
index 7b4729eb5c..0000000000
--- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Chrome.test.stg
+++ /dev/null
@@ -1,290 +0,0 @@
-writeln(s) ::= < + '\\n';>>
-
-write(s) ::= <;>>
-
-False() ::= "false"
-
-True() ::= "true"
-
-Not(v) ::= "!"
-
-Assert(s) ::= ""
-
-Cast(t,v) ::= ""
-
-Append(a,b) ::= " + "
-
-AppendStr(a,b) ::= <%%>
-
-Concat(a,b) ::= ""
-
-AssertIsList(v) ::= <>
-
-AssignLocal(s,v) ::= " = ;"
-
-InitIntMember(n,v) ::= <%this. = ;%>
-
-InitBooleanMember(n,v) ::= <%this. = ;%>
-
-InitIntVar(n,v) ::= <%%>
-
-IntArg(n) ::= ""
-
-VarRef(n) ::= ""
-
-GetMember(n) ::= <%this.%>
-
-SetMember(n,v) ::= <%this. = ;%>
-
-AddMember(n,v) ::= <%this. += ;%>
-
-MemberEquals(n,v) ::= <%this. === %>
-
-ModMemberEquals(n,m,v) ::= <%this. % === %>
-
-ModMemberNotEquals(n,m,v) ::= <%this. % != %>
-
-DumpDFA() ::= "this.dumpDFA();"
-
-Pass() ::= ""
-
-StringList() ::= "list"
-
-BuildParseTrees() ::= "this.buildParseTrees = true;"
-
-BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
-
-ToStringTree(s) ::= <%.toStringTree(null, this)%>
-
-Column() ::= "this.column"
-
-Text() ::= "this.text"
-
-ValEquals(a,b) ::= <%===%>
-
-TextEquals(a) ::= <%this.text===""%>
-
-PlusText(a) ::= <%"" + this.text%>
-
-InputText() ::= "this._input.getText()"
-
-LTEquals(i, v) ::= <%this._input.LT().text===%>
-
-LANotEquals(i, v) ::= <%this._input.LA()!=%>
-
-TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===%>
-
-ImportListener(X) ::= ""
-
-GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
-
-RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
-
-LL_EXACT_AMBIG_DETECTION() ::= <>
-
-ParserToken(parser, token) ::= <%.%>
-
-Production(p) ::= <%