diff --git a/.editorconfig b/.editorconfig
index 53b65e9f3..daa6da0fb 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,5 +1,8 @@
root = true
+[*]
+tab_width = 4
+
[*.{java,stg}]
charset = utf-8
insert_final_newline = true
diff --git a/.travis.yml b/.travis.yml
index d27ee56b3..d9969b6eb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,30 +2,26 @@ sudo: true
language: java
+cache:
+ directories:
+ - $HOME/.m2
+ - $HOME/Library/Caches/Homebrew
+
+stages:
+ - smoke-test
+ - main-test
+ - extended-test
+
matrix:
include:
- os: linux
compiler: clang
- jdk: oraclejdk7
+ jdk: openjdk7
env:
- TARGET=cpp
- CXX=g++-5
- - GROUP=ALL
- addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- - llvm-toolchain-precise-3.7
- packages:
- - g++-5
- - uuid-dev
- - clang-3.7
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=cpp
- GROUP=LEXER
+ stage: main-test
addons:
apt:
sources:
@@ -35,106 +31,150 @@ matrix:
- g++-5
- uuid-dev
- clang-3.7
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=cpp
- - GROUP=PARSER
- addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- - llvm-toolchain-precise-3.7
- packages:
- - g++-5
- - uuid-dev
- - clang-3.7
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=cpp
- - GROUP=RECURSION
- addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- - llvm-toolchain-precise-3.7
- packages:
- - g++-5
- - uuid-dev
- - clang-3.7
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=swift
- - GROUP=LEXER
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=swift
- - GROUP=PARSER
- - os: osx
- compiler: clang
- osx_image: xcode8.1
- env:
- - TARGET=swift
- - GROUP=RECURSION
- os: linux
+ compiler: clang
+ jdk: openjdk7
+ env:
+ - TARGET=cpp
+ - CXX=g++-5
+ - GROUP=PARSER
+ stage: main-test
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-precise-3.7
+ packages:
+ - g++-5
+ - uuid-dev
+ - clang-3.7
+ - os: linux
+ compiler: clang
+ jdk: openjdk7
+ env:
+ - TARGET=cpp
+ - CXX=g++-5
+ - GROUP=RECURSION
+ stage: main-test
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-precise-3.7
+ packages:
+ - g++-5
+ - uuid-dev
+ - clang-3.7
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=cpp
+ - GROUP=LEXER
+ stage: extended-test
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=cpp
+ - GROUP=PARSER
+ stage: extended-test
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=cpp
+ - GROUP=RECURSION
+ stage: extended-test
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=swift
+ - GROUP=LEXER
+ stage: main-test
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=swift
+ - GROUP=PARSER
+ stage: main-test
+ - os: osx
+ compiler: clang
+ osx_image: xcode9
+ env:
+ - TARGET=swift
+ - GROUP=RECURSION
+ stage: main-test
+ - os: linux
+ dist: trusty
compiler: clang
env:
- TARGET=swift
- GROUP=ALL
+ stage: extended-test
- os: osx
- osx_image: xcode8.2
+ osx_image: xcode9
env:
- TARGET=dotnet
- GROUP=LEXER
+ stage: extended-test
- os: osx
- osx_image: xcode8.2
+ osx_image: xcode9
env:
- TARGET=dotnet
- GROUP=PARSER
+ stage: extended-test
- os: osx
- osx_image: xcode8.2
+ osx_image: xcode9
env:
- TARGET=dotnet
- GROUP=RECURSION
+ stage: extended-test
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=java
+ stage: extended-test
+ - os: linux
+ jdk: openjdk8
+ env: TARGET=java
+ stage: extended-test
- os: linux
jdk: oraclejdk8
env: TARGET=java
+ stage: smoke-test
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=csharp
+ stage: extended-test
- os: linux
jdk: oraclejdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=LEXER
+ stage: main-test
- os: linux
- jdk: oraclejdk8
+ jdk: openjdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=PARSER
+ stage: main-test
- os: linux
jdk: oraclejdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=RECURSION
+ stage: main-test
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=python2
+ stage: extended-test
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=python3
addons:
apt:
@@ -142,16 +182,20 @@ matrix:
- deadsnakes # source required so it finds the package definition below
packages:
- python3.5
+ stage: main-test
- os: linux
- jdk: oraclejdk7
+ dist: trusty
+ jdk: openjdk8
env: TARGET=javascript
+ stage: main-test
- os: linux
- jdk: oraclejdk7
+ dist: trusty
+ jdk: openjdk8
env: TARGET=go
+ stage: main-test
before_install:
- - ./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh
+ - f="./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh"; ! [ -x "$f" ] || "$f"
script:
- - cd runtime-testsuite; ../.travis/run-tests-$TARGET.sh
-
+ - cd runtime-testsuite; travis_wait 40 ../.travis/run-tests-$TARGET.sh
diff --git a/.travis/before-install-linux-swift.sh b/.travis/before-install-linux-swift.sh
index 607f04449..1a2b2a555 100755
--- a/.travis/before-install-linux-swift.sh
+++ b/.travis/before-install-linux-swift.sh
@@ -1,14 +1,12 @@
set -euo pipefail
-# make sure we use trusty repositories (travis by default uses precise)
-curl https://repogen.simplylinux.ch/txt/trusty/sources_c4aa56bd26c0f54f391d8fae3e687ef5f6e97c26.txt | sudo tee /etc/apt/sources.list
-
# install dependencies
# some packages below will be update, swift assumes newer versions
# of, for example, sqlite3 and libicu, without the update some
# tools will not work
sudo apt-get update
-sudo apt-get install clang libicu-dev libxml2 sqlite3
+sudo apt-get install clang-3.6 libxml2
+sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
# This would fix a know linker issue mentioned in:
# https://bugs.swift.org/browse/SR-2299
diff --git a/.travis/before-install-osx-cpp.sh b/.travis/before-install-osx-cpp.sh
deleted file mode 100755
index 48152d221..000000000
--- a/.travis/before-install-osx-cpp.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-thisdir=$(dirname "$0")
-
-brew update
-brew install cmake
-
-# Work around apparent rvm bug that is in Travis's Xcode image.
-# https://github.com/direnv/direnv/issues/210
-# https://github.com/travis-ci/travis-ci/issues/6307
-shell_session_update() { :; }
diff --git a/.travis/before-install-osx-dotnet.sh b/.travis/before-install-osx-dotnet.sh
index 428016fa6..c784ba091 100755
--- a/.travis/before-install-osx-dotnet.sh
+++ b/.travis/before-install-osx-dotnet.sh
@@ -4,9 +4,7 @@ set -euo pipefail
thisdir=$(dirname "$0")
-# pre-requisites for dotnet core
-brew update
-brew install openssl
+# OpenSSL setup for dotnet core
mkdir -p /usr/local/lib
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
@@ -19,9 +17,3 @@ sudo installer -pkg /tmp/dotnet-dev-osx-x64.1.0.4.pkg -target /
# make the link
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
-
-# Work around apparent rvm bug that is in Travis's Xcode image.
-# https://github.com/direnv/direnv/issues/210
-# https://github.com/travis-ci/travis-ci/issues/6307
-shell_session_update() { :; }
-
diff --git a/.travis/before-install-osx-swift.sh b/.travis/before-install-osx-swift.sh
deleted file mode 100755
index 145a505c6..000000000
--- a/.travis/before-install-osx-swift.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-set -euo pipefail
-
-thisdir=$(dirname "$0")
-
-brew update
-
-# Work around apparent rvm bug that is in Travis's Xcode image.
-# https://github.com/direnv/direnv/issues/210
-# https://github.com/travis-ci/travis-ci/issues/6307
-shell_session_update() { :; }
diff --git a/.travis/run-tests-swift.sh b/.travis/run-tests-swift.sh
index 56d2cec65..8c63070aa 100755
--- a/.travis/run-tests-swift.sh
+++ b/.travis/run-tests-swift.sh
@@ -4,7 +4,7 @@
# here since environment variables doesn't pass
# across scripts
if [ $TRAVIS_OS_NAME == "linux" ]; then
- export SWIFT_VERSION=swift-3.1.1
+ export SWIFT_VERSION=swift-4.0
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu14.04/usr/bin/
export PATH=$SWIFT_HOME:$PATH
diff --git a/appveyor.yml b/appveyor.yml
index 57184557b..61ef31a41 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-version: '4.6-SNAPSHOT+AppVeyor.{build}'
+version: '4.7.1-SNAPSHOT+AppVeyor.{build}'
os: Windows Server 2012
build_script:
- mvn -DskipTests install -q --batch-mode
diff --git a/contributors.txt b/contributors.txt
index 841afcab0..df1350fef 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -151,7 +151,19 @@ YYYY/MM/DD, github id, Full name, email
2017/06/11, erikbra, Erik A. Brandstadmoen, erik@brandstadmoen.net
2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, janm@transactionware.com
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
+2017/06/28, jBugman, Sergey Parshukov, codedby@bugman.me
+2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
+2017/07/17, vaibhavaingankar09, Vaibhav Vaingankar, vbhvvaingankar9@gmail.com
+2017/07/23, venkatperi, Venkat Peri, venkatperi@gmail.com
2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
+2017/07/27, matthauck, Matt Hauck, matthauck@gmail.com
+2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
+2017/08/20, tiagomazzutti, Tiago Mazzutti, tiagomzt@gmail.com
2017/08/20, milanaleksic, Milan Aleksic, milanaleksic@gmail.com
+2017/08/29, Eddy Reyes, eddy@mindsight.io
+2017/09/09, brauliobz, Bráulio Bezerra, brauliobezerra@gmail.com
+2017/09/11, sachinjain024, Sachin Jain, sachinjain024@gmail.com
+2017/10/06, bramp, Andrew Brampton, brampton@gmail.com
+2017/10/15, simkimsia, Sim Kim Sia, kimcity@gmail.com
\ No newline at end of file
diff --git a/doc/getting-started.md b/doc/getting-started.md
index eaf2141fb..30acdb65a 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.5.3-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.7-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.
@@ -16,16 +16,18 @@ If you are going to integrate ANTLR into your existing build system using mvn, a
1. Download
```
$ cd /usr/local/lib
-$ curl -O http://www.antlr.org/download/antlr-4.5.3-complete.jar
+$ curl -O http://www.antlr.org/download/antlr-4.7-complete.jar
```
Or just download in browser from website:
[http://www.antlr.org/download.html](http://www.antlr.org/download.html)
and put it somewhere rational like `/usr/local/lib`.
+
2. Add `antlr-4.5.3-complete.jar` to your `CLASSPATH`:
```
$ export CLASSPATH=".:/usr/local/lib/antlr-4.5.3-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.5.3-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
@@ -39,11 +41,11 @@ $ alias grun='java org.antlr.v4.gui.TestRig'
0. Install Java (version 1.6 or higher)
1. Download antlr-4.5.3-complete.jar (or whatever version) from [http://www.antlr.org/download/](http://www.antlr.org/download/)
Save to your directory for 3rd party Java libraries, say `C:\Javalib`
-2. Add `antlr-4.5-complete.jar` to CLASSPATH, either:
+2. Add `antlr-4.5.3-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.5.3-complete.jar;%CLASSPATH%
+SET CLASSPATH=.;C:\Javalib\antlr-4.7-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
@@ -65,7 +67,7 @@ Either launch org.antlr.v4.Tool directly:
```
$ java org.antlr.v4.Tool
-ANTLR Parser Generator Version 4.5.3
+ANTLR Parser Generator Version 4.7
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
@@ -74,8 +76,8 @@ ANTLR Parser Generator Version 4.5.3
or use -jar option on java:
```
-$ java -jar /usr/local/lib/antlr-4.5.3-complete.jar
-ANTLR Parser Generator Version 4.5.3
+$ java -jar /usr/local/lib/antlr-4.7-complete.jar
+ANTLR Parser Generator Version 4.7
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
diff --git a/doc/images/gen_spm_module.png b/doc/images/gen_spm_module.png
new file mode 100644
index 000000000..0798c37b6
Binary files /dev/null and b/doc/images/gen_spm_module.png differ
diff --git a/doc/swift-target.md b/doc/swift-target.md
index 09dd17de3..4f4e6e7c1 100644
--- a/doc/swift-target.md
+++ b/doc/swift-target.md
@@ -6,7 +6,6 @@ To use ANTLR4 Swift target in production environment, make sure to turn on compi
Conclusion is, you need to turn on `release` mode (which will have all the optimization pre configured for you) so the ANTLR4 Swift target can have reasonable parsing speed.
-
## Install ANTLR4
Make sure you have the ANTLR
@@ -25,58 +24,120 @@ For a full list of antlr4 tool options, please visit the
## Build your Swift project with ANTLR runtime
-The following instructions are assuming Xcode as the IDE:
+### Note
-* __Add parser/lexer to project__. Make sure the parsers/lexers
+We use __boot.py__ script located at the root of the Swift runtime folder
+`antlr4/runtime/Swift` to provide additional support for both Xcode-based
+projects and SPM-based projects. Below sections are organized for both of
+the flavors. If you want to quickly get started, try:
+
+```
+python boot.py --help
+```
+
+for information about this script.
+
+### Xcode Projects
+
+Note that even if you are otherwise using ANTLR from a binary distribution,
+you should compile the ANTLR Swift runtime from source, because the Swift
+language does not yet have a stable ABI.
+
+ANTLR uses Swift Package Manager to generate Xcode project files. Note that
+Swift Package Manager does not currently support iOS, watchOS, or tvOS, so
+if you wish to use those platforms, you will need to alter the project build
+settings manually as appropriate.
+
+#### Download source code for ANTLR
+
+```
+git clone https://github.com/antlr/antlr4
+```
+
+#### Generate Xcode project for ANTLR runtime
+
+The `boot.py` script includes a wrapper around `swift package
+generate-xcodeproj`. Use this to generate `Antlr4.xcodeproj` for the ANTLR
+Swift runtime. (using _swift package generate-xcodeproj_ is not recommended)
+since the project is dependent on some parser files generated by _boot.py_.
+
+```
+cd antlr4/runtime/Swift
+python boot.py --gen-xcodeproj
+```
+
+#### Import ANTLR Swift runtime into your project
+
+Open your own project in Xcode.
+
+Open Finder in the `runtime/Swift` directory:
+
+```
+# From antlr4/runtime/Swift
+open .
+```
+
+Drag `Antlr4.xcodeproj` into your project.
+
+After this is done, your Xcode project navigator will be something like the
+screenshot below. In this example, your own project is "Smalltalk", and you
+will be able to see `Antlr4.xcodeproj` shown as a contained project.
+
+
+
+#### Edit the build settings if necessary
+
+Swift Package Manager currently does not support iOS, watchOS, or tvOS. If
+you wish to build for those platforms, you will need to alter the project
+build settings manually.
+
+#### Add generated parser and lexer to project
+
+Make sure the parsers/lexers
generated in __step 2__ are added to the project. To do this, you can
drag the generated files from Finder to the Xcode IDE. Remember to
check __Copy items if needed__ to make sure the files are actually
moved into the project folder instead of symbolic links (see the
screenshot below). After moving you will be able to see your files in
-the project navigator. But when you open one of the files, you will
-see Xcode complaining the module "Antlr4" could not be found at the
-import statement. This is expected, since we still need the ANTLR
-Swift runtime for those missing symbols.
+the project navigator. Make sure that the Target Membership settings
+are correct for your project.
-* __Download ANTLR runtime__. Due to unstable ABI of Swift language,
-there will not be a single "library" for the Swift ANTLR runtime for
-now. To get Swift ANTLR runtime, clone the ANTLR repository. Open it
-in finder. From the root directory of the repo, go to runtime/Swift
-folder. You will see the Xcode project manifest file:
-__Antlr4.xcodeproj__.
+#### Add the ANTLR Swift runtime as a dependency
-* __Import ANTLR Swift runtime into project__. Drag Antlr4.xcodeproj
-into your project, after this is done, your Xcode project navigator
-will be something like the screenshot below. In this case, your own
-project is "Smalltalk", and you will be able to see the
-Antlr4.xcodeproj shown as a contained project. The error message will
-still be there, that's because we still need to tell Xcode how to find
-the runtime.
+Select your own project in Xcode and go to the Build Phases settings panel.
+Add the ANTLR runtime under __Target Dependencies__ and __Link Binary With
+Libraries__.
-
+
-* __Build ANTLR runtime__. By expanding the "Products" folder in the
-inner project (Antlr4.xcodeproj), you will see two Antlr4.framework
-files. ".framework" file is the swift version of ".jar", ".a" as in
-JAVA, C/C++ Initially those two files should be red, that's because
-they are not built. To build, click the "target selection" button
-right next to your Xcode run button. And in the drop down select the
-target you want to build. And you will see the two Antlr4.framework
-files are for iOS and OSX, as shown below. After target selection,
-press "CMD+B", and Xcode will build the framework for you. Then you
-will see one of the frameworks become black.
+#### Build your project
-
+The runtime and generated grammar should now build correctly.
-* __Add dependencies__. Simply adding ANTLR Swift runtime and build
-the artifact is not enough. You still need to specify
-dependencies. Click your own project (Smalltalk), and you will see
-project setting page. Go to "Build Phase", and inside it make sure
-your ANTLR Swift runtime framework is added to both "__Target
-Dependencies__" and "__Link Binary With Libraries__" sections, as
-shown below. After correctly added dependencies, the error message for
-importing library will be gone.
+### Swift Package Manager Projects
-
\ No newline at end of file
+Since we cannot have a separate repository for Swift target (see issue [#1774](https://github.com/antlr/antlr4/issues/1774)),
+and Swift is currently not ABI stable. We currently support support SPM-based
+projects by creating temporary local repository.
+
+For people using [Swift Package Manager](https://swift.org/package-manager/),
+the __boot.py__ script supports generating local repository that can be used
+as a dependency to your project. Simply run:
+
+```
+python boot.py --gen-spm-module
+```
+
+The prompt will show something like below:
+
+
+
+Put the SPM directive that contains the url to temporary repository to your
+project's Package.swift. And run `swift build` in your project.
+
+The project is generated in your system's `/tmp/` directory, if you find it
+inconvenient, consider copy that generated ANTLR repository to some place
+that won't be cleaned automatically and update `url` parameter in your
+`Package.swift` file.
diff --git a/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java b/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
index 25c4c0919..c40c4048c 100644
--- a/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
+++ b/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
@@ -23,6 +23,7 @@ public class TestCodePointCharStream {
CodePointCharStream s = CharStreams.fromString("");
assertEquals(0, s.size());
assertEquals(0, s.index());
+ assertEquals("", s.toString());
}
@Test
diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java
index f6b890931..90dc05245 100644
--- a/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java
+++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java
@@ -145,7 +145,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
String projectName = "testcase-" + System.currentTimeMillis();
String projectDir = getTmpDir() + "/" + projectName;
- buildProject(projectDir);
+ buildProject(projectDir, projectName);
return execTest(projectDir, projectName);
}
@@ -183,12 +183,12 @@ public class BaseSwiftTest implements RuntimeTestSupport {
Collections.addAll(this.sourceFiles, files);
}
- private void buildProject(String projectDir) {
+ private void buildProject(String projectDir, String projectName) {
mkdir(projectDir);
fastFailRunProcess(projectDir, SWIFT_CMD, "package", "init", "--type", "executable");
for (String sourceFile: sourceFiles) {
String absPath = getTmpDir() + "/" + sourceFile;
- fastFailRunProcess(getTmpDir(), "mv", "-f", absPath, projectDir + "/Sources/");
+ fastFailRunProcess(getTmpDir(), "mv", "-f", absPath, projectDir + "/Sources/" + projectName);
}
fastFailRunProcess(getTmpDir(), "mv", "-f", "input", projectDir);
@@ -201,7 +201,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
"-Xlinker", "-rpath",
"-Xlinker", dylibPath);
if (buildResult.b.length() > 0) {
- throw new RuntimeException("unit test build failed: " + buildResult.b);
+ throw new RuntimeException("unit test build failed: " + buildResult.a + "\n" + buildResult.b);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
@@ -251,7 +251,7 @@ public class BaseSwiftTest implements RuntimeTestSupport {
addSourceFiles("main.swift");
String projectName = "testcase-" + System.currentTimeMillis();
String projectDir = getTmpDir() + "/" + projectName;
- buildProject(projectDir);
+ buildProject(projectDir, projectName);
return execTest(projectDir, projectName);
}
diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
index 9009b9f43..3ce2e87d2 100644
--- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
+++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
@@ -1092,7 +1092,10 @@ nextTransition_continue: ;
protected internal Guid ReadUUID()
{
byte[] d = BitConverter.GetBytes (ReadLong ());
- Array.Reverse(d);
+ if(BitConverter.IsLittleEndian)
+ {
+ Array.Reverse(d);
+ }
short c = (short)ReadInt();
short b = (short)ReadInt();
int a = ReadInt32();
diff --git a/runtime/Cpp/CMakeLists.txt b/runtime/Cpp/CMakeLists.txt
index 65e704516..c91e38e38 100644
--- a/runtime/Cpp/CMakeLists.txt
+++ b/runtime/Cpp/CMakeLists.txt
@@ -33,6 +33,7 @@ endif()
if(CMAKE_VERSION VERSION_EQUAL "3.3.0" OR
CMAKE_VERSION VERSION_GREATER "3.3.0")
CMAKE_POLICY(SET CMP0059 OLD)
+ CMAKE_POLICY(SET CMP0054 OLD)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
@@ -61,7 +62,11 @@ if (WITH_DEMO)
endif()
endif(WITH_DEMO)
-set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
+if (MSVC_VERSION)
+ set(MY_CXX_WARNING_FLAGS " /W4")
+else()
+ set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
+endif()
# Initialize CXXFLAGS.
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
@@ -75,11 +80,18 @@ else()
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=c++11")
endif()
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${MY_CXX_WARNING_FLAGS}")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${MY_CXX_WARNING_FLAGS}")
-set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${MY_CXX_WARNING_FLGAS}")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g ${MY_CXX_WARNING_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_WARNING_FLAGS}")
+if (MSVC_VERSION)
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /Zi /MP ${MY_CXX_WARNING_FLAGS}")
+ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /O1 /Oi /Ob2 /Gy /MP /DNDEBUG ${MY_CXX_WARNING_FLAGS}")
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Oi /Ob2 /Gy /MP /DNDEBUG ${MY_CXX_WARNING_FLGAS}")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /Oi /Ob2 /Gy /MP /Zi ${MY_CXX_WARNING_FLAGS}")
+else()
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${MY_CXX_WARNING_FLAGS}")
+ set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${MY_CXX_WARNING_FLGAS}")
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g ${MY_CXX_WARNING_FLAGS}")
+endif()
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
@@ -101,6 +113,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_SYSTEM_NAME MATCHES
if (WITH_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
+elseif ( MSVC_VERSION GREATER 1800 OR MSVC_VERSION EQUAL 1800 )
+ # Visual Studio 2012+ supports c++11 features
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()
diff --git a/runtime/Cpp/runtime/CMakeLists.txt b/runtime/Cpp/runtime/CMakeLists.txt
index b2a4fbd02..dcd21b8b0 100644
--- a/runtime/Cpp/runtime/CMakeLists.txt
+++ b/runtime/Cpp/runtime/CMakeLists.txt
@@ -44,7 +44,11 @@ elseif(APPLE)
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
endif()
-set(disabled_compile_warnings "-Wno-overloaded-virtual")
+if (MSVC_VERSION)
+ set(disabled_compile_warnings "/wd4251")
+else()
+ set(disabled_compile_warnings "-Wno-overloaded-virtual")
+endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(disabled_compile_warnings "${disabled_compile_warnings} -Wno-dollar-in-identifier-extension -Wno-four-char-constants")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
@@ -57,6 +61,15 @@ if (WIN32)
set(extra_share_compile_flags "-DANTLR4CPP_EXPORTS")
set(extra_static_compile_flags "-DANTLR4CPP_STATIC")
endif(WIN32)
+if (MSVC_VERSION)
+ target_compile_options(antlr4_shared PRIVATE "/MD$<$:d>")
+ target_compile_options(antlr4_static PRIVATE "/MT$<$:d>")
+endif()
+
+set(static_lib_suffix "")
+if (MSVC_VERSION)
+ set(static_lib_suffix "-static")
+endif()
set_target_properties(antlr4_shared
PROPERTIES VERSION ${ANTLR_VERSION}
@@ -72,7 +85,7 @@ set_target_properties(antlr4_shared
set_target_properties(antlr4_static
PROPERTIES VERSION ${ANTLR_VERSION}
SOVERSION ${ANTLR_VERSION}
- OUTPUT_NAME antlr4-runtime
+ OUTPUT_NAME "antlr4-runtime${static_lib_suffix}"
ARCHIVE_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
COMPILE_FLAGS "${disabled_compile_warnings} ${extra_static_compile_flags}")
diff --git a/runtime/Cpp/runtime/src/atn/PredictionMode.h b/runtime/Cpp/runtime/src/atn/PredictionMode.h
index d3de2e952..726f4cf40 100755
--- a/runtime/Cpp/runtime/src/atn/PredictionMode.h
+++ b/runtime/Cpp/runtime/src/atn/PredictionMode.h
@@ -15,7 +15,7 @@ namespace atn {
* utility methods for analyzing configuration sets for conflicts and/or
* ambiguities.
*/
- enum class ANTLR4CPP_PUBLIC PredictionMode {
+ enum class PredictionMode {
/**
* The SLL(*) prediction mode. This prediction mode ignores the current
* parser context when making predictions. This is the fastest prediction
diff --git a/runtime/Go/antlr/common_token_stream_test.go b/runtime/Go/antlr/common_token_stream_test.go
new file mode 100644
index 000000000..27cf42111
--- /dev/null
+++ b/runtime/Go/antlr/common_token_stream_test.go
@@ -0,0 +1,154 @@
+// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+// Use of this file is governed by the BSD 3-clause license that
+// can be found in the LICENSE.txt file in the project root.
+
+package antlr
+
+import (
+ "testing"
+)
+
+type commonTokenStreamTestLexer struct {
+ *BaseLexer
+
+ tokens []Token
+ i int
+}
+
+func (l *commonTokenStreamTestLexer) NextToken() Token {
+ tmp := l.tokens[l.i]
+ l.i++
+ return tmp
+}
+
+func TestCommonTokenStreamOffChannel(t *testing.T) {
+ assert := assertNew(t)
+ lexEngine := &commonTokenStreamTestLexer{
+ tokens: []Token{
+ newTestCommonToken(1, " ", LexerHidden), // 0
+ newTestCommonToken(1, "x", LexerDefaultTokenChannel), // 1
+ newTestCommonToken(1, " ", LexerHidden), // 2
+ newTestCommonToken(1, "=", LexerDefaultTokenChannel), // 3
+ newTestCommonToken(1, "34", LexerDefaultTokenChannel), // 4
+ newTestCommonToken(1, " ", LexerHidden), // 5
+ newTestCommonToken(1, " ", LexerHidden), // 6
+ newTestCommonToken(1, ";", LexerDefaultTokenChannel), // 7
+ newTestCommonToken(1, "\n", LexerHidden), // 9
+ newTestCommonToken(TokenEOF, "", LexerDefaultTokenChannel), // 10
+ },
+ }
+ tokens := NewCommonTokenStream(lexEngine, TokenDefaultChannel)
+
+ assert.Equal("x", tokens.LT(1).GetText()) // must skip first off channel token
+ tokens.Consume()
+ assert.Equal("=", tokens.LT(1).GetText())
+ assert.Equal("x", tokens.LT(-1).GetText())
+
+ tokens.Consume()
+ assert.Equal("34", tokens.LT(1).GetText())
+ assert.Equal("=", tokens.LT(-1).GetText())
+
+ tokens.Consume()
+ assert.Equal(";", tokens.LT(1).GetText())
+ assert.Equal("34", tokens.LT(-1).GetText())
+
+ tokens.Consume()
+ assert.Equal(TokenEOF, tokens.LT(1).GetTokenType())
+ assert.Equal(";", tokens.LT(-1).GetText())
+
+ assert.Equal("34", tokens.LT(-2).GetText())
+ assert.Equal("=", tokens.LT(-3).GetText())
+ assert.Equal("x", tokens.LT(-4).GetText())
+}
+
+func TestCommonTokenStreamFetchOffChannel(t *testing.T) {
+ assert := assertNew(t)
+ lexEngine := &commonTokenStreamTestLexer{
+ tokens: []Token{
+ newTestCommonToken(1, " ", LexerHidden), // 0
+ newTestCommonToken(1, "x", LexerDefaultTokenChannel), // 1
+ newTestCommonToken(1, " ", LexerHidden), // 2
+ newTestCommonToken(1, "=", LexerDefaultTokenChannel), // 3
+ newTestCommonToken(1, "34", LexerDefaultTokenChannel), // 4
+ newTestCommonToken(1, " ", LexerHidden), // 5
+ newTestCommonToken(1, " ", LexerHidden), // 6
+ newTestCommonToken(1, ";", LexerDefaultTokenChannel), // 7
+ newTestCommonToken(1, " ", LexerHidden), // 8
+ newTestCommonToken(1, "\n", LexerHidden), // 9
+ newTestCommonToken(TokenEOF, "", LexerDefaultTokenChannel), // 10
+ },
+ }
+ tokens := NewCommonTokenStream(lexEngine, TokenDefaultChannel)
+ tokens.Fill()
+
+ assert.Nil(tokens.getHiddenTokensToLeft(0, -1))
+ assert.Nil(tokens.getHiddenTokensToRight(0, -1))
+
+ assert.Equal("[[@0,0:0=' ',<1>,channel=1,0:-1]]", tokensToString(tokens.getHiddenTokensToLeft(1, -1)))
+ assert.Equal("[[@2,0:0=' ',<1>,channel=1,0:-1]]", tokensToString(tokens.getHiddenTokensToRight(1, -1)))
+
+ assert.Nil(tokens.getHiddenTokensToLeft(2, -1))
+ assert.Nil(tokens.getHiddenTokensToRight(2, -1))
+
+ assert.Equal("[[@2,0:0=' ',<1>,channel=1,0:-1]]", tokensToString(tokens.getHiddenTokensToLeft(3, -1)))
+ assert.Nil(tokens.getHiddenTokensToRight(3, -1))
+
+ assert.Nil(tokens.getHiddenTokensToLeft(4, -1))
+ assert.Equal("[[@5,0:0=' ',<1>,channel=1,0:-1], [@6,0:0=' ',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToRight(4, -1)))
+
+ assert.Nil(tokens.getHiddenTokensToLeft(5, -1))
+ assert.Equal("[[@6,0:0=' ',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToRight(5, -1)))
+
+ assert.Equal("[[@5,0:0=' ',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToLeft(6, -1)))
+ assert.Nil(tokens.getHiddenTokensToRight(6, -1))
+
+ assert.Equal("[[@5,0:0=' ',<1>,channel=1,0:-1], [@6,0:0=' ',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToLeft(7, -1)))
+ assert.Equal("[[@8,0:0=' ',<1>,channel=1,0:-1], [@9,0:0='\\n',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToRight(7, -1)))
+
+ assert.Nil(tokens.getHiddenTokensToLeft(8, -1))
+ assert.Equal("[[@9,0:0='\\n',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToRight(8, -1)))
+
+ assert.Equal("[[@8,0:0=' ',<1>,channel=1,0:-1]]",
+ tokensToString(tokens.getHiddenTokensToLeft(9, -1)))
+ assert.Nil(tokens.getHiddenTokensToRight(9, -1))
+
+}
+
+type commonTokenStreamTestLexerSingleEOF struct {
+ *BaseLexer
+
+ tokens []Token
+ i int
+}
+
+func (l *commonTokenStreamTestLexerSingleEOF) NextToken() Token {
+ return newTestCommonToken(TokenEOF, "", LexerDefaultTokenChannel)
+}
+
+func TestCommonTokenStreamSingleEOF(t *testing.T) {
+ assert := assertNew(t)
+ lexEngine := &commonTokenStreamTestLexerSingleEOF{}
+ tokens := NewCommonTokenStream(lexEngine, TokenDefaultChannel)
+ tokens.Fill()
+
+ assert.Equal(TokenEOF, tokens.LA(1))
+ assert.Equal(0, tokens.index)
+ assert.Equal(1, tokens.Size())
+}
+
+func TestCommonTokenStreamCannotConsumeEOF(t *testing.T) {
+ assert := assertNew(t)
+ lexEngine := &commonTokenStreamTestLexerSingleEOF{}
+ tokens := NewCommonTokenStream(lexEngine, TokenDefaultChannel)
+ tokens.Fill()
+ assert.Equal(TokenEOF, tokens.LA(1))
+ assert.Equal(0, tokens.index)
+ assert.Equal(1, tokens.Size())
+ assert.Panics(tokens.Consume)
+}
diff --git a/runtime/Go/antlr/lexer.go b/runtime/Go/antlr/lexer.go
index ec0e27945..02deaf99c 100644
--- a/runtime/Go/antlr/lexer.go
+++ b/runtime/Go/antlr/lexer.go
@@ -21,11 +21,11 @@ type Lexer interface {
Emit() Token
- setChannel(int)
- pushMode(int)
- popMode() int
- setType(int)
- setMode(int)
+ SetChannel(int)
+ PushMode(int)
+ PopMode() int
+ SetType(int)
+ SetMode(int)
}
type BaseLexer struct {
@@ -150,7 +150,7 @@ func (b *BaseLexer) GetSourceName() string {
return b.GrammarFileName
}
-func (b *BaseLexer) setChannel(v int) {
+func (b *BaseLexer) SetChannel(v int) {
b.channel = v
}
@@ -250,11 +250,11 @@ func (b *BaseLexer) More() {
b.thetype = LexerMore
}
-func (b *BaseLexer) setMode(m int) {
+func (b *BaseLexer) SetMode(m int) {
b.mode = m
}
-func (b *BaseLexer) pushMode(m int) {
+func (b *BaseLexer) PushMode(m int) {
if LexerATNSimulatorDebug {
fmt.Println("pushMode " + strconv.Itoa(m))
}
@@ -262,7 +262,7 @@ func (b *BaseLexer) pushMode(m int) {
b.mode = m
}
-func (b *BaseLexer) popMode() int {
+func (b *BaseLexer) PopMode() int {
if len(b.modeStack) == 0 {
panic("Empty Stack")
}
@@ -331,7 +331,7 @@ func (b *BaseLexer) GetType() int {
return b.thetype
}
-func (b *BaseLexer) setType(t int) {
+func (b *BaseLexer) SetType(t int) {
b.thetype = t
}
@@ -361,7 +361,7 @@ func (b *BaseLexer) GetATN() *ATN {
// Return a list of all Token objects in input char stream.
// Forces load of all tokens. Does not include EOF token.
// /
-func (b *BaseLexer) getAllTokens() []Token {
+func (b *BaseLexer) GetAllTokens() []Token {
vl := b.Virt
tokens := make([]Token, 0)
t := vl.NextToken()
diff --git a/runtime/Go/antlr/lexer_action.go b/runtime/Go/antlr/lexer_action.go
index 3ca5e9ff3..20df84f94 100644
--- a/runtime/Go/antlr/lexer_action.go
+++ b/runtime/Go/antlr/lexer_action.go
@@ -101,7 +101,7 @@ func NewLexerTypeAction(thetype int) *LexerTypeAction {
}
func (l *LexerTypeAction) execute(lexer Lexer) {
- lexer.setType(l.thetype)
+ lexer.SetType(l.thetype)
}
func (l *LexerTypeAction) hash() int {
@@ -145,7 +145,7 @@ func NewLexerPushModeAction(mode int) *LexerPushModeAction {
// This action is implemented by calling {@link Lexer//pushMode} with the
// value provided by {@link //getMode}.
func (l *LexerPushModeAction) execute(lexer Lexer) {
- lexer.pushMode(l.mode)
+ lexer.PushMode(l.mode)
}
func (l *LexerPushModeAction) hash() int {
@@ -190,7 +190,7 @@ var LexerPopModeActionINSTANCE = NewLexerPopModeAction()
// This action is implemented by calling {@link Lexer//popMode}.
func (l *LexerPopModeAction) execute(lexer Lexer) {
- lexer.popMode()
+ lexer.PopMode()
}
func (l *LexerPopModeAction) String() string {
@@ -242,7 +242,7 @@ func NewLexerModeAction(mode int) *LexerModeAction {
// This action is implemented by calling {@link Lexer//mode} with the
// value provided by {@link //getMode}.
func (l *LexerModeAction) execute(lexer Lexer) {
- lexer.setMode(l.mode)
+ lexer.SetMode(l.mode)
}
func (l *LexerModeAction) hash() int {
@@ -341,7 +341,7 @@ func NewLexerChannelAction(channel int) *LexerChannelAction {
// This action is implemented by calling {@link Lexer//setChannel} with the
// value provided by {@link //getChannel}.
func (l *LexerChannelAction) execute(lexer Lexer) {
- lexer.setChannel(l.channel)
+ lexer.SetChannel(l.channel)
}
func (l *LexerChannelAction) hash() int {
diff --git a/runtime/Go/antlr/testing_assert_test.go b/runtime/Go/antlr/testing_assert_test.go
new file mode 100644
index 000000000..f3ca0d341
--- /dev/null
+++ b/runtime/Go/antlr/testing_assert_test.go
@@ -0,0 +1,98 @@
+// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+// Use of this file is governed by the BSD 3-clause license that
+// can be found in the LICENSE.txt file in the project root.
+
+// These assert functions are borrowed from https://github.com/stretchr/testify/ (MIT License)
+
+package antlr
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+type assert struct {
+ t *testing.T
+}
+
+func assertNew(t *testing.T) *assert {
+ return &assert{
+ t: t,
+ }
+}
+
+func (a *assert) Equal(expected, actual interface{}) bool {
+ if !objectsAreEqual(expected, actual) {
+ return a.Fail(fmt.Sprintf("Not equal:\n"+
+ "expected: %#v\n"+
+ " actual: %#v\n", expected, actual))
+ }
+ return true
+}
+
+func objectsAreEqual(expected, actual interface{}) bool {
+ if expected == nil || actual == nil {
+ return expected == actual
+ }
+ return reflect.DeepEqual(expected, actual)
+}
+
+func (a *assert) Nil(object interface{}) bool {
+ if isNil(object) {
+ return true
+ }
+ return a.Fail(fmt.Sprintf("Expected nil, but got: %#v", object))
+}
+
+func (a *assert) NotNil(object interface{}) bool {
+ if !isNil(object) {
+ return true
+ }
+ return a.Fail("Expected value not to be nil.")
+}
+
+// isNil checks if a specified object is nil or not, without Failing.
+func isNil(object interface{}) bool {
+ if object == nil {
+ return true
+ }
+
+ value := reflect.ValueOf(object)
+ kind := value.Kind()
+ if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
+ return true
+ }
+
+ return false
+}
+
+func (a *assert) Panics(f func()) bool {
+ if funcDidPanic, panicValue := didPanic(f); !funcDidPanic {
+ return a.Fail(fmt.Sprintf("func %#v should panic\n\r\tPanic value:\t%v", f, panicValue))
+ }
+
+ return true
+}
+
+// Fail reports a failure through
+func (a *assert) Fail(failureMessage string) bool {
+ a.t.Errorf("%s", failureMessage)
+ return false
+}
+
+// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
+func didPanic(f func()) (bool, interface{}) {
+ didPanic := false
+ var message interface{}
+ func() {
+ defer func() {
+ if message = recover(); message != nil {
+ didPanic = true
+ }
+ }()
+ // call the target function
+ f()
+ }()
+ return didPanic, message
+}
diff --git a/runtime/Go/antlr/testing_lexer_b_test.go b/runtime/Go/antlr/testing_lexer_b_test.go
new file mode 100644
index 000000000..4ab9b340d
--- /dev/null
+++ b/runtime/Go/antlr/testing_lexer_b_test.go
@@ -0,0 +1,107 @@
+// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+// Use of this file is governed by the BSD 3-clause license that
+// can be found in the LICENSE.txt file in the project root.
+
+package antlr
+
+/*
+LexerB is a lexer for testing purpose.
+
+This file is generated from this grammer.
+
+lexer grammar LexerB;
+
+ID : 'a'..'z'+;
+INT : '0'..'9'+;
+SEMI : ';';
+ASSIGN : '=';
+PLUS : '+';
+MULT : '*';
+WS : ' '+;
+*/
+
+var lexerB_serializedLexerAtn = []uint16{
+ 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 9, 40, 8,
+ 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9,
+ 7, 4, 8, 9, 8, 3, 2, 6, 2, 19, 10, 2, 13, 2, 14, 2, 20, 3, 3, 6, 3, 24,
+ 10, 3, 13, 3, 14, 3, 25, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7,
+ 3, 8, 6, 8, 37, 10, 8, 13, 8, 14, 8, 38, 2, 2, 9, 3, 3, 5, 4, 7, 5, 9,
+ 6, 11, 7, 13, 8, 15, 9, 3, 2, 2, 2, 42, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2,
+ 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2,
+ 2, 2, 2, 15, 3, 2, 2, 2, 3, 18, 3, 2, 2, 2, 5, 23, 3, 2, 2, 2, 7, 27, 3,
+ 2, 2, 2, 9, 29, 3, 2, 2, 2, 11, 31, 3, 2, 2, 2, 13, 33, 3, 2, 2, 2, 15,
+ 36, 3, 2, 2, 2, 17, 19, 4, 99, 124, 2, 18, 17, 3, 2, 2, 2, 19, 20, 3, 2,
+ 2, 2, 20, 18, 3, 2, 2, 2, 20, 21, 3, 2, 2, 2, 21, 4, 3, 2, 2, 2, 22, 24,
+ 4, 50, 59, 2, 23, 22, 3, 2, 2, 2, 24, 25, 3, 2, 2, 2, 25, 23, 3, 2, 2,
+ 2, 25, 26, 3, 2, 2, 2, 26, 6, 3, 2, 2, 2, 27, 28, 7, 61, 2, 2, 28, 8, 3,
+ 2, 2, 2, 29, 30, 7, 63, 2, 2, 30, 10, 3, 2, 2, 2, 31, 32, 7, 45, 2, 2,
+ 32, 12, 3, 2, 2, 2, 33, 34, 7, 44, 2, 2, 34, 14, 3, 2, 2, 2, 35, 37, 7,
+ 34, 2, 2, 36, 35, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 36, 3, 2, 2, 2, 38,
+ 39, 3, 2, 2, 2, 39, 16, 3, 2, 2, 2, 6, 2, 20, 25, 38, 2,
+}
+
+var lexerB_lexerDeserializer = NewATNDeserializer(nil)
+var lexerB_lexerAtn = lexerB_lexerDeserializer.DeserializeFromUInt16(lexerB_serializedLexerAtn)
+
+var lexerB_lexerChannelNames = []string{
+ "DEFAULT_TOKEN_CHANNEL", "HIDDEN",
+}
+
+var lexerB_lexerModeNames = []string{
+ "DEFAULT_MODE",
+}
+
+var lexerB_lexerLiteralNames = []string{
+ "", "", "", "';'", "'='", "'+'", "'*'",
+}
+
+var lexerB_lexerSymbolicNames = []string{
+ "", "ID", "INT", "SEMI", "ASSIGN", "PLUS", "MULT", "WS",
+}
+
+var lexerB_lexerRuleNames = []string{
+ "ID", "INT", "SEMI", "ASSIGN", "PLUS", "MULT", "WS",
+}
+
+type LexerB struct {
+ *BaseLexer
+ channelNames []string
+ modeNames []string
+ // TODO: EOF string
+}
+
+var lexerB_lexerDecisionToDFA = make([]*DFA, len(lexerB_lexerAtn.DecisionToState))
+
+func init() {
+ for index, ds := range lexerB_lexerAtn.DecisionToState {
+ lexerB_lexerDecisionToDFA[index] = NewDFA(ds, index)
+ }
+}
+
+func NewLexerB(input CharStream) *LexerB {
+ l := new(LexerB)
+
+ l.BaseLexer = NewBaseLexer(input)
+ l.Interpreter = NewLexerATNSimulator(l, lexerB_lexerAtn, lexerB_lexerDecisionToDFA, NewPredictionContextCache())
+
+ l.channelNames = lexerB_lexerChannelNames
+ l.modeNames = lexerB_lexerModeNames
+ l.RuleNames = lexerB_lexerRuleNames
+ l.LiteralNames = lexerB_lexerLiteralNames
+ l.SymbolicNames = lexerB_lexerSymbolicNames
+ l.GrammarFileName = "LexerB.g4"
+ // TODO: l.EOF = TokenEOF
+
+ return l
+}
+
+// LexerB tokens.
+const (
+ LexerBID = 1
+ LexerBINT = 2
+ LexerBSEMI = 3
+ LexerBASSIGN = 4
+ LexerBPLUS = 5
+ LexerBMULT = 6
+ LexerBWS = 7
+)
diff --git a/runtime/Go/antlr/testing_util_test.go b/runtime/Go/antlr/testing_util_test.go
new file mode 100644
index 000000000..20428831b
--- /dev/null
+++ b/runtime/Go/antlr/testing_util_test.go
@@ -0,0 +1,30 @@
+package antlr
+
+import (
+ "fmt"
+ "strings"
+)
+
+// newTestCommonToken create common token with tokentype, text and channel
+// notice: test purpose only
+func newTestCommonToken(tokenType int, text string, channel int) *CommonToken {
+ t := new(CommonToken)
+ t.BaseToken = new(BaseToken)
+ t.tokenType = tokenType
+ t.channel = channel
+ t.text = text
+ t.line = 0
+ t.column = -1
+ return t
+}
+
+// tokensToString returnes []Tokens string
+// notice: test purpose only
+func tokensToString(tokens []Token) string {
+ buf := make([]string, len(tokens))
+ for i, token := range tokens {
+ buf[i] = fmt.Sprintf("%v", token)
+ }
+
+ return "[" + strings.Join(buf, ", ") + "]"
+}
diff --git a/runtime/Java/pom.xml b/runtime/Java/pom.xml
index c42015629..3eb60b2df 100644
--- a/runtime/Java/pom.xml
+++ b/runtime/Java/pom.xml
@@ -27,6 +27,7 @@
org.apache.maven.plugins
maven-source-plugin
+ 3.0.1
diff --git a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
index 491ef6918..107faa7b1 100644
--- a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
+++ b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
@@ -151,8 +151,8 @@ public abstract class CodePointCharStream implements CharStream {
/** Return the UTF-16 encoded string for the given interval */
@Override
public String getText(Interval interval) {
- int startIdx = Math.min(interval.a, size - 1);
- int len = Math.min(interval.b - interval.a + 1, size);
+ int startIdx = Math.min(interval.a, size);
+ int len = Math.min(interval.b - interval.a + 1, size - startIdx);
// We know the maximum code point in byteArray is U+00FF,
// so we can treat this as if it were ISO-8859-1, aka Latin-1,
diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java
index 46840ab7c..d415cdfb2 100755
--- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java
+++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java
@@ -1541,11 +1541,6 @@ public class ParserATNSimulator extends ATNSimulator {
ATNConfig c = getEpsilonTarget(config, t, continueCollecting,
depth == 0, fullCtx, treatEofAsEpsilon);
if ( c!=null ) {
- if (!t.isEpsilon() && !closureBusy.add(c)) {
- // avoid infinite recursion for EOF* and EOF+
- continue;
- }
-
int newDepth = depth;
if ( config.state instanceof RuleStopState) {
assert !fullCtx;
@@ -1555,11 +1550,6 @@ public class ParserATNSimulator extends ATNSimulator {
// come in handy and we avoid evaluating context dependent
// preds if this is > 0.
- if (!closureBusy.add(c)) {
- // avoid infinite recursion for right-recursive rules
- continue;
- }
-
if (_dfa != null && _dfa.isPrecedenceDfa()) {
int outermostPrecedenceReturn = ((EpsilonTransition)t).outermostPrecedenceReturn();
if (outermostPrecedenceReturn == _dfa.atnStartState.ruleIndex) {
@@ -1568,15 +1558,28 @@ public class ParserATNSimulator extends ATNSimulator {
}
c.reachesIntoOuterContext++;
+
+ if (!closureBusy.add(c)) {
+ // avoid infinite recursion for right-recursive rules
+ continue;
+ }
+
configs.dipsIntoOuterContext = true; // TODO: can remove? only care when we add to set per middle of this method
assert newDepth > Integer.MIN_VALUE;
newDepth--;
if ( debug ) System.out.println("dips into outer ctx: "+c);
}
- else if (t instanceof RuleTransition) {
- // latch when newDepth goes negative - once we step out of the entry context we can't return
- if (newDepth >= 0) {
- newDepth++;
+ else {
+ if (!t.isEpsilon() && !closureBusy.add(c)) {
+ // avoid infinite recursion for EOF* and EOF+
+ continue;
+ }
+
+ if (t instanceof RuleTransition) {
+ // latch when newDepth goes negative - once we step out of the entry context we can't return
+ if (newDepth >= 0) {
+ newDepth++;
+ }
}
}
diff --git a/runtime/JavaScript/src/antlr4/Utils.js b/runtime/JavaScript/src/antlr4/Utils.js
index d7627be60..2cb939a66 100644
--- a/runtime/JavaScript/src/antlr4/Utils.js
+++ b/runtime/JavaScript/src/antlr4/Utils.js
@@ -401,11 +401,11 @@ DoubleDict.prototype.set = function (a, b, o) {
function escapeWhitespace(s, escapeSpaces) {
- s = s.replace("\t", "\\t");
- s = s.replace("\n", "\\n");
- s = s.replace("\r", "\\r");
+ s = s.replace(/\t/g, "\\t")
+ .replace(/\n/g, "\\n")
+ .replace(/\r/g, "\\r");
if (escapeSpaces) {
- s = s.replace(" ", "\u00B7");
+ s = s.replace(/ /g, "\u00B7");
}
return s;
}
@@ -443,4 +443,4 @@ exports.hashStuff = hashStuff;
exports.escapeWhitespace = escapeWhitespace;
exports.arrayToString = arrayToString;
exports.titleCase = titleCase;
-exports.equalArrays = equalArrays;
\ No newline at end of file
+exports.equalArrays = equalArrays;
diff --git a/runtime/Python2/src/antlr4/Parser.py b/runtime/Python2/src/antlr4/Parser.py
index d88f77918..69abe739b 100644
--- a/runtime/Python2/src/antlr4/Parser.py
+++ b/runtime/Python2/src/antlr4/Parser.py
@@ -218,6 +218,13 @@ class Parser (Recognizer):
self._ctx.exitRule(listener)
listener.exitEveryRule(self._ctx)
+ # Gets the number of syntax errors reported during parsing. This value is
+ # incremented each time {@link #notifyErrorListeners} is called.
+ #
+ # @see #notifyErrorListeners
+ #
+ def getNumberOfSyntaxErrors(self):
+ return self._syntaxErrors
def getTokenFactory(self):
return self._input.tokenSource._factory
diff --git a/runtime/Python2/src/antlr4/tree/RuleTagToken.py b/runtime/Python2/src/antlr4/tree/RuleTagToken.py
index 2043c1625..d63a3a53b 100644
--- a/runtime/Python2/src/antlr4/tree/RuleTagToken.py
+++ b/runtime/Python2/src/antlr4/tree/RuleTagToken.py
@@ -36,14 +36,13 @@ class RuleTagToken(Token):
self.tokenIndex = -1 # from 0..n-1 of the token object in the input stream
self.line = 0 # line=1..n of the 1st character
self.column = -1 # beginning of the line at which it occurs, 0..n-1
- self.label = label
+ self.label = unicode(label)
self._text = self.getText() # text of the token.
-
- self.ruleName = ruleName
+ self.ruleName = unicode(ruleName)
def getText(self):
if self.label is None:
- return "<" + self.ruleName + ">"
+ return u"<" + self.ruleName + u">"
else:
- return "<" + self.label + ":" + self.ruleName + ">"
+ return u"<" + self.label + ":" + self.ruleName + u">"
diff --git a/runtime/Python2/src/antlr4/tree/TokenTagToken.py b/runtime/Python2/src/antlr4/tree/TokenTagToken.py
index 2ffc79f6f..dba41f785 100644
--- a/runtime/Python2/src/antlr4/tree/TokenTagToken.py
+++ b/runtime/Python2/src/antlr4/tree/TokenTagToken.py
@@ -24,8 +24,8 @@ class TokenTagToken(CommonToken):
#
def __init__(self, tokenName, type, label=None):
super(TokenTagToken, self).__init__(type=type)
- self.tokenName = tokenName
- self.label = label
+ self.tokenName = unicode(tokenName)
+ self.label = unicode(label)
self._text = self.getText()
#
@@ -36,9 +36,9 @@ class TokenTagToken(CommonToken):
#
def getText(self):
if self.label is None:
- return "<" + self.tokenName + ">"
+ return u"<" + self.tokenName + u">"
else:
- return "<" + self.label + ":" + self.tokenName + ">"
+ return u"<" + self.label + u":" + self.tokenName + u">"
# The implementation for {@link TokenTagToken} returns a string of the form
# {@code tokenName:type}.
diff --git a/runtime/Python2/src/antlr4/tree/Tree.py b/runtime/Python2/src/antlr4/tree/Tree.py
index 26e959612..14b5f29ec 100644
--- a/runtime/Python2/src/antlr4/tree/Tree.py
+++ b/runtime/Python2/src/antlr4/tree/Tree.py
@@ -108,13 +108,13 @@ class TerminalNodeImpl(TerminalNode):
return visitor.visitTerminal(self)
def getText(self):
- return self.symbol.text
+ return unicode(self.symbol.text)
def __unicode__(self):
if self.symbol.type == Token.EOF:
- return ""
+ return u""
else:
- return self.symbol.text
+ return unicode(self.symbol.text)
# Represents a token that was consumed during resynchronization
# rather than during a valid match operation. For example,
diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py
index 03f10a438..c461bbdc0 100644
--- a/runtime/Python3/src/antlr4/Parser.py
+++ b/runtime/Python3/src/antlr4/Parser.py
@@ -227,6 +227,14 @@ class Parser (Recognizer):
listener.exitEveryRule(self._ctx)
+ # Gets the number of syntax errors reported during parsing. This value is
+ # incremented each time {@link #notifyErrorListeners} is called.
+ #
+ # @see #notifyErrorListeners
+ #
+ def getNumberOfSyntaxErrors(self):
+ return self._syntaxErrors
+
def getTokenFactory(self):
return self._input.tokenSource._factory
diff --git a/runtime/Python3/src/antlr4/__init__.py b/runtime/Python3/src/antlr4/__init__.py
index 4eac6c579..37c834202 100644
--- a/runtime/Python3/src/antlr4/__init__.py
+++ b/runtime/Python3/src/antlr4/__init__.py
@@ -12,7 +12,7 @@ from antlr4.atn.LexerATNSimulator import LexerATNSimulator
from antlr4.atn.ParserATNSimulator import ParserATNSimulator
from antlr4.atn.PredictionMode import PredictionMode
from antlr4.PredictionContext import PredictionContextCache
-from antlr4.ParserRuleContext import ParserRuleContext
+from antlr4.ParserRuleContext import RuleContext, ParserRuleContext
from antlr4.tree.Tree import ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, TerminalNode, ErrorNode, RuleNode
from antlr4.error.Errors import RecognitionException, IllegalStateException, NoViableAltException
from antlr4.error.ErrorStrategy import BailErrorStrategy
diff --git a/runtime/Swift/.gitignore b/runtime/Swift/.gitignore
index c54511205..e4a84b226 100644
--- a/runtime/Swift/.gitignore
+++ b/runtime/Swift/.gitignore
@@ -1 +1,4 @@
+.build/
+Antlr4.xcodeproj/
+Tests/Antlr4Tests/gen/
xcuserdata/
diff --git a/runtime/Swift/Package.swift b/runtime/Swift/Package.swift
index 5c2e28b12..0d72a47dd 100644
--- a/runtime/Swift/Package.swift
+++ b/runtime/Swift/Package.swift
@@ -1,3 +1,4 @@
+// swift-tools-version:4.0
// Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
// Use of this file is governed by the BSD 3-clause license that
// can be found in the LICENSE.txt file in the project root.
@@ -5,15 +6,19 @@
import PackageDescription
let package = Package(
- name: "Antlr4"
-)
-
-products.append(
- Product(
- name: "Antlr4",
- type: .Library(.Dynamic),
- modules: [
- "Antlr4"
- ]
- )
+ name: "Antlr4",
+ products: [
+ .library(
+ name: "Antlr4",
+ type: .dynamic,
+ targets: ["Antlr4"]),
+ ],
+ targets: [
+ .target(
+ name: "Antlr4",
+ dependencies: []),
+ .testTarget(
+ name: "Antlr4Tests",
+ dependencies: ["Antlr4"]),
+ ]
)
diff --git a/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift b/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
index c83ee58a3..56d1987f3 100644
--- a/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
@@ -39,12 +39,12 @@ public protocol ANTLRErrorListener: class {
/// the parser was able to recover in line without exiting the
/// surrounding rule.
///
- func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
)
///
diff --git a/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift b/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
index 75d3cad8c..9a9805b96 100644
--- a/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
@@ -17,12 +17,12 @@ open class BaseErrorListener: ANTLRErrorListener {
public init() {
}
- open func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ open func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
) {
}
diff --git a/runtime/Swift/Sources/Antlr4/CharStream.swift b/runtime/Swift/Sources/Antlr4/CharStream.swift
index 81fbf84d6..38e87e109 100644
--- a/runtime/Swift/Sources/Antlr4/CharStream.swift
+++ b/runtime/Swift/Sources/Antlr4/CharStream.swift
@@ -19,7 +19,6 @@ public protocol CharStream: IntStream {
/// - parameter interval: an interval within the stream
/// - returns: the text of the specified interval
///
- /// - throws: _ANTLRError.nullPointer_ if `interval` is `null`
/// - throws: _ANTLRError.illegalArgument_ if `interval.a < 0`, or if
/// `interval.b < interval.a - 1`, or if `interval.b` lies at or
/// past the end of the stream
diff --git a/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift b/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
index 22a76c5f4..de6584c30 100644
--- a/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
@@ -25,12 +25,12 @@ public class ConsoleErrorListener: BaseErrorListener {
/// line __line__:__charPositionInLine__ __msg__
///
///
- override public func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ override public func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
) {
if Parser.ConsoleError {
errPrint("line \(line):\(charPositionInLine) \(msg)")
diff --git a/runtime/Swift/Sources/Antlr4/Lexer.swift b/runtime/Swift/Sources/Antlr4/Lexer.swift
index a05150db4..a324d321b 100644
--- a/runtime/Swift/Sources/Antlr4/Lexer.swift
+++ b/runtime/Swift/Sources/Antlr4/Lexer.swift
@@ -405,7 +405,7 @@ open class Lexer: Recognizer
}
}
- open func notifyListeners(_ e: LexerNoViableAltException, recognizer: Recognizer) {
+ open func notifyListeners(_ e: LexerNoViableAltException, recognizer: Recognizer) {
let text: String = _input!.getText(Interval.of(_tokenStartCharIndex, _input!.index()))
let msg: String = "token recognition error at: '\(getErrorDisplay(text))'"
diff --git a/runtime/Swift/Sources/Antlr4/Parser.swift b/runtime/Swift/Sources/Antlr4/Parser.swift
index 6f7f30742..5a4c9257e 100644
--- a/runtime/Swift/Sources/Antlr4/Parser.swift
+++ b/runtime/Swift/Sources/Antlr4/Parser.swift
@@ -336,8 +336,6 @@ open class Parser: Recognizer {
///
/// - Parameter listener: the listener to add
///
- /// - Throws: _ANTLRError.nullPointer_ if listener is `null`
- ///
public func addParseListener(_ listener: ParseTreeListener) {
if _parseListeners == nil {
_parseListeners = Array()
diff --git a/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift b/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
index 481064ff5..5d1d7646c 100644
--- a/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
@@ -20,13 +20,13 @@ public class ProxyErrorListener: ANTLRErrorListener {
self.delegates = delegates
}
- public func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?)
- {
+ public func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?)
+ {
for listener: ANTLRErrorListener in delegates {
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e)
}
diff --git a/runtime/Swift/Sources/Antlr4/Recognizer.swift b/runtime/Swift/Sources/Antlr4/Recognizer.swift
index 9a3acad79..6133bbeea 100644
--- a/runtime/Swift/Sources/Antlr4/Recognizer.swift
+++ b/runtime/Swift/Sources/Antlr4/Recognizer.swift
@@ -228,9 +228,6 @@ open class Recognizer {
return "\(s)"
}
- ///
- /// - Throws: ANTLRError.nullPointer if `listener` is `null`.
- ///
open func addErrorListener(_ listener: ANTLRErrorListener) {
_listeners.append(listener)
diff --git a/runtime/Swift/Sources/Antlr4/RuleContext.swift b/runtime/Swift/Sources/Antlr4/RuleContext.swift
index 18dafd571..a05b43257 100644
--- a/runtime/Swift/Sources/Antlr4/RuleContext.swift
+++ b/runtime/Swift/Sources/Antlr4/RuleContext.swift
@@ -233,7 +233,7 @@ open class RuleContext: RuleNode {
return description
}
- public final func toString(_ recog: Recognizer) -> String {
+ public final func toString(_ recog: Recognizer) -> String {
return toString(recog, ParserRuleContext.EMPTY)
}
@@ -242,7 +242,7 @@ open class RuleContext: RuleNode {
}
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
- open func toString(_ recog: Recognizer?, _ stop: RuleContext) -> String {
+ open func toString(_ recog: Recognizer?, _ stop: RuleContext) -> String {
let ruleNames: [String]? = recog != nil ? recog!.getRuleNames() : nil
let ruleNamesList: Array? = ruleNames ?? nil
return toString(ruleNamesList, stop)
diff --git a/runtime/Swift/Sources/Antlr4/TokenStream.swift b/runtime/Swift/Sources/Antlr4/TokenStream.swift
index ef5834862..536f33b90 100644
--- a/runtime/Swift/Sources/Antlr4/TokenStream.swift
+++ b/runtime/Swift/Sources/Antlr4/TokenStream.swift
@@ -63,7 +63,6 @@ public protocol TokenStream: IntStream {
///
/// - Parameter interval: The interval of tokens within this stream to get text
/// for.
- /// - Throws: ANTLRError.nullPointer if `interval` is `null`
/// - Returns: The text of all tokens within the specified interval in this
/// stream.
///
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
index 1054ef342..75bff30e4 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
@@ -167,7 +167,7 @@ public class ATNConfig: Hashable, CustomStringConvertible {
//return "MyClass \(string)"
return toString(nil, true)
}
- public func toString(_ recog: Recognizer?, _ showAlt: Bool) -> String {
+ public func toString(_ recog: Recognizer?, _ showAlt: Bool) -> String {
let buf: StringBuilder = StringBuilder()
buf.append("(")
buf.append(state)
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
index 5cac3bffb..803d9c369 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
@@ -238,12 +238,9 @@ public class ATNConfigSet: Hashable, CustomStringConvertible {
private var configsHashValue: Int {
var hashCode = 1
for item in configs {
- hashCode = Int.multiplyWithOverflow(3, hashCode).0
- hashCode = Int.addWithOverflow(hashCode, item.hashValue).0
-
+ hashCode = hashCode &* 3 &+ item.hashValue
}
return hashCode
-
}
public final var count: Int {
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift b/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
index 5d3d25015..7bc3f63fc 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
@@ -175,7 +175,7 @@ public class ATNDeserializer {
if let s = s as? BlockStartState {
let endStateNumber: Int = toInt(data[p])
p += 1
- endStateNumbers.append(s, endStateNumber)
+ endStateNumbers.append((s, endStateNumber))
}
}
atn.addState(s)
diff --git a/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift b/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
index c603b06c6..783a1ab5b 100644
--- a/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
@@ -712,17 +712,17 @@ public class PredictionContext: Hashable, CustomStringConvertible {
}
}
- public func toString(_ recog: Recognizer) -> String {
+ public func toString(_ recog: Recognizer) -> String {
return NSStringFromClass(PredictionContext.self)
// return toString(recog, ParserRuleContext.EMPTY);
}
- public func toStrings(_ recognizer: Recognizer, _ currentState: Int) -> [String] {
+ public func toStrings(_ recognizer: Recognizer, _ currentState: Int) -> [String] {
return toStrings(recognizer, PredictionContext.EMPTY, currentState)
}
// FROM SAM
- public func toStrings(_ recognizer: Recognizer?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
+ public func toStrings(_ recognizer: Recognizer?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
var result: Array = Array()
var perm: Int = 0
outer: while true {
diff --git a/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift b/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
index 9e0c777b0..4ad0bd935 100644
--- a/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
@@ -37,7 +37,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
/// prediction, so we passed in the outer context here in case of context
/// dependent predicate evaluation.
///
- public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
+ public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
RuntimeException(#function + " must be overridden")
return false
}
@@ -58,7 +58,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
/// * A non-`null` _org.antlr.v4.runtime.atn.SemanticContext_: the new simplified
/// semantic context after precedence predicates are evaluated.
///
- public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
+ public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
return self
}
public var hashValue: Int {
@@ -90,7 +90,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
}
override
- public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
+ public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
let localctx: RuleContext? = isCtxDependent ? parserCallStack : nil
return try parser.sempred(localctx, ruleIndex, predIndex)
}
@@ -126,12 +126,12 @@ public class SemanticContext: Hashable, CustomStringConvertible {
}
override
- public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
+ public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
return try parser.precpred(parserCallStack, precedence)
}
override
- public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
+ public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
if try parser.precpred(parserCallStack, precedence) {
return SemanticContext.NONE
} else {
@@ -187,31 +187,28 @@ public class SemanticContext: Hashable, CustomStringConvertible {
public init(_ a: SemanticContext, _ b: SemanticContext) {
var operands: Set = Set()
- if a is AND {
- operands.formUnion((a as! AND).opnds)
- //operands.addAll(Arrays.asList((a as AND).opnds));
+ if let aAnd = a as? AND {
+ operands.formUnion(aAnd.opnds)
} else {
operands.insert(a)
}
- if b is AND {
- operands.formUnion((b as! AND).opnds)
- //operands.addAll(Arrays.asList((b as AND).opnds));
+ if let bAnd = b as? AND {
+ operands.formUnion(bAnd.opnds)
} else {
operands.insert(b)
}
- let precedencePredicates: Array =
- SemanticContext.filterPrecedencePredicates(&operands)
+ let precedencePredicates = SemanticContext.filterPrecedencePredicates(&operands)
if !precedencePredicates.isEmpty {
// interested in the transition with the lowest precedence
- let reduced: PrecedencePredicate = precedencePredicates.sorted {
+ let reduced = precedencePredicates.sorted {
$0.precedence < $1.precedence
- }.first! //Collections.min(precedencePredicates);
- operands.insert(reduced)
+ }
+ operands.insert(reduced[0])
}
- opnds = Array(operands) //.toArray(new, SemanticContext[operands.size()]);
+ opnds = Array(operands)
}
override
@@ -236,7 +233,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
/// unordered.
///
override
- public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
+ public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
for opnd: SemanticContext in opnds {
if try !opnd.eval(parser, parserCallStack) {
return false
@@ -246,7 +243,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
}
override
- public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
+ public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
var differs: Bool = false
var operands: Array = Array()
for context: SemanticContext in opnds {
@@ -305,30 +302,28 @@ public class SemanticContext: Hashable, CustomStringConvertible {
public init(_ a: SemanticContext, _ b: SemanticContext) {
var operands: Set = Set()
- if a is OR {
- operands.formUnion((a as! OR).opnds)
- // operands.addAll(Arrays.asList((a as OR).opnds));
+ if let aOr = a as? OR {
+ operands.formUnion(aOr.opnds)
} else {
operands.insert(a)
}
- if b is OR {
- operands.formUnion((b as! OR).opnds)
- //operands.addAll(Arrays.asList((b as OR).opnds));
+ if let bOr = b as? OR {
+ operands.formUnion(bOr.opnds)
} else {
operands.insert(b)
}
- let precedencePredicates: Array = SemanticContext.filterPrecedencePredicates(&operands)
+ let precedencePredicates = SemanticContext.filterPrecedencePredicates(&operands)
if !precedencePredicates.isEmpty {
// interested in the transition with the highest precedence
- let reduced: PrecedencePredicate = precedencePredicates.sorted {
+
+ let reduced = precedencePredicates.sorted {
$0.precedence > $1.precedence
- }.first!
- //var reduced : PrecedencePredicate = Collections.max(precedencePredicates);
- operands.insert(reduced)
+ }
+ operands.insert(reduced[0])
}
- self.opnds = Array(operands) //operands.toArray(new, SemanticContext[operands.size()]);
+ self.opnds = Array(operands)
}
override
@@ -351,7 +346,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
/// unordered.
///
override
- public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
+ public func eval(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> Bool {
for opnd: SemanticContext in opnds {
if try opnd.eval(parser, parserCallStack) {
return true
@@ -361,7 +356,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
}
override
- public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
+ public func evalPrecedence(_ parser: Recognizer, _ parserCallStack: RuleContext) throws -> SemanticContext? {
var differs: Bool = false
var operands: Array = Array()
for context: SemanticContext in opnds {
@@ -447,21 +442,14 @@ public class SemanticContext: Hashable, CustomStringConvertible {
return result
}
- private static func filterPrecedencePredicates(
- _ collection: inout Set) ->
- Array {
-
- let result = collection.filter {
- $0 is PrecedencePredicate
+ private static func filterPrecedencePredicates(_ collection: inout Set) -> [PrecedencePredicate] {
+ let result = collection.flatMap {
+ $0 as? PrecedencePredicate
}
collection = Set(collection.filter {
!($0 is PrecedencePredicate)
})
- //if (result == nil) {
- //return Array();
- //}
-
- return (result as! Array)
+ return result
}
}
diff --git a/runtime/Swift/Sources/Antlr4/misc/ArrayWrapper.swift b/runtime/Swift/Sources/Antlr4/misc/ArrayWrapper.swift
index 1ad30758b..5d5a68b88 100644
--- a/runtime/Swift/Sources/Antlr4/misc/ArrayWrapper.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/ArrayWrapper.swift
@@ -69,7 +69,7 @@ public final class ArrayWrapper: ExpressibleByArrayLiteral, Hashabl
}
-public func == (lhs: ArrayWrapper, rhs: ArrayWrapper) -> Bool {
+public func == (lhs: ArrayWrapper, rhs: ArrayWrapper) -> Bool {
if lhs === rhs {
return true
}
diff --git a/runtime/Swift/Sources/Antlr4/misc/BitSet.swift b/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
index d2c9b510f..c68b698d0 100644
--- a/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
@@ -32,10 +32,6 @@ import Foundation
/// implementation. The length of a bit set relates to logical length
/// of a bit set and is defined independently of implementation.
///
-/// Unless otherwise noted, passing a null parameter to any of the
-/// methods in a `BitSet` will result in a
-/// `ANTLRError.nullPointer`.
-///
/// A `BitSet` is not safe for multithreaded use without
/// external synchronization.
///
@@ -648,12 +644,12 @@ public class BitSet: Hashable, CustomStringConvertible {
return 64
}
var n: Int32 = 63
- y = Int32(truncatingBitPattern: i)
+ y = Int32(truncatingIfNeeded: i)
if y != 0 {
n = n - 32
x = y
} else {
- x = Int32(truncatingBitPattern: i >>> 32)
+ x = Int32(truncatingIfNeeded: i >>> 32)
}
y = x << 16
diff --git a/runtime/Swift/Sources/Antlr4/misc/HashMap.swift b/runtime/Swift/Sources/Antlr4/misc/HashMap.swift
index 89aced6a2..0157d8d56 100644
--- a/runtime/Swift/Sources/Antlr4/misc/HashMap.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/HashMap.swift
@@ -41,7 +41,7 @@ final class Entry: CustomStringConvertible {
var description: String { return "\(getKey())=\(getValue())" }
}
-func == (lhs: Entry, rhs: Entry) -> Bool {
+func == (lhs: Entry, rhs: Entry) -> Bool {
if lhs === rhs {
return true
}
@@ -52,7 +52,7 @@ func == (lhs: Entry, rhs: Entry) -> Bool {
}
return false
}
-func == (lhs: Entry, rhs: Entry) -> Bool {
+func == (lhs: Entry, rhs: Entry) -> Bool {
if lhs === rhs {
return true
}
diff --git a/runtime/Swift/Sources/Antlr4/misc/MurmurHash.swift b/runtime/Swift/Sources/Antlr4/misc/MurmurHash.swift
index 09819e0d0..1bdbcd426 100644
--- a/runtime/Swift/Sources/Antlr4/misc/MurmurHash.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/MurmurHash.swift
@@ -49,19 +49,19 @@ public final class MurmurHash {
let m: Int32 = 5
let n: Int32 = -430675100//0xE6546B64;
- var k: Int32 = Int32(truncatingBitPattern: value)
- k = Int32.multiplyWithOverflow(k, c1).0
+ var k: Int32 = Int32(truncatingIfNeeded: value)
+ k = k.multipliedReportingOverflow(by: c1).partialValue
// (k,_) = UInt32.multiplyWithOverflow(k, c1) ;//( k * c1);
//TODO: CHECKE >>>
k = (k << r1) | (k >>> (Int32(32) - r1)) //k = (k << r1) | (k >>> (32 - r1));
//k = UInt32 (truncatingBitPattern:Int64(Int64(k) * Int64(c2)));//( k * c2);
//(k,_) = UInt32.multiplyWithOverflow(k, c2)
- k = Int32.multiplyWithOverflow(k, c2).0
+ k = k.multipliedReportingOverflow(by: c2).partialValue
var hash = Int32(hashIn)
hash = hash ^ k
hash = (hash << r2) | (hash >>> (Int32(32) - r2))//hash = (hash << r2) | (hash >>> (32 - r2));
- (hash, _) = Int32.multiplyWithOverflow(hash, m)
- (hash, _) = Int32.addWithOverflow(hash, n)
+ hash = hash.multipliedReportingOverflow(by: m).partialValue
+ hash = hash.addingReportingOverflow(n).partialValue
//hash = hash * m + n;
// print("murmur update2 : \(hash)")
return Int(hash)
@@ -90,12 +90,12 @@ public final class MurmurHash {
public static func finish(_ hashin: Int, _ numberOfWordsIn: Int) -> Int {
var hash = Int32(hashin)
let numberOfWords = Int32(numberOfWordsIn)
- hash = hash ^ Int32.multiplyWithOverflow(numberOfWords, Int32(4)).0 //(numberOfWords * UInt32(4));
+ hash = hash ^ numberOfWords.multipliedReportingOverflow(by: 4).partialValue //(numberOfWords * UInt32(4));
hash = hash ^ (hash >>> Int32(16)) //hash = hash ^ (hash >>> 16);
- (hash, _) = Int32.multiplyWithOverflow(hash, Int32(-2048144789))//hash * UInt32(0x85EBCA6B);
+ hash = hash.multipliedReportingOverflow(by: -2048144789).partialValue //hash * UInt32(0x85EBCA6B);
hash = hash ^ (hash >>> Int32(13))//hash = hash ^ (hash >>> 13);
//hash = UInt32(truncatingBitPattern: UInt64(hash) * UInt64(0xC2B2AE35)) ;
- (hash, _) = Int32.multiplyWithOverflow(hash, Int32(-1028477387))
+ hash = hash.multipliedReportingOverflow(by: -1028477387).partialValue
hash = hash ^ (hash >>> Int32(16))// hash = hash ^ (hash >>> 16);
//print("murmur finish : \(hash)")
return Int(hash)
diff --git a/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift b/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
index 2bc300c56..c9df3022e 100644
--- a/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
@@ -14,7 +14,6 @@
import Foundation
public enum ANTLRError: Error {
- case nullPointer(msg:String)
case unsupportedOperation(msg:String)
case indexOutOfBounds(msg:String)
case illegalState(msg:String)
diff --git a/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift b/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
index 49a39592c..1928be7f9 100644
--- a/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
@@ -11,14 +11,6 @@ import Foundation
extension String {
- func split(_ separator: String) -> [String] {
- return self.components(separatedBy: separator)
- }
-
- func containsIgnoreCase(_ find: String) -> Bool {
- return self.lowercased().range(of: find.lowercased()) != nil
- }
-
var length: Int {
return self.characters.count
}
@@ -60,32 +52,6 @@ extension String {
return index
}
- func substringAfter(_ string: String) -> String {
- if let range = self.range(of: string) {
- let intIndex: Int = self.characters.distance(from: self.startIndex, to: range.upperBound)
- return self.substring(from: self.characters.index(self.startIndex, offsetBy: intIndex))
- }
- return self
-
- }
-
- var lowercaseFirstChar: String {
- var result = self
- if self.length > 0 {
- let startIndex = self.startIndex
- result.replaceSubrange(startIndex ... startIndex, with: String(self[startIndex]).lowercased())
- }
- return result
- }
- func substringWithRange(_ range: Range) -> String {
-
-
- let start = self.characters.index(self.startIndex, offsetBy: range.lowerBound)
-
- let end = self.characters.index(self.startIndex, offsetBy: range.upperBound)
- return self.substring(with: start ..< end)
- }
-
subscript(integerIndex: Int) -> Character {
let index = characters.index(startIndex, offsetBy: integerIndex)
return self[index]
@@ -95,118 +61,7 @@ extension String {
let start = characters.index(startIndex, offsetBy: integerRange.lowerBound)
let end = characters.index(startIndex, offsetBy: integerRange.upperBound)
let range = start ..< end
- return self[range]
- }
-
- func charAt(_ index: Int) -> Character {
- return self[self.characters.index(self.startIndex, offsetBy: index)]
- }
-
-}
-
-// Mapping from XML/HTML character entity reference to character
-// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
-private let characterEntities: [String:Character] = [
- // XML predefined entities:
- """: "\"",
- "&": "&",
- "'": "'",
- "<": "<",
- ">": ">",
-
- // HTML character entity references:
- " ": "\u{00a0}",
- // ...
- "♦": "♦",
-]
-
-extension String {
-
- ///
- /// Returns a new string made by replacing in the `String`
- /// all HTML character entity references with the corresponding
- /// character.
- ///
- var stringByDecodingHTMLEntities: String {
-
-
- // Convert the number in the string to the corresponding
- // Unicode character, e.g.
- // decodeNumeric("64", 10) --> "@"
- // decodeNumeric("20ac", 16) --> "€"
- func decodeNumeric(_ string: String, base: Int32) -> Character? {
- let code = UInt32(strtoul(string, nil, base))
- return Character(UnicodeScalar(code)!)
- }
-
- // Decode the HTML character entity to the corresponding
- // Unicode character, return `nil` for invalid input.
- // decode("@") --> "@"
- // decode("€") --> "€"
- // decode("<") --> "<"
- // decode("&foo;") --> nil
- func decode(_ entity: String) -> Character? {
-
- if entity.hasPrefix("") || entity.hasPrefix("") {
- return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 3)), base: 16)
- } else if entity.hasPrefix("") {
- return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 2)), base: 10)
- } else {
- return characterEntities[entity]
- }
- }
-
- var result = ""
- var position = startIndex
-
- // Find the next '&' and copy the characters preceding it to `result`:
- while let ampRange = self.range(of: "&", range: position ..< endIndex) {
- result.append(self[position ..< ampRange.lowerBound])
- position = ampRange.lowerBound
-
- // Find the next ';' and copy everything from '&' to ';' into `entity`
- if let semiRange = self.range(of: ";", range: position ..< endIndex) {
- let entity = self[position ..< semiRange.upperBound]
- position = semiRange.upperBound
-
- if let decoded = decode(entity) {
- // Replace by decoded character:
- result.append(decoded)
- } else {
- // Invalid entity, copy verbatim:
- result.append(entity)
- }
- } else {
- // No matching ';'.
- break
- }
- }
- // Copy remaining characters to `result`:
- result.append(self[position ..< endIndex])
- return result
+ return String(self[range])
}
}
-extension String {
-
- static let htmlEscapedDictionary = [
- "&": "&",
- """: "\"",
- "'": "'",
- "9": "'",
- "": "'",
- "": "'",
- ">": ">",
- "<": "<"
- ]
-
- public var escapedHtmlString: String {
- var newString = "\(self)"
-
- for (key, value) in String.htmlEscapedDictionary {
- newString = newString.replacingOccurrences(of: value, with: key)
- }
- return newString
- }
-
-}
diff --git a/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift b/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
index c5f731a13..ecc9ae1d0 100644
--- a/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
+++ b/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
@@ -320,7 +320,6 @@ public class ParseTreePatternMatcher {
// add special rule token or conjure up new token from name
let firstStr = String(tagChunk.getTag()[0])
if firstStr.lowercased() != firstStr {
- //if ( Character.isUpperCase(tagChunk.getTag().charAt(0)) ) {
let ttype: Int = parser.getTokenType(tagChunk.getTag())
if ttype == CommonToken.INVALID_TYPE {
throw ANTLRError.illegalArgument(msg: "Unknown token " + tagChunk.getTag() + " in pattern: " + pattern)
@@ -329,7 +328,6 @@ public class ParseTreePatternMatcher {
tokens.append(t)
} else {
if firstStr.uppercased() != firstStr {
- // if ( Character.isLowerCase(tagChunk.getTag().charAt(0)) ) {
let ruleIndex: Int = parser.getRuleIndex(tagChunk.getTag())
if ruleIndex == -1 {
throw ANTLRError.illegalArgument(msg: "Unknown rule " + tagChunk.getTag() + " in pattern: " + pattern)
diff --git a/runtime/Swift/Tests/Antlr4Tests/VisitorTests.swift b/runtime/Swift/Tests/Antlr4Tests/VisitorTests.swift
index e22488797..d7adb1cb6 100644
--- a/runtime/Swift/Tests/Antlr4Tests/VisitorTests.swift
+++ b/runtime/Swift/Tests/Antlr4Tests/VisitorTests.swift
@@ -62,10 +62,10 @@ class VisitorTests: XCTestCase {
var errors = [String]()
- override func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int, _ charPositionInLine: Int,
- _ msg: String, _ e: AnyObject?) {
+ override func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int, _ charPositionInLine: Int,
+ _ msg: String, _ e: AnyObject?) {
errors.append("line \(line):\(charPositionInLine) \(msg)")
}
}
diff --git a/runtime/Swift/boot.py b/runtime/Swift/boot.py
index b362224de..ff82c9e00 100755
--- a/runtime/Swift/boot.py
+++ b/runtime/Swift/boot.py
@@ -110,7 +110,7 @@ def get_argument_parser():
"Use this command if you want to include ANTLR4 as SPM dependency.", )
p.add_argument("--gen-xcodeproj",
action="store_true",
- help=" Generates an Xcode project for ANTLR4 Swift runtime. "
+ help=" Generates an Xcode project for ANTLR4 Swift runtime. "
"This directive will generate all the required parsers for the project. "
"Feel free to re-run whenever you updated the test grammar files.")
p.add_argument("--test",
@@ -147,7 +147,11 @@ def generate_spm_module(in_folder=TMP_FOLDER):
call(["git", "tag", "{}.0.0".format(MAJOR_VERSION)])
antlr_says("Created local repository.")
- antlr_says("Put .Package(url: \"{}\", majorVersion: {}) in Package.swift.".format(os.getcwd(), MAJOR_VERSION))
+ antlr_says("(swift-tools-version:3.0) "
+ "Put .Package(url: \"{}\", majorVersion: {}) in Package.swift.".format(os.getcwd(), MAJOR_VERSION))
+ antlr_says("(swift-tools-wersion:4.0) "
+ "Put .package(url: \"{}\", from: \"{}.0.0\") in Package.swift "
+ "and add \"Antlr4\" to target dependencies. ".format(os.getcwd(), MAJOR_VERSION))
def generate_xcodeproj():
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
index 3219c0bad..b19d6c865 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
@@ -8,6 +8,7 @@ package org.antlr.v4.test.tool;
import org.antlr.v4.Tool;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -60,6 +61,16 @@ public class TestToolSyntaxErrors extends BaseJavaToolTest {
super.testSetUp();
}
+ @Test
+ public void AllErrorCodesDistinct() {
+ ErrorType[] errorTypes = ErrorType.class.getEnumConstants();
+ for (int i = 0; i < errorTypes.length; i++) {
+ for (int j = i + 1; j < errorTypes.length; j++) {
+ Assert.assertNotEquals(errorTypes[i].code, errorTypes[j].code);
+ }
+ }
+ }
+
@Test public void testA() { super.testErrors(A, true); }
@Test public void testExtraColon() {
diff --git a/tool/pom.xml b/tool/pom.xml
index 1952a25ec..cb172c534 100644
--- a/tool/pom.xml
+++ b/tool/pom.xml
@@ -58,6 +58,7 @@
org.apache.maven.plugins
maven-source-plugin
+ 3.0.1
@@ -86,6 +87,7 @@
org.codehaus.mojo
build-helper-maven-plugin
+ 3.0.0
generate-sources
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
index b1835e4e7..81d00484e 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
@@ -1,5 +1,5 @@
fileHeader(grammarFileName, ANTLRVersion) ::= <<
-// Generated from by ANTLR .
+// Code generated from by ANTLR . DO NOT EDIT.
>>
ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
@@ -777,29 +777,31 @@ MatchSet(m, expr, capture) ::= ""
MatchNotSet(m, expr, capture) ::= ""
CommonSetStuff(m, expr, capture, invert) ::= <<
-p.SetState()
-
-
-var _lt = p.GetTokenStream().LT(1)
-
- = _lt}; separator="\n">
-
-
-
-
-
-
-if \<= 0 || if !() {
+{
+ p.SetState()
- var _ri = p.GetErrorHandler().RecoverInline(p)
- = _ri}; separator="\n">
-
- p.GetErrorHandler().RecoverInline(p)
+ var _lt = p.GetTokenStream().LT(1)
+
+ = _lt}; separator="\n">
+
-} else {
- p.GetErrorHandler().ReportMatch(p)
- p.Consume()
+
+
+
+
+ if \<= 0 || if !() {
+
+ var _ri = p.GetErrorHandler().RecoverInline(p)
+
+ = _ri}; separator="\n">
+
+ p.GetErrorHandler().RecoverInline(p)
+
+ } else {
+ p.GetErrorHandler().ReportMatch(p)
+ p.Consume()
+ }
}
>>
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
index 0ebd212ec..492c56644 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
@@ -894,8 +894,10 @@ public class extends {
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
+
public static final int
=}; separator=", ", wrap, anchor>;
+
public static final int
=}; separator=", ", wrap, anchor>;
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
index fb5883c02..728db6307 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
@@ -36,12 +36,12 @@
* REQUIRED.
*/
-pythonTypeInitMap ::= [
- "bool":"False",
+javascriptTypeInitMap ::= [
+ "bool":"false",
"int":"0",
"float":"0.0",
"str":"",
- default:"None" // anything other than a primitive type is an object
+ default:"{}" // anything other than a primitive type is an object
]
// args must be ,
@@ -802,6 +802,9 @@ var antlr4 = require('antlr4/index');
>>
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
+
+var = require('./').;
+
@@ -860,7 +863,7 @@ var serializedATN = [" "}>"].join("");
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".js"
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
index b01a76fc4..570f1659f 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
@@ -809,7 +809,7 @@ def serializedATN():
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".py"
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
index 081e3f3f1..34e525b85 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
@@ -816,7 +816,7 @@ def serializedATN():
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".py"
diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java
index 700269fb9..d7ad7ab40 100644
--- a/tool/src/org/antlr/v4/tool/ErrorType.java
+++ b/tool/src/org/antlr/v4/tool/ErrorType.java
@@ -394,11 +394,11 @@ public enum ErrorType {
*/
IMPORT_NAME_CLASH(113, " grammar and imported grammar both generate ", ErrorSeverity.ERROR),
/**
- * Compiler Error 160.
+ * Compiler Error 114.
*
* cannot find tokens file filename
*/
- CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(160, "cannot find tokens file ", ErrorSeverity.ERROR),
+ CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(114, "cannot find tokens file ", ErrorSeverity.ERROR),
/**
* Compiler Warning 118.
*
@@ -522,7 +522,7 @@ public enum ErrorType {
*/
USE_OF_BAD_WORD(134, "symbol conflicts with generated code in target language or runtime", ErrorSeverity.ERROR),
/**
- * Compiler Error 134.
+ * Compiler Error 183.
*
* rule reference rule is not currently supported in a set
*
@@ -530,7 +530,7 @@ public enum ErrorType {
* Note: This error has the same number as the unrelated error
* {@link #USE_OF_BAD_WORD}.
*/
- UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference is not currently supported in a set", ErrorSeverity.ERROR),
+ UNSUPPORTED_REFERENCE_IN_LEXER_SET(183, "rule reference is not currently supported in a set", ErrorSeverity.ERROR),
/**
* Compiler Error 135.
*