Merge branch 'master' into export-lexer-methods
This commit is contained in:
commit
8a551095dc
|
@ -1,5 +1,8 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
tab_width = 4
|
||||
|
||||
[*.{java,stg}]
|
||||
charset = utf-8
|
||||
insert_final_newline = true
|
||||
|
|
198
.travis.yml
198
.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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() { :; }
|
|
@ -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() { :; }
|
||||
|
||||
|
|
|
@ -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() { :; }
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -151,7 +151,18 @@ 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/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
|
|
@ -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
|
||||
...
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 379 KiB |
|
@ -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.
|
||||
|
||||
<img src=images/xcodenav.png width="300">
|
||||
|
||||
#### 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.
|
||||
|
||||
<img src=images/dragfile.png width="500">
|
||||
|
||||
* __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__.
|
||||
|
||||
<img src=images/xcodenav.png width="300">
|
||||
<img src=images/xcodedep.png width="800">
|
||||
|
||||
* __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
|
||||
|
||||
<img src=images/targetselection.png width="500">
|
||||
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
|
||||
|
||||
<img src=images/xcodedep.png width="800">
|
||||
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:
|
||||
|
||||
<img src=images/gen_spm_module.png width="800">
|
||||
|
||||
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.
|
||||
|
|
|
@ -23,6 +23,7 @@ public class TestCodePointCharStream {
|
|||
CodePointCharStream s = CharStreams.fromString("");
|
||||
assertEquals(0, s.size());
|
||||
assertEquals(0, s.index());
|
||||
assertEquals("", s.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<plugin> <!-- create src jar -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
exports.equalArrays = equalArrays;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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">"
|
||||
|
|
|
@ -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">"
|
||||
|
||||
# <p>The implementation for {@link TokenTagToken} returns a string of the form
|
||||
# {@code tokenName:type}.</p>
|
||||
|
|
|
@ -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 "<EOF>"
|
||||
return u"<EOF>"
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
.build/
|
||||
Antlr4.xcodeproj/
|
||||
Tests/Antlr4Tests/gen/
|
||||
xcuserdata/
|
||||
|
|
|
@ -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"]),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -39,12 +39,12 @@ public protocol ANTLRErrorListener: class {
|
|||
/// the parser was able to recover in line without exiting the
|
||||
/// surrounding rule.
|
||||
///
|
||||
func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
)
|
||||
|
||||
///
|
||||
|
|
|
@ -17,12 +17,12 @@ open class BaseErrorListener: ANTLRErrorListener {
|
|||
public init() {
|
||||
}
|
||||
|
||||
open func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
open func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,12 +25,12 @@ public class ConsoleErrorListener: BaseErrorListener {
|
|||
/// line __line__:__charPositionInLine__ __msg__
|
||||
///
|
||||
///
|
||||
override public func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
override public func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?
|
||||
) {
|
||||
if Parser.ConsoleError {
|
||||
errPrint("line \(line):\(charPositionInLine) \(msg)")
|
||||
|
|
|
@ -405,7 +405,7 @@ open class Lexer: Recognizer<LexerATNSimulator>
|
|||
}
|
||||
}
|
||||
|
||||
open func notifyListeners<T:ATNSimulator>(_ e: LexerNoViableAltException, recognizer: Recognizer<T>) {
|
||||
open func notifyListeners<T>(_ e: LexerNoViableAltException, recognizer: Recognizer<T>) {
|
||||
|
||||
let text: String = _input!.getText(Interval.of(_tokenStartCharIndex, _input!.index()))
|
||||
let msg: String = "token recognition error at: '\(getErrorDisplay(text))'"
|
||||
|
|
|
@ -336,8 +336,6 @@ open class Parser: Recognizer<ParserATNSimulator> {
|
|||
///
|
||||
/// - Parameter listener: the listener to add
|
||||
///
|
||||
/// - Throws: _ANTLRError.nullPointer_ if listener is `null`
|
||||
///
|
||||
public func addParseListener(_ listener: ParseTreeListener) {
|
||||
if _parseListeners == nil {
|
||||
_parseListeners = Array<ParseTreeListener>()
|
||||
|
|
|
@ -20,13 +20,13 @@ public class ProxyErrorListener: ANTLRErrorListener {
|
|||
self.delegates = delegates
|
||||
}
|
||||
|
||||
public func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?)
|
||||
{
|
||||
public func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int,
|
||||
_ charPositionInLine: Int,
|
||||
_ msg: String,
|
||||
_ e: AnyObject?)
|
||||
{
|
||||
for listener: ANTLRErrorListener in delegates {
|
||||
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e)
|
||||
}
|
||||
|
|
|
@ -228,9 +228,6 @@ open class Recognizer<ATNInterpreter:ATNSimulator> {
|
|||
return "\(s)"
|
||||
}
|
||||
|
||||
///
|
||||
/// - Throws: ANTLRError.nullPointer if `listener` is `null`.
|
||||
///
|
||||
open func addErrorListener(_ listener: ANTLRErrorListener) {
|
||||
|
||||
_listeners.append(listener)
|
||||
|
|
|
@ -233,7 +233,7 @@ open class RuleContext: RuleNode {
|
|||
return description
|
||||
}
|
||||
|
||||
public final func toString<T:ATNSimulator>(_ recog: Recognizer<T>) -> String {
|
||||
public final func toString<T>(_ recog: Recognizer<T>) -> 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<T:ATNSimulator>(_ recog: Recognizer<T>?, _ stop: RuleContext) -> String {
|
||||
open func toString<T>(_ recog: Recognizer<T>?, _ stop: RuleContext) -> String {
|
||||
let ruleNames: [String]? = recog != nil ? recog!.getRuleNames() : nil
|
||||
let ruleNamesList: Array<String>? = ruleNames ?? nil
|
||||
return toString(ruleNamesList, stop)
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -167,7 +167,7 @@ public class ATNConfig: Hashable, CustomStringConvertible {
|
|||
//return "MyClass \(string)"
|
||||
return toString(nil, true)
|
||||
}
|
||||
public func toString<T:ATNSimulator>(_ recog: Recognizer<T>?, _ showAlt: Bool) -> String {
|
||||
public func toString<T>(_ recog: Recognizer<T>?, _ showAlt: Bool) -> String {
|
||||
let buf: StringBuilder = StringBuilder()
|
||||
buf.append("(")
|
||||
buf.append(state)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -712,17 +712,17 @@ public class PredictionContext: Hashable, CustomStringConvertible {
|
|||
}
|
||||
}
|
||||
|
||||
public func toString<T:ATNSimulator>(_ recog: Recognizer<T>) -> String {
|
||||
public func toString<T>(_ recog: Recognizer<T>) -> String {
|
||||
return NSStringFromClass(PredictionContext.self)
|
||||
// return toString(recog, ParserRuleContext.EMPTY);
|
||||
}
|
||||
|
||||
public func toStrings<T:ATNSimulator>(_ recognizer: Recognizer<T>, _ currentState: Int) -> [String] {
|
||||
public func toStrings<T>(_ recognizer: Recognizer<T>, _ currentState: Int) -> [String] {
|
||||
return toStrings(recognizer, PredictionContext.EMPTY, currentState)
|
||||
}
|
||||
|
||||
// FROM SAM
|
||||
public func toStrings<T:ATNSimulator>(_ recognizer: Recognizer<T>?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
|
||||
public func toStrings<T>(_ recognizer: Recognizer<T>?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
|
||||
var result: Array<String> = Array<String>()
|
||||
var perm: Int = 0
|
||||
outer: while true {
|
||||
|
|
|
@ -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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
public func eval<T>(_ parser: Recognizer<T>, _ 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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
return self
|
||||
}
|
||||
public var hashValue: Int {
|
||||
|
@ -90,7 +90,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
|||
}
|
||||
|
||||
override
|
||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
public func eval<T>(_ parser: Recognizer<T>, _ 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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
return try parser.precpred(parserCallStack, precedence)
|
||||
}
|
||||
|
||||
override
|
||||
public func evalPrecedence<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ 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<SemanticContext> = Set<SemanticContext>()
|
||||
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<PrecedencePredicate> =
|
||||
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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
public func eval<T>(_ parser: Recognizer<T>, _ 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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
var differs: Bool = false
|
||||
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
||||
for context: SemanticContext in opnds {
|
||||
|
@ -305,30 +302,28 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
|||
|
||||
public init(_ a: SemanticContext, _ b: SemanticContext) {
|
||||
var operands: Set<SemanticContext> = Set<SemanticContext>()
|
||||
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<PrecedencePredicate> = 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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||
public func eval<T>(_ parser: Recognizer<T>, _ 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<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||
var differs: Bool = false
|
||||
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
||||
for context: SemanticContext in opnds {
|
||||
|
@ -447,21 +442,14 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
|||
return result
|
||||
}
|
||||
|
||||
private static func filterPrecedencePredicates(
|
||||
_ collection: inout Set<SemanticContext>) ->
|
||||
Array<PrecedencePredicate> {
|
||||
|
||||
let result = collection.filter {
|
||||
$0 is PrecedencePredicate
|
||||
private static func filterPrecedencePredicates(_ collection: inout Set<SemanticContext>) -> [PrecedencePredicate] {
|
||||
let result = collection.flatMap {
|
||||
$0 as? PrecedencePredicate
|
||||
}
|
||||
collection = Set<SemanticContext>(collection.filter {
|
||||
!($0 is PrecedencePredicate)
|
||||
})
|
||||
//if (result == nil) {
|
||||
//return Array<PrecedencePredicate>();
|
||||
//}
|
||||
|
||||
return (result as! Array<PrecedencePredicate>)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public final class ArrayWrapper<T: Hashable>: ExpressibleByArrayLiteral, Hashabl
|
|||
|
||||
}
|
||||
|
||||
public func == <Element: Equatable>(lhs: ArrayWrapper<Element>, rhs: ArrayWrapper<Element>) -> Bool {
|
||||
public func == <Element>(lhs: ArrayWrapper<Element>, rhs: ArrayWrapper<Element>) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -41,7 +41,7 @@ final class Entry<K: Hashable,V>: CustomStringConvertible {
|
|||
var description: String { return "\(getKey())=\(getValue())" }
|
||||
|
||||
}
|
||||
func == <K: Hashable, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
||||
func == <K, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func == <K: Hashable, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
func == <K: Hashable, V: Equatable>(lhs: Entry<K,V?>, rhs: Entry<K,V?>) -> Bool {
|
||||
func == <K, V: Equatable>(lhs: Entry<K,V?>, rhs: Entry<K,V?>) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Int>) -> 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("&#x") || entity.hasPrefix("&#X") {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -62,10 +62,10 @@ class VisitorTests: XCTestCase {
|
|||
|
||||
var errors = [String]()
|
||||
|
||||
override func syntaxError<T : ATNSimulator>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int, _ charPositionInLine: Int,
|
||||
_ msg: String, _ e: AnyObject?) {
|
||||
override func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||
_ offendingSymbol: AnyObject?,
|
||||
_ line: Int, _ charPositionInLine: Int,
|
||||
_ msg: String, _ e: AnyObject?) {
|
||||
errors.append("line \(line):\(charPositionInLine) \(msg)")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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="<DEVELOPER> Generates an Xcode project for ANTLR4 Swift runtime. "
|
||||
help="<DEVELOPER, USER> 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():
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<plugin> <!-- create src jar -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
@ -86,6 +87,7 @@
|
|||
<plugin> <!-- include code-generated sources -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileHeader(grammarFileName, ANTLRVersion) ::= <<
|
||||
// Generated from <grammarFileName; format="java-escape"> by ANTLR <ANTLRVersion>.
|
||||
// Code generated from <grammarFileName; format="java-escape"> by ANTLR <ANTLRVersion>. DO NOT EDIT.
|
||||
>>
|
||||
|
||||
ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
|
||||
|
@ -777,29 +777,31 @@ MatchSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, false)>"
|
|||
MatchNotSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, true)>"
|
||||
|
||||
CommonSetStuff(m, expr, capture, invert) ::= <<
|
||||
p.SetState(<m.stateNumber>)
|
||||
<if(m.labels)>
|
||||
|
||||
var _lt = p.GetTokenStream().LT(1)<! TODO: Should LT be called always like InvokeRule and MatchToken? !>
|
||||
|
||||
<m.labels:{l | <labelref(l)> = _lt}; separator="\n">
|
||||
|
||||
<endif>
|
||||
<if(capture)>
|
||||
<capture>
|
||||
|
||||
<endif>
|
||||
<if(invert)>if <m.varName> \<= 0 || <expr> <else>if !(<expr>)<endif> {
|
||||
{
|
||||
p.SetState(<m.stateNumber>)
|
||||
<if(m.labels)>
|
||||
var _ri = p.GetErrorHandler().RecoverInline(p)
|
||||
|
||||
<m.labels:{l | <labelref(l)> = _ri}; separator="\n">
|
||||
<else>
|
||||
p.GetErrorHandler().RecoverInline(p)
|
||||
var _lt = p.GetTokenStream().LT(1)<! TODO: Should LT be called always like InvokeRule and MatchToken? !>
|
||||
|
||||
<m.labels:{l | <labelref(l)> = _lt}; separator="\n">
|
||||
|
||||
<endif>
|
||||
} else {
|
||||
p.GetErrorHandler().ReportMatch(p)
|
||||
p.Consume()
|
||||
<if(capture)>
|
||||
<capture>
|
||||
|
||||
<endif>
|
||||
<if(invert)>if <m.varName> \<= 0 || <expr> <else>if !(<expr>)<endif> {
|
||||
<if(m.labels)>
|
||||
var _ri = p.GetErrorHandler().RecoverInline(p)
|
||||
|
||||
<m.labels:{l | <labelref(l)> = _ri}; separator="\n">
|
||||
<else>
|
||||
p.GetErrorHandler().RecoverInline(p)
|
||||
<endif>
|
||||
} else {
|
||||
p.GetErrorHandler().ReportMatch(p)
|
||||
p.Consume()
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
|
|
@ -894,8 +894,10 @@ public class <lexer.name> extends <superClass; null="Lexer"> {
|
|||
protected static final DFA[] _decisionToDFA;
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
<if(lexer.tokens)>
|
||||
public static final int
|
||||
<lexer.tokens:{k | <k>=<lexer.tokens.(k)>}; separator=", ", wrap, anchor>;
|
||||
<endif>
|
||||
<if(lexer.channels)>
|
||||
public static final int
|
||||
<lexer.channels:{c | <c>=<lexer.channels.(c)>}; separator=", ", wrap, anchor>;
|
||||
|
|
|
@ -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 <object-model-object>, <fields-resulting-in-STs>
|
||||
|
@ -802,6 +802,9 @@ var antlr4 = require('antlr4/index');
|
|||
>>
|
||||
|
||||
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
|
||||
<if(superClass)>
|
||||
var <superClass> = require('./<superClass>').<superClass>;
|
||||
<endif>
|
||||
|
||||
<atn>
|
||||
|
||||
|
@ -860,7 +863,7 @@ var serializedATN = ["<model.serialized; wrap={",<\n> "}>"].join("");
|
|||
* must be an object, default value is "null".
|
||||
*/
|
||||
initValue(typeName) ::= <<
|
||||
<javaTypeInitMap.(typeName)>
|
||||
<javacriptTypeInitMap.(typeName)>
|
||||
>>
|
||||
|
||||
codeFileExtension() ::= ".js"
|
||||
|
|
|
@ -809,7 +809,7 @@ def serializedATN():
|
|||
* must be an object, default value is "null".
|
||||
*/
|
||||
initValue(typeName) ::= <<
|
||||
<javaTypeInitMap.(typeName)>
|
||||
<pythonTypeInitMap.(typeName)>
|
||||
>>
|
||||
|
||||
codeFileExtension() ::= ".py"
|
||||
|
|
|
@ -816,7 +816,7 @@ def serializedATN():
|
|||
* must be an object, default value is "null".
|
||||
*/
|
||||
initValue(typeName) ::= <<
|
||||
<javaTypeInitMap.(typeName)>
|
||||
<pythonTypeInitMap.(typeName)>
|
||||
>>
|
||||
|
||||
codeFileExtension() ::= ".py"
|
||||
|
|
|
@ -394,11 +394,11 @@ public enum ErrorType {
|
|||
*/
|
||||
IMPORT_NAME_CLASH(113, "<arg.typeString> grammar <arg.name> and imported <arg2.typeString> grammar <arg2.name> both generate <arg2.recognizerName>", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 160.
|
||||
* Compiler Error 114.
|
||||
*
|
||||
* <p>cannot find tokens file <em>filename</em></p>
|
||||
*/
|
||||
CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(160, "cannot find tokens file <arg>", ErrorSeverity.ERROR),
|
||||
CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(114, "cannot find tokens file <arg>", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Warning 118.
|
||||
*
|
||||
|
@ -522,7 +522,7 @@ public enum ErrorType {
|
|||
*/
|
||||
USE_OF_BAD_WORD(134, "symbol <arg> conflicts with generated code in target language or runtime", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 134.
|
||||
* Compiler Error 183.
|
||||
*
|
||||
* <p>rule reference <em>rule</em> is not currently supported in a set</p>
|
||||
*
|
||||
|
@ -530,7 +530,7 @@ public enum ErrorType {
|
|||
* Note: This error has the same number as the unrelated error
|
||||
* {@link #USE_OF_BAD_WORD}.</p>
|
||||
*/
|
||||
UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference <arg> is not currently supported in a set", ErrorSeverity.ERROR),
|
||||
UNSUPPORTED_REFERENCE_IN_LEXER_SET(183, "rule reference <arg> is not currently supported in a set", ErrorSeverity.ERROR),
|
||||
/**
|
||||
* Compiler Error 135.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue