forked from jasder/antlr
Merge branch 'master' into master
This commit is contained in:
commit
527118197f
|
@ -3,7 +3,7 @@ target/
|
|||
# ... but not code generation targets
|
||||
!tool/src/org/antlr/v4/codegen/target/
|
||||
|
||||
# Node.js (npm and typings) cached dependencies
|
||||
# Node.js (npm and typings) cached dependencies
|
||||
node_modules/
|
||||
typings/
|
||||
|
||||
|
@ -97,3 +97,7 @@ xcuserdata
|
|||
# VSCode Java plugin temporary files
|
||||
javac-services.0.log
|
||||
javac-services.0.log.lck
|
||||
test/
|
||||
|
||||
# Don't ignore python tests
|
||||
!runtime/Python3/test/
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "runtime/PHP"]
|
||||
path = runtime/PHP
|
||||
url = https://github.com/antlr/antlr-php-runtime.git
|
198
.travis.yml
198
.travis.yml
|
@ -19,8 +19,9 @@ stages:
|
|||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang
|
||||
jdk: openjdk7
|
||||
jdk: openjdk8
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- CXX=g++-5
|
||||
|
@ -35,125 +36,135 @@ matrix:
|
|||
- g++-5
|
||||
- uuid-dev
|
||||
- clang-3.7
|
||||
- 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
|
||||
jdk: openjdk8
|
||||
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
|
||||
dist: trusty
|
||||
compiler: clang
|
||||
jdk: openjdk8
|
||||
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: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=LEXER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=PARSER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=RECURSION
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=LEXER
|
||||
stage: main-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=PARSER
|
||||
stage: main-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=RECURSION
|
||||
stage: main-test
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=ALL
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode9
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=LEXER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode9
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=PARSER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode9
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=RECURSION
|
||||
stage: extended-test
|
||||
- os: linux
|
||||
dist: trusty
|
||||
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: openjdk7
|
||||
jdk: openjdk8
|
||||
env: TARGET=csharp
|
||||
stage: main-test
|
||||
- os: linux
|
||||
jdk: oraclejdk8
|
||||
jdk: openjdk8
|
||||
env: TARGET=dart
|
||||
stage: main-test
|
||||
- os: linux
|
||||
language: php
|
||||
php:
|
||||
- 7.2
|
||||
jdk: openjdk8
|
||||
env: TARGET=php
|
||||
stage: main-test
|
||||
- os: linux
|
||||
jdk: openjdk8
|
||||
dist: trusty
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
|
@ -167,25 +178,25 @@ matrix:
|
|||
- GROUP=PARSER
|
||||
stage: extended-test
|
||||
- os: linux
|
||||
jdk: oraclejdk8
|
||||
jdk: openjdk8
|
||||
dist: trusty
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=RECURSION
|
||||
stage: extended-test
|
||||
- os: linux
|
||||
jdk: openjdk7
|
||||
jdk: openjdk8
|
||||
env: TARGET=python2
|
||||
stage: main-test
|
||||
- os: linux
|
||||
jdk: openjdk7
|
||||
jdk: openjdk8
|
||||
env: TARGET=python3
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- deadsnakes # source required so it finds the package definition below
|
||||
packages:
|
||||
- python3.5
|
||||
- python3.7
|
||||
stage: main-test
|
||||
- os: linux
|
||||
dist: trusty
|
||||
|
@ -202,4 +213,9 @@ before_install:
|
|||
- f="./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh"; ! [ -x "$f" ] || "$f"
|
||||
|
||||
script:
|
||||
- cd runtime-testsuite; travis_wait 40 ../.travis/run-tests-$TARGET.sh
|
||||
- |
|
||||
cd runtime-testsuite;
|
||||
travis_wait 40 ../.travis/run-tests-$TARGET.sh;
|
||||
rc=$?;
|
||||
cat target/surefire-reports/*.dumpstream || true;
|
||||
exit $rc
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
set -euo pipefail
|
||||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
echo "deb http://download.mono-project.com/repo/debian xenial main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
|
||||
sudo apt-get update -qq
|
||||
echo "deb http://download.mono-project.com/repo/debian wheezy/snapshots/3.12.1 main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
|
||||
sudo apt-get install -qq mono-complete
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
wget https://storage.googleapis.com/dart-archive/channels/stable/release/2.8.4/linux_packages/dart_2.8.4-1_amd64.deb
|
||||
sudo dpkg -i ./dart_2.8.4-1_amd64.deb
|
||||
sudo rm ./dart_2.8.4-1_amd64.deb
|
||||
sudo apt-get install -f
|
|
@ -6,5 +6,5 @@ set -euo pipefail
|
|||
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
|
||||
sudo apt-get update
|
||||
sudo apt-get install dotnet-dev-1.0.4
|
||||
sudo apt-get --allow-unauthenticated install dotnet-dev-1.0.4
|
||||
|
||||
|
|
|
@ -2,7 +2,5 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
sudo apt-get update -qq
|
||||
eval "$(sudo gimme 1.7.3)"
|
||||
( go version ; go env ) || true
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
sudo apt-get update -qq
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
sudo apt-get update -qq
|
||||
curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -
|
||||
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
|
||||
sudo apt-get install -qq nodejs
|
||||
node --version
|
||||
|
|
|
@ -4,3 +4,7 @@ set -euo pipefail
|
|||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
sudo apt-get update -qq
|
||||
|
||||
php -v
|
||||
|
||||
mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
|
||||
sudo apt-get update -qq
|
||||
python --version
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
python3 --version
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $GROUP == "LEXER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LexerTests" -Dtest=cpp.* test
|
||||
elif [ $GROUP == "PARSER" ]; then
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=csharp.* test
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
mvn -q -Dparallel=classes -DthreadCount=4 -Dtest=dart.* test
|
|
@ -1,10 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# we need to build the runtime before test run, since we used "--no-dependencies"
|
||||
# when we call dotnet cli for restore and build, in order to speed up
|
||||
|
||||
dotnet restore ../runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
dotnet build -c Release ../runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
dotnet build -c Release -f netstandard1.3 ../runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
|
||||
# call test
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=go.* test
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=java.* test
|
||||
cd ../tool-testsuite
|
||||
mvn test
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=node.* test
|
||||
set -euo pipefail
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=javascript.* test
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
php_path=$(which php)
|
||||
|
||||
composer install -d ../runtime/PHP
|
||||
|
||||
mvn -q -DPHP_PATH="${php_path}" -Dparallel=methods -DthreadCount=4 -Dtest=php.* test
|
|
@ -1,3 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
python --version
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=python2.* test
|
||||
|
||||
cd ../runtime/Python2/tests
|
||||
|
||||
python run.py
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
python3 --version
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=python3.* test
|
||||
|
||||
cd ../runtime/Python3/test
|
||||
|
||||
python3 run.py
|
||||
|
|
|
@ -6,19 +6,20 @@ set -euo pipefail
|
|||
# here since environment variables doesn't pass
|
||||
# across scripts
|
||||
if [ $TRAVIS_OS_NAME == "linux" ]; then
|
||||
export SWIFT_VERSION=swift-4.0.2
|
||||
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu14.04/usr/bin/
|
||||
export SWIFT_VERSION=swift-5.0.1
|
||||
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu16.04/usr/bin/
|
||||
export PATH=$SWIFT_HOME:$PATH
|
||||
|
||||
# download swift
|
||||
mkdir swift
|
||||
curl https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1404/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu14.04.tar.gz -s | tar xz -C swift &> /dev/null
|
||||
curl https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1604/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu16.04.tar.gz -s | tar xz -C swift &> /dev/null
|
||||
fi
|
||||
|
||||
if [ -z "${JAVA_HOME-}" ]
|
||||
then
|
||||
export JAVA_HOME="$(dirname $(java -XshowSettings:properties -version 2>&1 |
|
||||
grep 'java\.home' | awk '{ print $3 }'))"
|
||||
export JAVA_HOME="$(java -XshowSettings:properties -version 2>&1 |
|
||||
grep 'java\.home' | awk '{ print $3 }')"
|
||||
echo "export JAVA_HOME=$JAVA_HOME"
|
||||
fi
|
||||
|
||||
# check swift
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# ANTLR v4
|
||||
|
||||
[![Build Travis-CI Status](https://travis-ci.org/antlr/antlr4.png?branch=master)](https://travis-ci.org/antlr/antlr4) [![Build AppVeyor Status](https://ci.appveyor.com/api/projects/status/5acpbx1pg7bhgh8v/branch/master?svg=true)](https://ci.appveyor.com/project/parrt/antlr4) [![Java 7+](https://img.shields.io/badge/java-7+-4c7e9f.svg)](http://java.oracle.com) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/antlr/antlr4/master/LICENSE.txt)
|
||||
[![Build Travis-CI Status](https://travis-ci.org/antlr/antlr4.svg?branch=master)](https://travis-ci.org/antlr/antlr4) [![Build AppVeyor Status](https://ci.appveyor.com/api/projects/status/5acpbx1pg7bhgh8v/branch/master?svg=true)](https://ci.appveyor.com/project/parrt/antlr4) [![Java 7+](https://img.shields.io/badge/java-7+-4c7e9f.svg)](http://java.oracle.com) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/antlr/antlr4/master/LICENSE.txt)
|
||||
|
||||
**ANTLR** (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build parse trees and also generates a listener interface (or visitor) that makes it easy to respond to the recognition of phrases of interest.
|
||||
|
||||
|
@ -22,6 +22,8 @@ ANTLR project lead and supreme dictator for life
|
|||
* [Janyou](https://github.com/janyou) (Swift target)
|
||||
* [Ewan Mellor](https://github.com/ewanmellor), [Hanzhou Shi](https://github.com/hanjoes) (Swift target merging)
|
||||
* [Ben Hamilton](https://github.com/bhamiltoncx) (Full Unicode support in serialized ATN and all languages' runtimes for code points > U+FFFF)
|
||||
* [Marcos Passos](https://github.com/marcospassos) (PHP target)
|
||||
* [Lingyu Li](https://github.com/lingyv-li) (Dart target)
|
||||
|
||||
## Useful information
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
|
|
@ -4,6 +4,11 @@ cache:
|
|||
- '%USERPROFILE%\.nuget\packages -> **\project.json'
|
||||
image: Visual Studio 2017
|
||||
build: off
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
- cinst -y php --params "/InstallDir:C:\tools\php"
|
||||
- cinst -y composer
|
||||
- cinst -y dart-sdk --version=2.8.4
|
||||
build_script:
|
||||
- mvn -DskipTests install --batch-mode
|
||||
- msbuild /target:restore /target:rebuild /property:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /verbosity:detailed runtime/CSharp/runtime/CSharp/Antlr4.dotnet.sln
|
||||
|
@ -11,7 +16,7 @@ build_script:
|
|||
after_build:
|
||||
- msbuild /target:pack /property:Configuration=Release /verbosity:detailed runtime/CSharp/runtime/CSharp/Antlr4.dotnet.sln
|
||||
test_script:
|
||||
- mvn install -Dantlr-python2-python="C:\Python27\python.exe" -Dantlr-python3-python="C:\Python35\python.exe" -Dantlr-javascript-nodejs="C:\Program Files (x86)\nodejs\node.exe" --batch-mode
|
||||
- mvn install -Dantlr-php-php="C:\tools\php\php.exe" -Dantlr-dart-dart="C:\tools\dart-sdk\bin\dart.exe" -Dantlr-dart-pub="C:\tools\dart-sdk\bin\pub.bat" -Dantlr-dart-dart2native="C:\tools\dart-sdk\bin\dart2native.bat" -Dantlr-python2-python="C:\Python27\python.exe" -Dantlr-python3-python="C:\Python35\python.exe" -Dantlr-javascript-nodejs="C:\Program Files (x86)\nodejs\node.exe" --batch-mode
|
||||
artifacts:
|
||||
- path: 'runtime\**\*.nupkg'
|
||||
name: NuGet
|
|
@ -1,5 +1,9 @@
|
|||
ANTLR Project Contributors Certification of Origin and Rights
|
||||
|
||||
NOTE: This tool is mature and Terence is mostly occupied elsewhere. We
|
||||
can't accept any changes that could have widespread effects on thousands
|
||||
of existing projects. Sorry!
|
||||
|
||||
All contributors to ANTLR v4 must formally agree to abide by this
|
||||
certificate of origin by signing on the bottom with their github
|
||||
userid, full name, email address (you can obscure your e-mail, but it
|
||||
|
@ -178,11 +182,22 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2017/12/01, DavidMoraisFerreira, David Morais Ferreira, david.moraisferreira@gmail.com
|
||||
2017/12/01, SebastianLng, Sebastian Lang, sebastian.lang@outlook.com
|
||||
2017/12/03, oranoran, Oran Epelbaum, oran / epelbaum me
|
||||
2017/12/12, janlinde, Jan Lindemann, jan@janware.com
|
||||
2017/12/13, enessoylu, Enes Soylu, enessoylutr@gmail.com
|
||||
2017/12/20, kbsletten, Kyle Sletten, kbsletten@gmail.com
|
||||
2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com
|
||||
2018/03/08, dannoc, Daniel Clifford, danno@google.com
|
||||
2018/03/10, uvguy, kangjoni76@gmail.com
|
||||
2018/01/06, kasbah, Kaspar Emanuel, kaspar@monostable.co.uk
|
||||
2018/01/15, xgcssch, Sönke Schau, xgcssch@users.noreply.github.com
|
||||
2018/02/08, razfriman, Raz Friman, raz@razfriman.com
|
||||
2018/02/11, io7m, Mark Raynsford, code@io7m.com
|
||||
2018/04/24, solussd, Joe Smith, joe@uwcreations.com
|
||||
2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com
|
||||
2018/06/14, scadgek, Sergey Chupov, scadgek@live.com
|
||||
2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com
|
||||
2018/06/27, wu-sheng, Wu Sheng, wu.sheng@foxmail.com
|
||||
2018/02/25, chaseoxide, Marcus Ong, taccs97[at]gmail[dot]com
|
||||
2018/05/15, johnvanderholt, jan dillingh johnvanderholte@gmail.com
|
||||
2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com
|
||||
2018/05/15, johnvanderholt, jan dillingh johnvanderholte@gmail.com
|
||||
|
@ -193,4 +208,55 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2018/07/03, jgoppert, James Goppert, james.goppert@gmail.com
|
||||
2018/07/27, Maksim Novikov, mnovikov.work@gmail.com
|
||||
2018/08/03, ENDOH takanao, djmchl@gmail.com
|
||||
2018/10/08, xsIceman, Andreas Skaar, andreas.skaar@gmail.com
|
||||
2018/10/08, xsIceman, Andreas Skaar, andreas.skaar@gmail.com
|
||||
2018/10/18, edirgarcia, Edir García Lazo, edirgl@hotmail.com
|
||||
2018/07/31, Lucas Henrqiue, lucashenrique580@gmail.com
|
||||
2018/08/03, ENDOH takanao, djmchl@gmail.com
|
||||
2018/10/29, chrisaycock, Christopher Aycock, chris[at]chrisaycock[dot]com
|
||||
2018/11/12, vinoski, Steve Vinoski, vinoski@ieee.org
|
||||
2018/11/14, nxtstep, Adriaan (Arjan) Duz, codewithadriaan[et]gmail[dot]com
|
||||
2018/11/15, amykyta3, Alex Mykyta, amykyta3@users.noreply.github.com
|
||||
2018/11/29, hannemann-tamas, Ralf Hannemann-Tamas, ralf.ht@gmail.com
|
||||
2018/12/20, WalterCouto, Walter Couto, WalterCouto@users.noreply.github.com
|
||||
2018/12/23, youkaichao, Kaichao You, youkaichao@gmail.com
|
||||
2019/01/16, kuegi, Markus Zancolo, markus.zancolo@roomle.com
|
||||
2019/02/06, ralucado, Cristina Raluca Vijulie, ralucris.v[at]gmail[dot]com
|
||||
2019/02/23, gedimitr, Gerasimos Dimitriadis, gedimitr@gmail.com
|
||||
2019/03/13, base698, Justin Thomas, justin.thomas1@gmail.com
|
||||
2019/03/18, carlodri, Carlo Dri, carlo.dri@gmail.com
|
||||
2019/05/02, askingalot, Andy Collins, askingalot@gmail.com
|
||||
2019/07/11, olowo726, Olof Wolgast, olof@baah.se
|
||||
2019/07/16, abhijithneilabraham, Abhijith Neil Abraham, abhijithneilabrahampk@gmail.com
|
||||
2019/07/26, Braavos96, Eric Hettiaratchi, erichettiaratchi@gmail.com
|
||||
2019/08/23, akaJes, Oleksandr Mamchyts, akaJes@gmail.com
|
||||
2019/09/10, ImanHosseini, Iman Hosseini, hosseini.iman@yahoo.com
|
||||
2019/09/03, João Henrique, johnnyonflame@hotmail.com
|
||||
2019/09/10, neko1235, Ihar Mokharau, igor.mohorev@gmail.com
|
||||
2019/09/10, yar3333, Yaroslav Sivakov, yar3333@gmail.com
|
||||
2019/09/10, marcospassos, Marcos Passos, marcospassos.com@gmail.com
|
||||
2019/09/10, amorimjuliana, Juliana Amorim, juu.amorim@gmail.com
|
||||
2019/09/17, kaz, Kazuki Sawada, kazuki@6715.jp
|
||||
2019/09/28, lmy269, Mingyang Liu, lmy040758@gmail.com
|
||||
2019/10/29, tehbone, Tabari Alexander, tehbone@gmail.com
|
||||
2019/10/31, a-square, Alexei Averchenko, lex.aver@gmail.com
|
||||
2019/11/11, foxeverl, Liu Xinfeng, liuxf1986[at]gmail[dot]com
|
||||
2019/11/17, felixn, Felix Nieuwenhuizhen, felix@tdlrali.com
|
||||
2019/11/18, mlilback, Mark Lilback, mark@lilback.com
|
||||
2020/01/19, lingyv-li, Lingyu Li, lingyv.li@gmail.com
|
||||
2020/02/02, carocad, Camilo Roca, carocad@unal.edu.co
|
||||
2020/02/10, julibert, Julián Bermúdez Ortega, julibert.dev@gmail.com
|
||||
2020/02/21, StochasticTinkr, Daniel Pitts, github@coloraura.com
|
||||
2020/03/17, XsongyangX, Song Yang, songyang1218@gmail.com
|
||||
2020/04/07, deniskyashif, Denis Kyashif, denis.kyashif@gmail.com
|
||||
2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com
|
||||
2020/06/04, sigmasoldi3r, Pablo Blanco, pablobc.1995@gmail.com
|
||||
2020/05/25, graknol, Sindre van der Linden, graknol@gmail.com
|
||||
2020/05/31, d-markey, David Markey, dmarkey@free.fr
|
||||
2020/06/02, cohomology, Kilian Kilger, kkilger AT gmail.com
|
||||
2020/06/04, IohannRabeson, Iohann Rabeson, iotaka6@gmail.com
|
||||
2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com
|
||||
2020/08/22, stevenjohnstone, Steven Johnstone, steven.james.johnstone@gmail.com
|
||||
2020/09/06, ArthurSonzogni, Sonzogni Arthur, arthursonzogni@gmail.com
|
||||
2020/09/12, Clcanny, Charles Ruan, a837940593@gmail.com
|
||||
2020/09/15, rmcgregor1990, Robert McGregor, rmcgregor1990@gmail.com
|
||||
2020/10/08, Marti2203, Martin Mirchev, mirchevmartin2203@gmail.com
|
|
@ -42,9 +42,9 @@ In order to perform the tests on all target languages, you need to have the foll
|
|||
* `mono` (e.g., `brew install mono`) on non-Windows boxes (on Windows it uses the Microsoft .net stack). Also must [`xbuild` the runtime](https://github.com/antlr/antlr4/blob/master/doc/releasing-antlr.md) before tests will run; see below
|
||||
* `nodejs`
|
||||
* Python 2.7
|
||||
* Python 3.5
|
||||
* Python 3.6
|
||||
* Go
|
||||
* Swift 3 (via XCode 8.x) tested currently only osx
|
||||
* Swift 4 (via XCode 10.x) tested currently only osx
|
||||
* clang (for C++ target)
|
||||
*
|
||||
To **install into local repository** `~/.m2/repository/org/antlr`, do this:
|
||||
|
|
|
@ -28,16 +28,7 @@ Checking out files: 100% (1427/1427), done.
|
|||
# Compile
|
||||
|
||||
```bash
|
||||
$ cd /tmp
|
||||
$ git clone git@github.com:antlr/antlr4.git
|
||||
Cloning into 'antlr4'...
|
||||
remote: Counting objects: 59858, done.
|
||||
remote: Compressing objects: 100% (57/57), done.
|
||||
remote: Total 59858 (delta 28), reused 9 (delta 9), pack-reused 59786
|
||||
Receiving objects: 100% (59858/59858), 31.10 MiB | 819.00 KiB/s, done.
|
||||
Resolving deltas: 100% (31898/31898), done.
|
||||
Checking connectivity... done.
|
||||
$ cd antlr4
|
||||
$ cd /tmp/antlr4
|
||||
$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
|
||||
$ mvn clean # must be separate, not part of install/compile
|
||||
$ mvn -DskipTests install
|
||||
|
|
|
@ -14,7 +14,7 @@ For the 4.7.1 release, we discussed both approaches in [detail](https://github.c
|
|||
|
||||
## Case-insensitive grammars
|
||||
|
||||
As a prime example of a grammar that specifically describes case insensitive keywords, see the
|
||||
As a prime example of a grammar that specifically describes case insensitive keywords, see the
|
||||
[SQLite grammar](https://github.com/antlr/grammars-v4/blob/master/sqlite/SQLite.g4). To match a case insensitive keyword, there are rules such as
|
||||
|
||||
```
|
||||
|
@ -72,7 +72,8 @@ Lexer lexer = new SomeSQLLexer(upper);
|
|||
|
||||
Here are implementations of `CaseChangingCharStream` in various target languages:
|
||||
|
||||
* [Java](https://github.com/parrt/antlr4/blob/case-insensitivity-doc/doc/resources/CaseChangingCharStream.java)
|
||||
* [JavaScript](https://github.com/parrt/antlr4/blob/case-insensitivity-doc/doc/resources/CaseInsensitiveInputStream.js)
|
||||
* [Go](https://github.com/parrt/antlr4/blob/case-insensitivity-doc/doc/resources/case_changing_stream.go)
|
||||
* [C#](https://github.com/parrt/antlr4/blob/case-insensitivity-doc/doc/resources/CaseChangingCharStream.cs)
|
||||
* [C#](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingCharStream.cs)
|
||||
* [Go](https://github.com/antlr/antlr4/blob/master/doc/resources/case_changing_stream.go)
|
||||
* [Java](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingCharStream.java)
|
||||
* [JavaScript](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingStream.js)
|
||||
* [Python2/3](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingStream.py)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# C++
|
||||
|
||||
The C++ target supports all platforms that can either run MS Visual Studio 2013 (or newer), XCode 7 (or newer) or CMake (C++11 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](http://blorente.me//Antlr-,-C++-and-CMake-Wait-what.html).
|
||||
The C++ target supports all platforms that can either run MS Visual Studio 2013 (or newer), XCode 7 (or newer) or CMake (C++11 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](https://beyondtheloop.dev/Antlr-cpp-cmake/).
|
||||
|
||||
## How to create a C++ lexer or parser?
|
||||
This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:
|
||||
|
@ -45,7 +45,7 @@ The generation step above created a listener and base listener class for you. Th
|
|||
#include "MyGrammarParser.h"
|
||||
#include "MyGrammarBaseListener.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace antlr4;
|
||||
|
||||
class TreeShapeListener : public MyGrammarBaseListener {
|
||||
public:
|
||||
|
@ -65,7 +65,7 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
tree::ParseTree *tree = parser.key();
|
||||
TreeShapeListener listener;
|
||||
tree::ParseTreeWalker::DEFAULT->walk(&listener, tree);
|
||||
tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ Creating a new target involves the following key elements:
|
|||
1. Create *X*.stg in directory tool/resources/org/antlr/v4/tool/templates/codegen/*X*/*X*.stg. This is a [StringTemplate](http://www.stringtemplate.org/) group file (`.stg`) that tells ANTLR how to express all of the parsing elements needed to generate code. You will see templates called `ParserFile`, `Parser`, `Lexer`, `CodeBlockForAlt`, `AltBlock`, etc... Each of these must be described how to build the indicated chunk of code. Your best bet is to find the closest existing target, copy that template file, and tweak to suit.
|
||||
1. Create a runtime library to support the parsers generated by ANTLR. Under directory runtime/*X*, you are in complete control of the directory structure as dictated by common usage of that target language. For example, Java has: `runtime/Java/lib` and `runtime/Java/src` directories. Under `src`, you will find a directory structure for package `org.antlr.v4.runtime` and below.
|
||||
1. Create a template file for runtime tests. All you have to do is provide a few templates that indicate how to print values and declare variables. Our runtime test mechanism in dir `runtime-testsuite` will automatically generate code using these templates for each target and check the test results. It needs to know how to define various class fields, compare members and so on. You must create a *X*.test.stg file underneath [runtime-testsuite/resources/org/antlr/v4/test/runtime](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/resources/org/antlr/v4/test/runtime). Again, your best bet is to copy the templates from the closest language to your target and tweak it to suit.
|
||||
1. Create test files under [/runtime-testsuite/test/org/antlr/v4/test/runtime](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/test/org/antlr/v4/test/runtime). They will load defined test cases in each test descriptor. Also add the `/runtime-testsuite/test/org/antlr/v4/test/runtime/X/BaseXTest.java` which defines how test cases will execute and output.
|
||||
1. Create/edit shell scripts in [/.travis](https://github.com/antlr/antlr4/blob/master/.travis) and [/appveyor.yml](https://github.com/antlr/antlr4/blob/master/appveyor.yml) to run tests in CI pipelines.
|
||||
|
||||
## Getting started
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ Let's suppose that your grammar is named `MyGrammar`. The tool will generate for
|
|||
|
||||
Now a fully functioning code might look like the following for start rule `StartRule`:
|
||||
|
||||
```
|
||||
```csharp
|
||||
using Antlr4.Runtime;
|
||||
using Antlr4.Runtime.Tree;
|
||||
|
||||
|
@ -59,7 +59,7 @@ Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value".
|
|||
|
||||
The antlr4 tool will have generated the following listener (only partial code shown here):
|
||||
|
||||
```
|
||||
```csharp
|
||||
interface IMyGrammarParserListener : IParseTreeListener {
|
||||
void EnterKey (MyGrammarParser.KeyContext context);
|
||||
void ExitKey (MyGrammarParser.KeyContext context);
|
||||
|
@ -70,7 +70,7 @@ interface IMyGrammarParserListener : IParseTreeListener {
|
|||
|
||||
In order to provide custom behavior, you might want to create the following class:
|
||||
|
||||
```
|
||||
```csharp
|
||||
class KeyPrinter : MyGrammarBaseListener {
|
||||
// override default listener behavior
|
||||
void ExitKey (MyGrammarParser.KeyContext context) {
|
||||
|
@ -82,7 +82,7 @@ class KeyPrinter : MyGrammarBaseListener {
|
|||
In order to execute this listener, you would simply add the following lines to the above code:
|
||||
|
||||
|
||||
```
|
||||
```csharp
|
||||
...
|
||||
IParseTree tree = parser.StartRule() - only repeated here for reference
|
||||
KeyPrinter printer = new KeyPrinter();
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
# ANTLR4 Runtime for Dart
|
||||
|
||||
Notice: Dart target may generate code incompatible with Dart 2.9 sound null safety. Please set the minimum SDK constraint to 2.8.4 or lower if such violation is found. Contributions are welcomed.
|
||||
|
||||
### First steps
|
||||
|
||||
#### 1. Install ANTLR4
|
||||
|
||||
[The getting started guide](https://github.com/antlr/antlr4/blob/master/doc/getting-started.md)
|
||||
should get you started.
|
||||
|
||||
#### 2. Install the Dart ANTLR runtime
|
||||
|
||||
Each target language for ANTLR has a runtime package for running parser
|
||||
generated by ANTLR4. The runtime provides a common set of tools for using your parser.
|
||||
|
||||
Install the runtime with the same version as the main ANTLR tool:
|
||||
|
||||
Add this to your package's pubspec.yaml file:
|
||||
```yaml
|
||||
...
|
||||
dependencies:
|
||||
antlr4: <ANTLR version>
|
||||
...
|
||||
```
|
||||
|
||||
#### 3. Generate your parser
|
||||
|
||||
You use the ANTLR4 "tool" to generate a parser. These will reference the ANTLR
|
||||
runtime, installed above.
|
||||
|
||||
Suppose you're using a UNIX system and have set up an alias for the ANTLR4 tool
|
||||
as described in [the getting started guide](https://github.com/antlr/antlr4/blob/master/doc/getting-started.md).
|
||||
To generate your Dart parser, run the following command:
|
||||
|
||||
```shell script
|
||||
antlr4 -Dlanguage=Dart MyGrammar.g4
|
||||
```
|
||||
|
||||
For a full list of antlr4 tool options, please visit the
|
||||
[tool documentation page](https://github.com/antlr/antlr4/blob/master/doc/tool-options.md).
|
||||
|
||||
### Complete example
|
||||
|
||||
Suppose you're using the JSON grammar from https://github.com/antlr/grammars-v4/tree/master/json.
|
||||
|
||||
Then, invoke `antlr4 -Dlanguage=Dart JSON.g4`. The result of this is a
|
||||
collection of `.dart` including:
|
||||
|
||||
* JsonLexer.dart
|
||||
* JsonParser.dart
|
||||
* JsonBaseListener.dart
|
||||
* JsonListener.dart (if you have not activated the -no-listener option)
|
||||
* JsonVisitor.dart (if you have activated the -visitor option)
|
||||
|
||||
We'll write a small main func to call the generated parser/lexer
|
||||
(assuming they are separate). This one writes out the encountered
|
||||
`ParseTreeContext`'s:
|
||||
|
||||
```dart
|
||||
import 'package:antlr4/antlr4.dart';
|
||||
import 'package:my_project/JSONParser.dart';
|
||||
import 'package:my_project/JSONLexer.dart';
|
||||
|
||||
class TreeShapeListener implements ParseTreeListener {
|
||||
@override
|
||||
void enterEveryRule(ParserRuleContext ctx) {
|
||||
print(ctx.text);
|
||||
}
|
||||
|
||||
@override
|
||||
void exitEveryRule(ParserRuleContext node) {
|
||||
}
|
||||
|
||||
@override
|
||||
void visitErrorNode(ErrorNode node) {
|
||||
}
|
||||
|
||||
@override
|
||||
void visitTerminal(TerminalNode node) {
|
||||
}
|
||||
}
|
||||
|
||||
void main(List<String> args) async {
|
||||
JSONLexer.checkVersion();
|
||||
JSONParser.checkVersion();
|
||||
final input = await InputStream.fromPath(args[0]);
|
||||
final lexer = JSONLexer(input);
|
||||
final tokens = CommonTokenStream(lexer);
|
||||
final parser = JSONParser(tokens);
|
||||
parser.addErrorListener(DiagnosticErrorListener());
|
||||
parser.buildParseTree = true;
|
||||
final tree = parser.json();
|
||||
ParseTreeWalker.DEFAULT.walk(TreeShapeListener(), tree);
|
||||
}
|
||||
```
|
||||
|
||||
Create a `example.json` file:
|
||||
```json
|
||||
{"a":1}
|
||||
```
|
||||
|
||||
Parse the input file:
|
||||
|
||||
```shell script
|
||||
dart bin/main.dart example.json
|
||||
```
|
||||
|
||||
The expected output is:
|
||||
|
||||
```
|
||||
{"a":1}
|
||||
{"a":1}
|
||||
{"a":1}
|
||||
"a":1
|
||||
1
|
||||
```
|
|
@ -16,10 +16,10 @@ 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.7.1-complete.jar
|
||||
$ curl -O https://www.antlr.org/download/antlr-4.7.1-complete.jar
|
||||
```
|
||||
Or just download in browser from website:
|
||||
[http://www.antlr.org/download.html](http://www.antlr.org/download.html)
|
||||
[https://www.antlr.org/download.html](https://www.antlr.org/download.html)
|
||||
and put it somewhere rational like `/usr/local/lib`.
|
||||
|
||||
2. Add `antlr-4.7.1-complete.jar` to your `CLASSPATH`:
|
||||
|
@ -31,7 +31,7 @@ It's also a good idea to put this in your `.bash_profile` or whatever your start
|
|||
3. Create aliases for the ANTLR Tool, and `TestRig`.
|
||||
```
|
||||
$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
|
||||
$ alias grun='java org.antlr.v4.gui.TestRig'
|
||||
$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
|
||||
```
|
||||
|
||||
### WINDOWS
|
||||
|
@ -39,9 +39,9 @@ $ alias grun='java org.antlr.v4.gui.TestRig'
|
|||
(*Thanks to Graham Wideman*)
|
||||
|
||||
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/)
|
||||
1. Download antlr-4.7.1-complete.jar (or whatever version) from [https://www.antlr.org/download/](https://www.antlr.org/download/)
|
||||
Save to your directory for 3rd party Java libraries, say `C:\Javalib`
|
||||
2. Add `antlr-4.5.3-complete.jar` to CLASSPATH, either:
|
||||
2. Add `antlr-4.7.1-complete.jar` to CLASSPATH, either:
|
||||
* Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable
|
||||
* Temporarily, at command line:
|
||||
```
|
||||
|
@ -53,6 +53,10 @@ SET CLASSPATH=.;C:\Javalib\antlr-4.7.1-complete.jar;%CLASSPATH%
|
|||
java org.antlr.v4.Tool %*
|
||||
```
|
||||
```
|
||||
@ECHO OFF
|
||||
SET TEST_CURRENT_DIR=%CLASSPATH:.;=%
|
||||
if "%TEST_CURRENT_DIR%" == "%CLASSPATH%" ( SET CLASSPATH=.;%CLASSPATH% )
|
||||
@ECHO ON
|
||||
java org.antlr.v4.gui.TestRig %*
|
||||
```
|
||||
* Or, use doskey commands:
|
||||
|
@ -108,8 +112,11 @@ Now test it:
|
|||
|
||||
```
|
||||
$ grun Hello r -tree
|
||||
(Now enter something like the string below)
|
||||
hello parrt
|
||||
(now,do:)
|
||||
^D
|
||||
(The output:)
|
||||
(r hello parrt)
|
||||
(That ^D means EOF on unix; it's ^Z in Windows.) The -tree option prints the parse tree in LISP notation.
|
||||
It's nicer to look at parse trees visually.
|
||||
|
|
|
@ -21,6 +21,8 @@ This documentation is a reference and summarizes grammar syntax and the key sema
|
|||
|
||||
<a href="https://vimeo.com/59285751"><img src=images/tertalk.png width=200></a>
|
||||
|
||||
For those using Java, here's a great [set of ANTLR in Intellij notes](https://docs.google.com/document/d/1gQ2lsidvN2cDUUsHEkT05L-wGbX5mROB7d70Aaj3R64/edit#heading=h.xr0jj8vcdsgc) by Andreas Stefik.
|
||||
|
||||
## Sections
|
||||
|
||||
* [Getting Started with ANTLR v4](getting-started.md)
|
||||
|
|
|
@ -16,7 +16,7 @@ Also, I have prepared a [video](https://youtu.be/eW4WFgRtFeY) that will help you
|
|||
|
||||
### Eclipse
|
||||
|
||||
Edgar Espina has created an [eclipse plugin for ANTLR v4](https://youtu.be/eW4WFgRtFeY). Features: Advanced Syntax Highlighting, Automatic Code Generation (on save), Manual Code Generation (through External Tools menu), Code Formatter (Ctrl+Shift+F), Syntax Diagrams, Advanced Rule Navigation between files (F3), Quick fixes.
|
||||
Edgar Espina has created an [eclipse plugin for ANTLR v4](https://marketplace.eclipse.org/content/antlr-ide). Features: Advanced Syntax Highlighting, Automatic Code Generation (on save), Manual Code Generation (through External Tools menu), Code Formatter (Ctrl+Shift+F), Syntax Diagrams, Advanced Rule Navigation between files (F3), Quick fixes.
|
||||
|
||||
### NetBeans
|
||||
|
||||
|
@ -241,4 +241,4 @@ mvn install
|
|||
mvn exec:java -Dexec.mainClass=org.abcd.examples.ArrayInit.ArrayInit
|
||||
{1,2,3}
|
||||
^D
|
||||
```
|
||||
```
|
||||
|
|
|
@ -15,7 +15,7 @@ The tests were conducted using Selenium. No issue was found, so you should find
|
|||
|
||||
## Is NodeJS supported?
|
||||
|
||||
The runtime has also been extensively tested against Node.js 0.12.7. No issue was found.
|
||||
The runtime has also been extensively tested against Node.js 10 LTS. No issue was found.
|
||||
|
||||
## How to create a JavaScript lexer or parser?
|
||||
|
||||
|
@ -55,32 +55,17 @@ You can get [information on webpack here](https://webpack.github.io).
|
|||
|
||||
The steps to create your parsing code are the following:
|
||||
- generate your lexer, parser, listener and visitor using the antlr tool
|
||||
- write your parse tree handling code by providig your custom listener or visitor, and associated code, using 'require' to load antlr.
|
||||
- write your parse tree handling code by providing your custom listener or visitor, and associated code, using 'require' to load antlr.
|
||||
- create an index.js file with the entry point to your parsing code (or several if required).
|
||||
- test your parsing logic thoroughly using node.js
|
||||
|
||||
You are now ready to bundle your parsing code as follows:
|
||||
- following webpack specs, create a webpack.config file
|
||||
- in the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" }
|
||||
- in the `webpack.config` file, exclude node.js only modules using: `node: { module: "empty", net: "empty", fs: "empty" }`
|
||||
- from the cmd line, navigate to the directory containing webpack.config and type: webpack
|
||||
|
||||
This will produce a single js file containing all your parsing code. Easy to include in your web pages!
|
||||
|
||||
If you can't use webpack, you can use the lib/require.js script which implements the Node.js 'require' function in brwsers.
|
||||
|
||||
This script is provided by Torben Haase, and is NOT part of ANTLR JavaScript runtime.
|
||||
|
||||
Assuming you have, at the root of your web site, both the 'antlr4' directory and a 'lib' directory with 'require.js' inside it, all you need to put in your HTML header is the following:
|
||||
|
||||
```xml
|
||||
<script src='lib/require.js'>
|
||||
<script>
|
||||
var antlr4 = require('antlr4/index');
|
||||
</script>
|
||||
```
|
||||
|
||||
This will load the runtime asynchronously.
|
||||
|
||||
## How do I run the generated lexer and/or parser?
|
||||
|
||||
Let's suppose that your grammar is named, as above, "MyGrammar". Let's suppose this parser comprises a rule named "StartRule". The tool will have generated for you the following files:
|
||||
|
@ -117,6 +102,44 @@ This program will work. But it won't be useful unless you do one of the followin
|
|||
|
||||
(please note that production code is target specific, so you can't have multi target grammars that include production code)
|
||||
|
||||
## How do I create and run a visitor?
|
||||
```javascript
|
||||
// test.js
|
||||
var antlr4 = require('antlr4');
|
||||
var MyGrammarLexer = require('./QueryLexer').QueryLexer;
|
||||
var MyGrammarParser = require('./QueryParser').QueryParser;
|
||||
var MyGrammarListener = require('./QueryListener').QueryListener;
|
||||
|
||||
|
||||
var input = "field = 123 AND items in (1,2,3)"
|
||||
var chars = new antlr4.InputStream(input);
|
||||
var lexer = new MyGrammarLexer(chars);
|
||||
var tokens = new antlr4.CommonTokenStream(lexer);
|
||||
var parser = new MyGrammarParser(tokens);
|
||||
parser.buildParseTrees = true;
|
||||
var tree = parser.query();
|
||||
|
||||
class Visitor {
|
||||
visitChildren(ctx) {
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.children) {
|
||||
return ctx.children.map(child => {
|
||||
if (child.children && child.children.length != 0) {
|
||||
return child.accept(this);
|
||||
} else {
|
||||
return child.getText();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tree.accept(new Visitor());
|
||||
````
|
||||
|
||||
## How do I create and run a custom listener?
|
||||
|
||||
Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value". The antlr4 tool will have generated the following listener:
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
# ANTLR4 Runtime for PHP
|
||||
|
||||
### First steps
|
||||
|
||||
#### 1. Install ANTLR4
|
||||
|
||||
[The getting started guide](https://github.com/antlr/antlr4/blob/master/doc/getting-started.md)
|
||||
should get you started.
|
||||
|
||||
#### 2. Install the PHP ANTLR runtime
|
||||
|
||||
Each target language for ANTLR has a runtime package for running parser
|
||||
generated by ANTLR4. The runtime provides a common set of tools for using your parser.
|
||||
|
||||
Install the runtime with Composer:
|
||||
|
||||
```bash
|
||||
composer install antlr/antlr4
|
||||
```
|
||||
|
||||
#### 3. Generate your parser
|
||||
|
||||
You use the ANTLR4 "tool" to generate a parser. These will reference the ANTLR
|
||||
runtime, installed above.
|
||||
|
||||
Suppose you're using a UNIX system and have set up an alias for the ANTLR4 tool
|
||||
as described in [the getting started guide](https://github.com/antlr/antlr4/blob/master/doc/getting-started.md).
|
||||
To generate your PHP parser, run the following command:
|
||||
|
||||
```bash
|
||||
antlr4 -Dlanguage=PHP MyGrammar.g4
|
||||
```
|
||||
|
||||
For a full list of antlr4 tool options, please visit the
|
||||
[tool documentation page](https://github.com/antlr/antlr4/blob/master/doc/tool-options.md).
|
||||
|
||||
### Complete example
|
||||
|
||||
Suppose you're using the JSON grammar from https://github.com/antlr/grammars-v4/tree/master/json.
|
||||
|
||||
Then, invoke `antlr4 -Dlanguage=PHP JSON.g4`. The result of this is a
|
||||
collection of `.php` files in the `parser` directory including:
|
||||
```
|
||||
JsonParser.php
|
||||
JsonBaseListener.php
|
||||
JsonLexer.php
|
||||
JsonListener.php
|
||||
```
|
||||
|
||||
Another common option to the ANTLR tool is `-visitor`, which generates a parse
|
||||
tree visitor, but we won't be doing that here. For a full list of antlr4 tool
|
||||
options, please visit the [tool documentation page](tool-options.md).
|
||||
|
||||
We'll write a small main func to call the generated parser/lexer
|
||||
(assuming they are separate). This one writes out the encountered
|
||||
`ParseTreeContext`'s:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace JsonParser;
|
||||
|
||||
use Antlr\Antlr4\Runtime\CommonTokenStream;
|
||||
use Antlr\Antlr4\Runtime\Error\Listeners\DiagnosticErrorListener;
|
||||
use Antlr\Antlr4\Runtime\InputStream;
|
||||
use Antlr\Antlr4\Runtime\ParserRuleContext;
|
||||
use Antlr\Antlr4\Runtime\Tree\ErrorNode;
|
||||
use Antlr\Antlr4\Runtime\Tree\ParseTreeListener;
|
||||
use Antlr\Antlr4\Runtime\Tree\ParseTreeWalker;
|
||||
use Antlr\Antlr4\Runtime\Tree\TerminalNode;
|
||||
|
||||
final class TreeShapeListener implements ParseTreeListener {
|
||||
public function visitTerminal(TerminalNode $node) : void {}
|
||||
public function visitErrorNode(ErrorNode $node) : void {}
|
||||
public function exitEveryRule(ParserRuleContext $ctx) : void {}
|
||||
|
||||
public function enterEveryRule(ParserRuleContext $ctx) : void {
|
||||
echo $ctx->getText();
|
||||
}
|
||||
}
|
||||
|
||||
$input = InputStream::fromPath($argv[1]);
|
||||
$lexer = new JSONLexer($input);
|
||||
$tokens = new CommonTokenStream($lexer);
|
||||
$parser = new JSONParser($tokens);
|
||||
$parser->addErrorListener(new DiagnosticErrorListener());
|
||||
$parser->setBuildParseTree(true);
|
||||
$tree = $parser->json();
|
||||
|
||||
ParseTreeWalker::default()->walk(new TreeShapeListener(), $tree);
|
||||
```
|
||||
|
||||
Create a `example.json` file:
|
||||
```json
|
||||
{"a":1}
|
||||
```
|
||||
|
||||
Parse the input file:
|
||||
|
||||
```
|
||||
php json.php example.json
|
||||
```
|
||||
|
||||
The expected output is:
|
||||
|
||||
```
|
||||
{"a":1}
|
||||
{"a":1}
|
||||
"a":1
|
||||
1
|
||||
```
|
|
@ -50,8 +50,8 @@ from MyGrammarLexer import MyGrammarLexer
|
|||
from MyGrammarParser import MyGrammarParser
|
||||
|
||||
def main(argv):
|
||||
input = FileStream(argv[1])
|
||||
lexer = MyGrammarLexer(input)
|
||||
input_stream = FileStream(argv[1])
|
||||
lexer = MyGrammarLexer(input_stream)
|
||||
stream = CommonTokenStream(lexer)
|
||||
parser = MyGrammarParser(stream)
|
||||
tree = parser.startRule()
|
||||
|
|
|
@ -9,17 +9,41 @@ Create a pre-release or full release at github; [Example 4.5-rc-1](https://githu
|
|||
Wack any existing tag as mvn will create one and it fails if already there.
|
||||
|
||||
```
|
||||
$ git tag -d 4.7
|
||||
$ git push origin :refs/tags/4.7
|
||||
$ git push upstream :refs/tags/4.7
|
||||
$ git tag -d 4.8
|
||||
$ git push origin :refs/tags/4.8
|
||||
$ git push upstream :refs/tags/4.8
|
||||
```
|
||||
|
||||
### Create release candidate tag
|
||||
|
||||
```bash
|
||||
$ git tag -a 4.7-rc1 -m 'heading towards 4.7'
|
||||
$ git push origin 4.7-rc1
|
||||
$ git push upstream 4.7-rc1
|
||||
$ git tag -a 4.8-rc1 -m 'heading towards 4.8'
|
||||
$ git push origin 4.8-rc1
|
||||
$ git push upstream 4.8-rc1
|
||||
```
|
||||
|
||||
## Update submodules
|
||||
|
||||
Make sure you tell git to pull in the submodule (for every clone you do of antlr4):
|
||||
|
||||
```bash
|
||||
git submodule init
|
||||
```
|
||||
|
||||
Also bump version to 4.8 in `runtime/PHP/src/RuntimeMetaData.php`.
|
||||
|
||||
Update the runtime submodules by running the following command:
|
||||
|
||||
```bash
|
||||
git submodule update --recursive
|
||||
git submodule update --remote --merge # might only need this last one but do both
|
||||
```
|
||||
|
||||
Make sure these changes go back to antlr4 repo:
|
||||
|
||||
```bash
|
||||
git add runtime/PHP
|
||||
git commit -m "Update PHP Runtime to latest version"
|
||||
```
|
||||
|
||||
## Bump version
|
||||
|
@ -33,7 +57,7 @@ Edit the repository looking for 4.5 or whatever and update it. Bump version in t
|
|||
* runtime/Python3/src/antlr4/Recognizer.py
|
||||
* runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Properties/AssemblyInfo.cs
|
||||
* runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
* runtime/JavaScript/src/antlr4/package.json
|
||||
* runtime/JavaScript/package.json
|
||||
* runtime/JavaScript/src/antlr4/Recognizer.js
|
||||
* runtime/Cpp/VERSION
|
||||
* runtime/Cpp/runtime/src/RuntimeMetaData.cpp
|
||||
|
@ -41,6 +65,8 @@ Edit the repository looking for 4.5 or whatever and update it. Bump version in t
|
|||
* runtime/Cpp/demo/generate.cmd
|
||||
* runtime/Go/antlr/recognizer.go
|
||||
* runtime/Swift/Antlr4/org/antlr/v4/runtime/RuntimeMetaData.swift
|
||||
* runtime/Dart/lib/src/runtime_meta_data.dart
|
||||
* runtime/Dart/pubspec.yaml
|
||||
* tool/src/org/antlr/v4/codegen/target/GoTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/CppTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/CSharpTarget.java
|
||||
|
@ -59,6 +85,10 @@ find tool runtime -type f -exec grep -l '4\.6' {} \;
|
|||
|
||||
Commit to repository.
|
||||
|
||||
## Building
|
||||
|
||||
ugh. apparently you have to `mvn install` and then `mvn compile` or some such or subdir pom.xml's won't see the latest runtime build.
|
||||
|
||||
## Maven Repository Settings
|
||||
|
||||
First, make sure you have maven set up to communicate with staging servers etc... Create file `~/.m2/settings.xml` with appropriate username/password for staging server and gpg.keyname/passphrase for signing. Make sure it has strict visibility privileges to just you. On unix, it looks like:
|
||||
|
@ -106,7 +136,7 @@ Here is the file template
|
|||
|
||||
## Maven deploy snapshot
|
||||
|
||||
The goal is to get a snapshot, such as `4.7-SNAPSHOT`, to the staging server: [antlr4 tool](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4) and [antlr4 java runtime](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-runtime).
|
||||
The goal is to get a snapshot, such as `4.8-SNAPSHOT`, to the staging server: [antlr4 tool](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4) and [antlr4 java runtime](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-runtime).
|
||||
|
||||
Do this:
|
||||
|
||||
|
@ -114,15 +144,15 @@ Do this:
|
|||
$ mvn deploy -DskipTests
|
||||
...
|
||||
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ antlr4-tool-testsuite ---
|
||||
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/maven-metadata.xml
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/antlr4-tool-testsuite-4.7-20161211.173752-1.jar
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/antlr4-tool-testsuite-4.7-20161211.173752-1.jar (3 KB at 3.4 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/antlr4-tool-testsuite-4.7-20161211.173752-1.pom
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/antlr4-tool-testsuite-4.7-20161211.173752-1.pom (3 KB at 6.5 KB/sec)
|
||||
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/maven-metadata.xml
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/antlr4-tool-testsuite-4.8-20161211.173752-1.jar
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/antlr4-tool-testsuite-4.8-20161211.173752-1.jar (3 KB at 3.4 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/antlr4-tool-testsuite-4.8-20161211.173752-1.pom
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/antlr4-tool-testsuite-4.8-20161211.173752-1.pom (3 KB at 6.5 KB/sec)
|
||||
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
|
||||
Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (371 B at 1.4 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/maven-metadata.xml
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.7-SNAPSHOT/maven-metadata.xml (774 B at 1.8 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/maven-metadata.xml
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.8-SNAPSHOT/maven-metadata.xml (774 B at 1.8 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (388 B at 0.9 KB/sec)
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
|
@ -150,13 +180,13 @@ Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antl
|
|||
The maven deploy lifecycle phased deploys the artifacts and the poms for the ANTLR project to the [sonatype remote staging server](https://oss.sonatype.org/content/repositories/snapshots/).
|
||||
|
||||
```bash
|
||||
mvn deploy -DskipTests
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`; mvn deploy -DskipTests
|
||||
```
|
||||
|
||||
With JDK 1.7 (not 6 or 8), do this:
|
||||
|
||||
```bash
|
||||
mvn release:prepare -Darguments="-DskipTests"
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`; mvn release:prepare -Darguments="-DskipTests"
|
||||
```
|
||||
|
||||
Hm...per https://github.com/keybase/keybase-issues/issues/1712 we need this to make gpg work:
|
||||
|
@ -175,6 +205,12 @@ alias jar='/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/j
|
|||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
|
||||
```
|
||||
|
||||
But I think just this on front of mvn works:
|
||||
|
||||
```
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`; mvn ...
|
||||
```
|
||||
|
||||
You should see 0x33 in generated .class files after 0xCAFEBABE; see [Java SE 7 = 51 (0x33 hex)](https://en.wikipedia.org/wiki/Java_class_file):
|
||||
|
||||
```bash
|
||||
|
@ -186,18 +222,18 @@ It will start out by asking you the version number:
|
|||
|
||||
```
|
||||
...
|
||||
What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.7: : 4.7
|
||||
What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.7: :
|
||||
What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.7: :
|
||||
What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.7: :
|
||||
What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.7: :
|
||||
What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.7: :
|
||||
What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.7: : 4.7
|
||||
What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.7.1-SNAPSHOT:
|
||||
What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.8: : 4.8
|
||||
What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.8: :
|
||||
What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.8: :
|
||||
What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.8: :
|
||||
What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.8: :
|
||||
What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.8: :
|
||||
What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.8: : 4.8
|
||||
What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.8.1-SNAPSHOT:
|
||||
...
|
||||
```
|
||||
|
||||
Maven will go through your pom.xml files to update versions from 4.7-SNAPSHOT to 4.7 for release and then to 4.7.1-SNAPSHOT after release, which is done with:
|
||||
Maven will go through your pom.xml files to update versions from 4.8-SNAPSHOT to 4.8 for release and then to 4.8.1-SNAPSHOT after release, which is done with:
|
||||
|
||||
```bash
|
||||
mvn release:perform -Darguments="-DskipTests"
|
||||
|
@ -211,16 +247,18 @@ Now, go here:
|
|||
|
||||
and on the left click "Staging Repositories". You click the staging repo and close it, then you refresh, click it and release it. It's done when you see it here:
|
||||
|
||||
[http://repo1.maven.org/maven2/org/antlr/antlr4-runtime/](http://repo1.maven.org/maven2/org/antlr/antlr4-runtime/)
|
||||
[https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.8-1/antlr4-runtime-4.8-1.jar](https://oss.sonatype.org/service/local/repositories/releases/content/org/antlr/antlr4-runtime/4.8-1/antlr4-runtime-4.8-1.jar)
|
||||
|
||||
All releases should be here: https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/
|
||||
|
||||
Copy the jars to antlr.org site and update download/index.html
|
||||
|
||||
```bash
|
||||
cp ~/.m2/repository/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7.jar ~/antlr/sites/website-antlr4/download/antlr-runtime-4.7.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4/4.7/antlr4-4.7-complete.jar ~/antlr/sites/website-antlr4/download/antlr-4.7-complete.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4-runtime/4.8/antlr4-runtime-4.8.jar ~/antlr/sites/website-antlr4/download/antlr-runtime-4.8.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4/4.8/antlr4-4.8-complete.jar ~/antlr/sites/website-antlr4/download/antlr-4.8-complete.jar
|
||||
cd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr-4.7-complete.jar
|
||||
git add antlr-runtime-4.7.jar
|
||||
git add antlr-4.8-complete.jar
|
||||
git add antlr-runtime-4.8.jar
|
||||
```
|
||||
|
||||
Update on site:
|
||||
|
@ -232,7 +270,7 @@ Update on site:
|
|||
* scripts/topnav.js
|
||||
|
||||
```
|
||||
git commit -a -m 'add 4.7 jars'
|
||||
git commit -a -m 'add 4.8 jars'
|
||||
git push origin gh-pages
|
||||
```
|
||||
|
||||
|
@ -241,16 +279,14 @@ git push origin gh-pages
|
|||
### JavaScript
|
||||
|
||||
```bash
|
||||
cd runtime/JavaScript/src
|
||||
zip -r /tmp/antlr-javascript-runtime-4.7.zip antlr4
|
||||
cp /tmp/antlr-javascript-runtime-4.7.zip ~/antlr/sites/website-antlr4/download
|
||||
cd runtime/JavaScript
|
||||
# git add, commit, push
|
||||
```
|
||||
|
||||
**Push to npm**
|
||||
|
||||
```bash
|
||||
cd runtime/JavaScript/src
|
||||
cd runtime/JavaScript
|
||||
npm login
|
||||
npm publish antlr4
|
||||
```
|
||||
|
@ -258,11 +294,8 @@ npm publish antlr4
|
|||
Move target to website
|
||||
|
||||
```bash
|
||||
pushd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr-javascript-runtime-4.7.zip
|
||||
git commit -a -m 'update JS runtime'
|
||||
git push origin gh-pages
|
||||
popd
|
||||
npm run build
|
||||
cp /dist/antlr4.js ~/antlr/sites/website-antlr4/download
|
||||
```
|
||||
|
||||
### CSharp
|
||||
|
@ -303,7 +336,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
|
|||
Restore completed in 427.62 ms for C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\Antlr4.Runtime.dotnet.csproj.
|
||||
Antlr4.Runtime.dotnet -> C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\netstandard1.3\Antlr4.Runtime.Standard.dll
|
||||
Antlr4.Runtime.dotnet -> C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\net35\Antlr4.Runtime.Standard.dll
|
||||
Successfully created package 'C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\Antlr4.Runtime.Standard.4.7.2.nupkg'.
|
||||
Successfully created package 'C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\Antlr4.Runtime.Standard.4.8.2.nupkg'.
|
||||
```
|
||||
|
||||
**Publishing to NuGet**
|
||||
|
@ -365,7 +398,7 @@ There are links to the artifacts in [download.html](http://www.antlr.org/downloa
|
|||
|
||||
The C++ target is the most complex one, because it addresses multiple platforms, which require individual handling. We have 4 scenarios to cover:
|
||||
|
||||
* **Windows**: static and dynamic libraries for the VC++ runtime 2013 or 2015 (corresponding to Visual Studio 2013 or 2015) + header files. All that in 32 and 64bit, debug + release.
|
||||
* **Windows**: static and dynamic libraries for the VC++ runtime 2017 or 2019 (corresponding to Visual Studio 2017 or 2019) + header files. All that in 32 and 64bit, debug + release.
|
||||
* **MacOS**: static and dynamic release libraries + header files.
|
||||
* **iOS**: no prebuilt binaries, but just a zip of the source, including the XCode project to build everything from source.
|
||||
* **Linux**: no prebuilt binaries, but just a zip of the source code, including the cmake file to build everything from source there.
|
||||
|
@ -379,7 +412,7 @@ On a Mac (with XCode 7+ installed):
|
|||
```bash
|
||||
cd runtime/Cpp
|
||||
./deploy-macos.sh
|
||||
cp antlr4-cpp-runtime-macos.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.7-macos.zip
|
||||
cp antlr4-cpp-runtime-macos.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.8-macos.zip
|
||||
```
|
||||
|
||||
On any Mac or Linux machine:
|
||||
|
@ -387,15 +420,15 @@ On any Mac or Linux machine:
|
|||
```bash
|
||||
cd runtime/Cpp
|
||||
./deploy-source.sh
|
||||
cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.7-source.zip
|
||||
cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.8-source.zip
|
||||
```
|
||||
|
||||
On a Windows machine the build scripts checks if VS 2013 and/or VS 2015 are installed and builds binaries for each, if found. This script requires 7z to be installed (http://7-zip.org then do `set PATH=%PATH%;C:\Program Files\7-Zip\` from DOS not powershell).
|
||||
On a Windows machine the build scripts checks if VS 2017 and/or VS 2019 are installed and builds binaries for each, if found. This script requires 7z to be installed (http://7-zip.org then do `set PATH=%PATH%;C:\Program Files\7-Zip\` from DOS not powershell).
|
||||
|
||||
```bash
|
||||
cd runtime/Cpp
|
||||
deploy-windows.cmd
|
||||
cp runtime\bin\vs-2015\x64\Release DLL\antlr4-cpp-runtime-vs2015.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.7-vs2015.zip
|
||||
deploy-windows.cmd Community
|
||||
cp antlr4-cpp-runtime-vs2019.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.8-vs2019.zip
|
||||
```
|
||||
|
||||
Move target to website (**_rename to a specific ANTLR version first if needed_**):
|
||||
|
@ -403,14 +436,27 @@ Move target to website (**_rename to a specific ANTLR version first if needed_**
|
|||
```bash
|
||||
pushd ~/antlr/sites/website-antlr4/download
|
||||
# vi index.html
|
||||
git add antlr4cpp-runtime-4.7-macos.zip
|
||||
git add antlr4cpp-runtime-4.7-windows.zip
|
||||
git add antlr4cpp-runtime-4.7-source.zip
|
||||
git add antlr4cpp-runtime-4.8-macos.zip
|
||||
git add antlr4cpp-runtime-4.8-windows.zip
|
||||
git add antlr4cpp-runtime-4.8-source.zip
|
||||
git commit -a -m 'update C++ runtime'
|
||||
git push origin gh-pages
|
||||
popd
|
||||
```
|
||||
|
||||
### Dart
|
||||
|
||||
Push to pub.dev
|
||||
|
||||
```bash
|
||||
cd runtime/Dart
|
||||
pub publish
|
||||
```
|
||||
|
||||
It will warn that no change log found for the new version.
|
||||
If there are changes relevant to dart in this release, edit [CHANGELOG.md](https://github.com/antlr/antlr4/blob/master/runtime/Dart/CHANGELOG.md) to describe the changes.
|
||||
Otherwise enter `N` to ignore the warning.
|
||||
|
||||
## Update javadoc for runtime and tool
|
||||
|
||||
First, gen javadoc:
|
||||
|
@ -427,9 +473,9 @@ cd ~/antlr/sites/website-antlr4/api
|
|||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
cd Java
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7-javadoc.jar
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.8/antlr4-runtime-4.8-javadoc.jar
|
||||
cd ../JavaTool
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4/4.7/antlr4-4.7-javadoc.jar
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4/4.8/antlr4-4.8-javadoc.jar
|
||||
git commit -a -m 'freshen api doc'
|
||||
git push origin gh-pages
|
||||
```
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
/* 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.
|
||||
*/
|
||||
//
|
||||
|
||||
function CaseChangingStream(stream, upper) {
|
||||
this._stream = stream;
|
||||
this._upper = upper;
|
||||
}
|
||||
|
||||
CaseChangingStream.prototype.LA = function(offset) {
|
||||
var c = this._stream.LA(offset);
|
||||
if (c <= 0) {
|
||||
return c;
|
||||
}
|
||||
return String.fromCodePoint(c)[this._upper ? "toUpperCase" : "toLowerCase"]().codePointAt(0);
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.reset = function() {
|
||||
return this._stream.reset();
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.consume = function() {
|
||||
return this._stream.consume();
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.LT = function(offset) {
|
||||
return this._stream.LT(offset);
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.mark = function() {
|
||||
return this._stream.mark();
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.release = function(marker) {
|
||||
return this._stream.release(marker);
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.seek = function(_index) {
|
||||
return this._stream.seek(_index);
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.getText = function(start, stop) {
|
||||
return this._stream.getText(start, stop);
|
||||
};
|
||||
|
||||
CaseChangingStream.prototype.toString = function() {
|
||||
return this._stream.toString();
|
||||
};
|
||||
|
||||
Object.defineProperty(CaseChangingStream.prototype, "index", {
|
||||
get: function() {
|
||||
return this._stream.index;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(CaseChangingStream.prototype, "size", {
|
||||
get: function() {
|
||||
return this._stream.size;
|
||||
}
|
||||
});
|
||||
|
||||
exports.CaseChangingStream = CaseChangingStream;
|
|
@ -0,0 +1,13 @@
|
|||
class CaseChangingStream():
|
||||
def __init__(self, stream, upper):
|
||||
self._stream = stream
|
||||
self._upper = upper
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self._stream.__getattribute__(name)
|
||||
|
||||
def LA(self, offset):
|
||||
c = self._stream.LA(offset)
|
||||
if c <= 0:
|
||||
return c
|
||||
return ord(chr(c).upper() if self._upper else chr(c).lower())
|
|
@ -1,54 +0,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.
|
||||
*/
|
||||
//
|
||||
|
||||
function CaseInsensitiveInputStream(stream, upper) {
|
||||
this._stream = stream;
|
||||
this._case = upper ? String.toUpperCase : String.toLowerCase;
|
||||
return this;
|
||||
}
|
||||
|
||||
CaseInsensitiveInputStream.prototype.LA = function (offset) {
|
||||
c = this._stream.LA(i);
|
||||
if (c <= 0) {
|
||||
return c;
|
||||
}
|
||||
return this._case.call(String.fromCodePoint(c))
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.reset = function() {
|
||||
return this._stream.reset();
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.consume = function() {
|
||||
return this._stream.consume();
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.LT = function(offset) {
|
||||
return this._stream.LT(offset);
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.mark = function() {
|
||||
return this._stream.mark();
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.release = function(marker) {
|
||||
return this._stream.release(marker);
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.seek = function(_index) {
|
||||
return this._stream.getText(start, stop);
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.getText = function(start, stop) {
|
||||
return this._stream.getText(start, stop);
|
||||
};
|
||||
|
||||
CaseInsensitiveInputStream.prototype.toString = function() {
|
||||
return this._stream.toString();
|
||||
};
|
||||
|
||||
exports.CaseInsensitiveInputStream = CaseInsensitiveInputStream;
|
|
@ -1,13 +1,15 @@
|
|||
package antlr
|
||||
package antlr_resource
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
|
||||
"github.com/antlr/antlr4/runtime/Go/antlr"
|
||||
)
|
||||
|
||||
// CaseChangingStream wraps an existing CharStream, but upper cases, or
|
||||
// lower cases the input before it is tokenized.
|
||||
type CaseChangingStream struct {
|
||||
CharStream
|
||||
antlr.CharStream
|
||||
|
||||
upper bool
|
||||
}
|
||||
|
@ -15,10 +17,8 @@ type CaseChangingStream struct {
|
|||
// NewCaseChangingStream returns a new CaseChangingStream that forces
|
||||
// all tokens read from the underlying stream to be either upper case
|
||||
// or lower case based on the upper argument.
|
||||
func NewCaseChangingStream(in CharStream, upper bool) *CaseChangingStream {
|
||||
return &CaseChangingStream{
|
||||
in, upper,
|
||||
}
|
||||
func NewCaseChangingStream(in antlr.CharStream, upper bool) *CaseChangingStream {
|
||||
return &CaseChangingStream{in, upper}
|
||||
}
|
||||
|
||||
// LA gets the value of the symbol at offset from the current position
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
# ANTLR4 Language Target, Runtime for Swift
|
||||
|
||||
## Requirements
|
||||
|
||||
ANTLR 4.7.2 requires Swift 4.2. It works on Swift 4.2.1 also.
|
||||
|
||||
ANTLR 4.7.1 requires Swift 4.0, and does not work on Swift 4.2. (The status of
|
||||
Swift 4.1 support is unknown.)
|
||||
|
||||
## Performance Note
|
||||
|
||||
To use ANTLR4 Swift target in production environment, make sure to turn on compiler optimizations by following [these instructions](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#build-configurations) if you use SwiftPM to build your project. If you are using Xcode to build your project, it's unlikely you will not use `release` build for production build.
|
||||
|
|
|
@ -9,12 +9,14 @@ This page lists the available and upcoming ANTLR runtimes. Please note that you
|
|||
* [Go](go-target.md)
|
||||
* [C++](cpp-target.md)
|
||||
* [Swift](swift-target.md)
|
||||
* [PHP](php-target.md)
|
||||
* [Dart](dart-target.md)
|
||||
|
||||
## Target feature parity
|
||||
|
||||
New features generally appear in the Java target and then migrate to the other targets, but these other targets don't always get updated in the same overall tool release. This section tries to identify features added to Java that have not been added to the other targets.
|
||||
|
||||
|Feature|Java|C♯|Python2|Python3|JavaScript|Go|C++|Swift|
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|-|
|
||||
|Feature|Java|C♯|Python2|Python3|JavaScript|Go|C++|Swift|PHP|Dart
|
||||
|---|---|---|---|---|---|---|---|---|---|---|
|
||||
|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|-|-|-|
|
||||
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -13,7 +13,7 @@
|
|||
</parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>ANTLR 4</name>
|
||||
|
@ -138,6 +138,8 @@
|
|||
<filesets>
|
||||
<fileset>
|
||||
<directory>runtime/Swift/.build</directory>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>runtime/Swift/Tests/Antlr4Tests/gen</directory>
|
||||
</fileset>
|
||||
</filesets>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>antlr4-runtime-test-annotations</artifactId>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>antlr4-runtime-testsuite</artifactId>
|
||||
<name>ANTLR 4 Runtime Tests (2nd generation)</name>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>ST4</artifactId>
|
||||
<version>4.0.8</version>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -59,18 +59,6 @@
|
|||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.46.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
|
@ -92,6 +80,11 @@
|
|||
</resource>
|
||||
<resource>
|
||||
<directory>../runtime</directory>
|
||||
<excludes>
|
||||
<exclude>**/.build/**</exclude>
|
||||
<exclude>**/target/**</exclude>
|
||||
<exclude>Swift/*.xcodeproj/**</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
|
@ -103,14 +96,16 @@
|
|||
<!-- SUREFIRE-951: file.encoding cannot be set via systemPropertyVariables -->
|
||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||
<includes>
|
||||
<include>**/csharp/Test*.java</include>
|
||||
<include>**/java/Test*.java</include>
|
||||
<include>**/go/Test*.java</include>
|
||||
<include>**/javascript/node/Test*.java</include>
|
||||
<include>**/python2/Test*.java</include>
|
||||
<include>**/python3/Test*.java</include>
|
||||
<include>${antlr.tests.swift}</include>
|
||||
</includes>
|
||||
<include>**/csharp/Test*.java</include>
|
||||
<include>**/java/Test*.java</include>
|
||||
<include>**/go/Test*.java</include>
|
||||
<include>**/javascript/Test*.java</include>
|
||||
<include>**/python2/Test*.java</include>
|
||||
<include>**/python3/Test*.java</include>
|
||||
<include>**/php/Test*.java</include>
|
||||
<include>**/dart/Test*.java</include>
|
||||
<include>${antlr.tests.swift}</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>antlr4-runtime-test-annotation-processors</artifactId>
|
||||
|
@ -18,11 +18,9 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.4.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||
<groupId>com.github.olivergondza</groupId>
|
||||
<artifactId>maven-jdk-tools-wrapper</artifactId>
|
||||
<version>0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "((<t>)<v>)"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "System.Collections.IList __ttt__ = <v>;" // just use static type system
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%int <n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "int <n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
|
@ -94,6 +98,8 @@ bool Property() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
public override IToken NextToken() {
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
@ -92,6 +96,8 @@ this.Property = function() {
|
|||
}
|
||||
>>
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
|
|
|
@ -9,19 +9,20 @@ Assert(s) ::= ""
|
|||
Cast(t,v) ::= "dynamic_cast\<<t> *>(<v>)" // Should actually use a more specific name. We may have to use other casts as well.
|
||||
Append(a,b) ::= "<a> + <b>->toString()"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
AppendStr(a,b) ::= "<a> + <b>"
|
||||
|
||||
AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually).
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= "int <n> = <v>;"
|
||||
InitBooleanMember(n,v) ::= "bool <n> = <v>;"
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
IntArg(n) ::= "int <n>"
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= "<n>"
|
||||
SetMember(n,v) ::= "<n> = <v>;"
|
||||
AddMember(n,v) ::= "<n> += <v>;"
|
||||
PlusMember(v,n) ::= "<v> + <n>"
|
||||
MemberEquals(n,v) ::= "<n> == <v>"
|
||||
ModMemberEquals(n,m,v) ::= "<n> % <m> == <v>"
|
||||
ModMemberNotEquals(n,m,v) ::= "<n> % <m> != <v>"
|
||||
|
@ -68,6 +69,8 @@ bool Property() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
protected:
|
||||
class PositionAdjustingLexerATNSimulator : public antlr4::atn::LexerATNSimulator {
|
||||
|
|
|
@ -0,0 +1,318 @@
|
|||
writeln(s) ::= <<print(<s>);>>
|
||||
write(s) ::= <<stdout.write(<s>);>>
|
||||
writeList(s) ::= <<print(<s; separator="+">);>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= <<assert(<s>);>>
|
||||
|
||||
Cast(t,v) ::= "(<v> as <t>)"
|
||||
|
||||
Append(a,b) ::= "<a>.toString() + <b>.toString()"
|
||||
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "assert (<v> is List);" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%int <n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "int <n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "List\<String>"
|
||||
|
||||
BuildParseTrees() ::= "buildParseTree = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%errorHandler = new BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(parser: this)%>
|
||||
|
||||
Column() ::= "this.charPositionInLine"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text == "<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "tokenStream.text"
|
||||
|
||||
LTEquals(i, v) ::= <%tokenStream.LT(<i>).text == <v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%tokenStream.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this.tokenStartCharPositionInLine==<i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.expectedTokens.toString(vocabulary: this.vocabulary)"
|
||||
|
||||
RuleInvocationStack() ::= "ruleInvocationStack"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<interpreter.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.TOKEN_<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
bool Property() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= <<
|
||||
class PositionAdjustingLexerATNSimulator extends LexerATNSimulator {
|
||||
PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn,
|
||||
List\<DFA> decisionToDFA, PredictionContextCache sharedContextCache)
|
||||
: super(atn, decisionToDFA, sharedContextCache, recog: recog);
|
||||
|
||||
void resetAcceptPosition(CharStream input, int index, int line,
|
||||
int charPositionInLine) {
|
||||
input.seek(index);
|
||||
this.line = line;
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
consume(input);
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
@override
|
||||
Token nextToken() {
|
||||
if (!(super.interpreter is PositionAdjustingLexerATNSimulator)) {
|
||||
interpreter = new PositionAdjustingLexerATNSimulator(
|
||||
this, _ATN, _decisionToDFA, _sharedContextCache);
|
||||
}
|
||||
|
||||
return super.nextToken();
|
||||
}
|
||||
|
||||
@override
|
||||
Token emit() {
|
||||
switch (type) {
|
||||
case TOKEN_TOKENS:
|
||||
handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
|
||||
case TOKEN_LABEL:
|
||||
handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return super.emit();
|
||||
}
|
||||
|
||||
bool handleAcceptPositionForIdentifier() {
|
||||
String tokenText = text;
|
||||
int identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
isIdentifierChar(tokenText[identifierLength])) {
|
||||
identifierLength++;
|
||||
}
|
||||
|
||||
if (inputStream.index > tokenStartCharIndex + identifierLength) {
|
||||
int offset = identifierLength - 1;
|
||||
interpreter.resetAcceptPosition(inputStream, tokenStartCharIndex + offset,
|
||||
tokenStartLine, tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handleAcceptPositionForKeyword(String keyword) {
|
||||
if (inputStream.index > tokenStartCharIndex + keyword.length) {
|
||||
int offset = keyword.length - 1;
|
||||
interpreter.resetAcceptPosition(inputStream, tokenStartCharIndex + offset,
|
||||
tokenStartLine, tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
PositionAdjustingLexerATNSimulator get interpreter {
|
||||
return super.interpreter as PositionAdjustingLexerATNSimulator;
|
||||
}
|
||||
|
||||
static bool isIdentifierChar(String c) {
|
||||
return isLetterOrDigit(c) || c == '_';
|
||||
}
|
||||
|
||||
static const ZERO = 48;
|
||||
static const LOWER_A = 97;
|
||||
static const LOWER_Z = 122;
|
||||
static const UPPER_A = 65;
|
||||
static const UPPER_Z = 90;
|
||||
|
||||
static bool isLetterOrDigit(String char) => isLetter(char) || isDigit(char);
|
||||
|
||||
// Note: this is intentially ASCII only
|
||||
static bool isLetter(String char) {
|
||||
if (char == null) return false;
|
||||
var cc = char.codeUnitAt(0);
|
||||
return cc >= LOWER_A && cc \<= LOWER_Z || cc >= UPPER_A && cc \<= UPPER_Z;
|
||||
}
|
||||
|
||||
static bool isDigit(String char) {
|
||||
if (char == null) return false;
|
||||
var cc = char.codeUnitAt(0);
|
||||
return cc >= ZERO && cc \< ZERO + 10;
|
||||
}
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
void visitTerminal(TerminalNode node) {
|
||||
print(node.symbol.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(new LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::definitions {
|
||||
class MyRuleNode extends ParserRuleContext {
|
||||
int altNum;
|
||||
|
||||
MyRuleNode(ParserRuleContext parent, int invokingStateNumber)
|
||||
: super(parent, invokingStateNumber);
|
||||
|
||||
@override int get altNumber {
|
||||
return altNum;
|
||||
}
|
||||
|
||||
@override void set altNumber(int altNum) {
|
||||
this.altNum = altNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
void exitA(AContext ctx) {
|
||||
if (ctx.childCount==2)
|
||||
stdout.write("${ctx.INT(0).symbol.text} ${ctx.INT(1).symbol.text} ${ctx.INTs()}");
|
||||
else
|
||||
print(ctx.ID().symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
void exitA(AContext ctx) {
|
||||
if (ctx.childCount==2) {
|
||||
stdout.write("${ctx.b(0).start.text} ${ctx.b(1).start.text} ${ctx.bs()[0].start.text}");
|
||||
} else
|
||||
print(ctx.b(0).start.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
void exitE(EContext ctx) {
|
||||
if (ctx.childCount==3) {
|
||||
stdout.write("${ctx.e(0).start.text} ${ctx.e(1).start.text} ${ctx.es()[0].start.text}\n");
|
||||
} else
|
||||
print(ctx.INT().symbol.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
void exitCall(CallContext ctx) {
|
||||
stdout.write("${ctx.e().start.text} ${ctx.eList()}");
|
||||
}
|
||||
void exitInt(IntContext ctx) {
|
||||
print(ctx.INT().symbol.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
void foo() {
|
||||
SContext s = null;
|
||||
List\<AContext> a = s.as();
|
||||
List\<BContext> b = s.bs();
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<
|
||||
void foo() {print("foo");}
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "foo();"
|
||||
|
||||
Declare_pred() ::= <<bool pred(bool v) {
|
||||
print("eval=\$v");
|
||||
return v;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
@ -98,6 +102,8 @@ this.Property = function() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array"}>>
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
@ -100,6 +104,8 @@ this.Property = function() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "(<v>)"
|
|||
|
||||
Append(a,b) ::= "<a> + fmt.Sprint(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= "<a> + <b>"
|
||||
|
||||
DeclareLocal(s, v) ::= "var <s> = <v>"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= ""
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n, v) ::= <%var <n> int = <v>; var _ int = <n>; %>
|
|||
|
||||
InitBooleanMember(n, v) ::= <%var <n> bool = <v>; var _ bool = <n>; %>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "int <n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%<n>%>
|
||||
|
||||
SetMember(n, v) ::= <%<n> = <v>;%>
|
||||
|
||||
AddMember(n, v) ::= <%<n> += <v>;%>
|
||||
|
||||
PlusMember(v, n) ::= <%<v> + fmt.Sprint(<n>)%>
|
||||
|
||||
MemberEquals(n, v) ::= <%<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n, m, v) ::= <%<n> % <m> == <v>%>
|
||||
|
@ -94,9 +98,13 @@ func (p *TParser) Property() bool {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
func (p *PositionAdjustingLexer) NextToken() antlr.Token {
|
||||
if _, ok := p.Interpreter.(*PositionAdjustingLexerATNSimulator); !ok {
|
||||
lexerDeserializer := antlr.NewATNDeserializer(nil)
|
||||
lexerAtn := lexerDeserializer.DeserializeFromUInt16(serializedLexerAtn)
|
||||
p.Interpreter = NewPositionAdjustingLexerATNSimulator(p, lexerAtn, p.Interpreter.DecisionToDFA(), p.Interpreter.SharedContextCache())
|
||||
p.Virt = p
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "((<t>)<v>)"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use static type system
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%int <n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%boolean <n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "int <n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
|
@ -94,6 +98,8 @@ boolean Property() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
@ -98,6 +102,8 @@ this.Property = function() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
|
@ -182,18 +188,21 @@ walker.walk(new this.LeafListener(), <s>);
|
|||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
class MyRuleNode extends antlr4.ParserRuleContext {
|
||||
constructor(parent, invokingState) {
|
||||
super(parent, invokingState);
|
||||
this.altNum = 0;
|
||||
}
|
||||
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
getAltNumber() {
|
||||
return this.altNum;
|
||||
}
|
||||
|
||||
setAltNumber(altNumber){
|
||||
this.altNum = altNumber;
|
||||
}
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
MyRuleNode.prototype.getAltNumber = function() { return this.altNum; }
|
||||
MyRuleNode.prototype.setAltNumber = function(altNumber) { this.altNum = altNumber; }
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
|
|
|
@ -0,0 +1,272 @@
|
|||
writeln(s) ::= <<echo <s> . \PHP_EOL;>>
|
||||
write(s) ::= <<echo <s>;>>
|
||||
writeList(s) ::= <<echo <s; separator=".">;>>
|
||||
|
||||
False() ::= "false"
|
||||
True() ::= "true"
|
||||
Not(v) ::= "!<v>"
|
||||
Assert(s) ::= <<assert(<s>);>>
|
||||
Cast(t,v) ::= "<v>"
|
||||
Append(a,b) ::= "<a> . <b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= "assert(\is_array(<v>));" // just use static type system
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%public \$<n> = <v>;%>
|
||||
InitBooleanMember(n,v) ::= <%public \$<n> = <v>;%>
|
||||
InitIntVar(n,v) ::= <%\$<n> = <v>;%>
|
||||
IntArg(n) ::= "int <n>"
|
||||
VarRef(n) ::= "$<n>"
|
||||
|
||||
GetMember(n) ::= <%\$this-><n>%>
|
||||
SetMember(n,v) ::= <%\$this-><n> = <v>;%>
|
||||
AddMember(n,v) ::= <%\$this-><n> += <v>;%>
|
||||
PlusMember(v,n) ::= <%<v> + \$this-><n>%>
|
||||
MemberEquals(n,v) ::= <%\$this-><n> == <v>%>
|
||||
ModMemberEquals(n,m,v) ::= <%\$this-><n> % <m> == <v>%>
|
||||
ModMemberNotEquals(n,m,v) ::= <%\$this-><n> % <m> !== <v>%>
|
||||
|
||||
DumpDFA() ::= "\$this->dumpDFA();"
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= ""
|
||||
BuildParseTrees() ::= "\$this->setBuildParseTree(true);"
|
||||
BailErrorStrategy() ::= <%\$this->setErrorHandler(new Antlr\\Antlr4\\Runtime\\Error\\BailErrorStrategy());%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>->toStringTree(\$this->getRuleNames())%>
|
||||
Column() ::= "\$this->getCharPositionInLine()"
|
||||
Text() ::= "\$this->getText()"
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
TextEquals(a) ::= <%\$this->getText() === "<a>"%>
|
||||
PlusText(a) ::= <%"<a>" . \$this->getText()%>
|
||||
InputText() ::= "\$this->input->getText()"
|
||||
LTEquals(i, v) ::= <%\$this->input->LT(<i>)->getText() === <v>%>
|
||||
LANotEquals(i, v) ::= <%\$this->input->LA(<i>) !== <v>%>
|
||||
TokenStartColumnEquals(i) ::= <%\$this->tokenStartCharPositionInLine === <i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "\$this->getExpectedTokens()->toStringVocabulary(\$this->getVocabulary())"
|
||||
|
||||
RuleInvocationStack() ::= "'[' . \implode(', ', \$this->getRuleInvocationStack()) . ']'"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<\$this->interp->setPredictionMode(Antlr\\Antlr4\\Runtime\\Atn\\PredictionMode::LL_EXACT_AMBIG_DETECTION);>>
|
||||
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>::<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
public function Property() : bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>-><call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= <<
|
||||
class PositionAdjustingLexerATNSimulator extends LexerATNSimulator {
|
||||
public function resetAcceptPosition(CharStream \$input, int \$index, int \$line, int \$charPositionInLine) : void {
|
||||
\$input->seek(\$index);
|
||||
\$this->line = \$line;
|
||||
\$this->charPositionInLine = \$charPositionInLine;
|
||||
\$this->consume(\$input);
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
public function nextToken() : Antlr\\Antlr4\\Runtime\\Token
|
||||
{
|
||||
if (!\$this->interp instanceof PositionAdjustingLexerATNSimulator) {
|
||||
\$this->interp = new PositionAdjustingLexerATNSimulator(\$this, self::\$atn, self::\$decisionToDFA, self::\$sharedContextCache);
|
||||
}
|
||||
|
||||
return parent::nextToken();
|
||||
}
|
||||
|
||||
public function emit() : Antlr\\Antlr4\\Runtime\\Token
|
||||
{
|
||||
switch (\$this->type) {
|
||||
case self::TOKENS:
|
||||
\$this->handleAcceptPositionForKeyword('tokens');
|
||||
break;
|
||||
|
||||
case self::LABEL:
|
||||
\$this->handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::emit();
|
||||
}
|
||||
|
||||
private function handleAcceptPositionForIdentifier() : bool
|
||||
{
|
||||
\$tokenText = \$this->getText();
|
||||
\$identifierLength = 0;
|
||||
while (\$identifierLength \< \strlen(\$tokenText) && self::isIdentifierChar(\$tokenText[\$identifierLength])) {
|
||||
\$identifierLength++;
|
||||
}
|
||||
|
||||
if (\$this->getInputStream()->getIndex() > \$this->tokenStartCharIndex + \$identifierLength) {
|
||||
\$offset = \$identifierLength - 1;
|
||||
\$this->getInterpreter()->resetAcceptPosition(\$this->getInputStream(), \$this->tokenStartCharIndex + \$offset, \$this->tokenStartLine, \$this->tokenStartCharPositionInLine + \$offset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function handleAcceptPositionForKeyword(string \$keyword) : bool
|
||||
{
|
||||
if (\$this->getInputStream()->getIndex() > \$this->tokenStartCharIndex + \strlen(\$keyword)) {
|
||||
\$offset = \strlen(\$keyword) - 1;
|
||||
\$this->getInterpreter()->resetAcceptPosition(\$this->getInputStream(), \$this->tokenStartCharIndex + \$offset, \$this->tokenStartLine, \$this->tokenStartCharPositionInLine + \$offset);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function isIdentifierChar(string \$c) : bool
|
||||
{
|
||||
return \ctype_alnum(\$c) || \$c === '_';
|
||||
}
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener
|
||||
{
|
||||
public function visitTerminal(Antlr\\Antlr4\\Runtime\\Tree\\TerminalNode \$node) : void
|
||||
{
|
||||
echo \$node->getSymbol()->getText() . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
\$walker = new Antlr\\Antlr4\\Runtime\\Tree\\ParseTreeWalker();
|
||||
\$walker->walk(new LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::contexts {
|
||||
class MyRuleNode extends ParserRuleContext
|
||||
{
|
||||
public \$altNum;
|
||||
|
||||
public function getAltNumber() : int
|
||||
{
|
||||
return \$this->altNum;
|
||||
}
|
||||
|
||||
public function setAltNumber(int \$altNum) : void
|
||||
{
|
||||
\$this->altNum = \$altNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
public function exitA(Context\\AContext \$ctx) : void {
|
||||
if (\$ctx->getChildCount() === 2) {
|
||||
echo \sprintf('%s %s [%s]',\$ctx->INT(0)->getSymbol()->getText(), \$ctx->INT(1)->getSymbol()->getText(), \implode(', ', \$ctx->INT())) . \PHP_EOL;
|
||||
} else {
|
||||
echo \$ctx->ID()->getSymbol() . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
public function exitA(Context\\AContext \$ctx) : void
|
||||
{
|
||||
if (\$ctx->getChildCount() === 2) {
|
||||
echo \sprintf('%s %s %s', \$ctx->b(0)->start->getText(), \$ctx->b(1)->start->getText(),\$ctx->b()[0]->start->getText()) . \PHP_EOL;
|
||||
} else {
|
||||
echo \$ctx->b(0)->start->getText() . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener {
|
||||
public function exitE(Context\\EContext \$ctx) : void
|
||||
{
|
||||
if (\$ctx->getChildCount() === 3) {
|
||||
echo \sprintf('%s %s %s', \$ctx->e(0)->start->getText(), \$ctx->e(1)->start->getText(), \$ctx->e()[0]->start->getText()) . \PHP_EOL;
|
||||
} else {
|
||||
echo \$ctx->INT()->getSymbol()->getText() . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
class LeafListener extends TBaseListener
|
||||
{
|
||||
public function exitCall(Context\\CallContext \$ctx) : void {
|
||||
echo \sprintf('%s %s',\$ctx->e()->start->getText(),\$ctx->eList()) . \PHP_EOL;
|
||||
}
|
||||
|
||||
public function exitInt(Context\\IntContext \$ctx) : void {
|
||||
echo \$ctx->INT()->getSymbol()->getText() . \PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
public function foo() : void {
|
||||
\$s = null;
|
||||
\$a = \$s->a();
|
||||
\$b = \$s->b();
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<
|
||||
public function foo() : void {
|
||||
echo 'foo' . \PHP_EOL;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "\$this->foo();"
|
||||
|
||||
Declare_pred() ::= <<public function pred(bool \$v) : bool {
|
||||
echo "eval=".(\$v ? 'true' : 'false') . \PHP_EOL;
|
||||
return \$v;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= "\$this->pred(<v>)"
|
||||
|
||||
ParserTokenType(t) ::= "Parser::<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>-><rule>"
|
||||
StringType() ::= ""
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>-><subctx>-><member>"
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + str(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= "<a> + <b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%<n> = <v>%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%self.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%self.<n> = <v>%>
|
||||
|
||||
AddMember(n,v) ::= <%self.<n> += <v>%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
|
||||
|
||||
MemberEquals(n,v) ::= <%self.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
|
||||
|
@ -94,6 +98,8 @@ def Property(self):
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
def resetAcceptPosition(self, index, line, column):
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + str(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= "<a> + <b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%<n> = <v>%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%self.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%self.<n> = <v>%>
|
||||
|
||||
AddMember(n,v) ::= <%self.<n> += <v>%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
|
||||
|
||||
MemberEquals(n,v) ::= <%self.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
|
||||
|
@ -99,6 +103,8 @@ def Property(self):
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
def resetAcceptPosition(self, index, line, column):
|
||||
|
|
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "<v>"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "<n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
@ -98,6 +102,8 @@ this.Property = function() {
|
|||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
writeln(s) ::= <<print(<s>)>>
|
||||
writeln(s) ::= <<print((<s>) ?? "nil")>>
|
||||
|
||||
write(s) ::= <<print(<s>, terminator: "")>>
|
||||
write(s) ::= <<print((<s>) ?? "nil", terminator: "")>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
|
@ -14,9 +14,9 @@ Cast(t,v) ::= "((<v> as! <t>))"
|
|||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= <%<Append(a,b)>%>
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
AssertIsList(v) ::= "var __ttt__ = <v>;" // just use static type system
|
||||
|
||||
|
@ -26,14 +26,18 @@ InitIntMember(n,v) ::= <%var <n> = <v>%>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%var <n> = <v>%>
|
||||
|
||||
InitIntVar(n,v) ::= <%<InitIntMember(n,v)>%>
|
||||
|
||||
IntArg(n) ::= "int <n>"
|
||||
|
||||
VarRef(n) ::= "<n>"
|
||||
|
||||
GetMember(n) ::= <%self.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%self.<n> = <v>%>
|
||||
|
||||
AddMember(n,v) ::= <%self.<n> += <v>%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + self.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%self.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
|
||||
|
@ -96,6 +100,8 @@ ParserPropertyCall(parser, property) ::= <<
|
|||
<parser>.<property>
|
||||
>>
|
||||
|
||||
PositionAdjustingLexerDef() ::= ""
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
override
|
||||
|
@ -123,7 +129,7 @@ open func emit() -> Token {
|
|||
private func handleAcceptPositionForIdentifier() -> Bool {
|
||||
let tokenText = getText()
|
||||
var identifierLength = 0
|
||||
while ((identifierLength \< tokenText.characters.count) && isIdentifierChar(tokenText[tokenText.characters.index(tokenText.startIndex, offsetBy: identifierLength)])) {
|
||||
while ((identifierLength \< tokenText.count) && isIdentifierChar(tokenText[tokenText.index(tokenText.startIndex, offsetBy: identifierLength)])) {
|
||||
identifierLength += 1
|
||||
}
|
||||
|
||||
|
@ -137,8 +143,8 @@ private func handleAcceptPositionForIdentifier() -> Bool {
|
|||
}
|
||||
|
||||
private func handleAcceptPositionForKeyword(_ keyword:String) -> Bool {
|
||||
if getInputStream()!.index() > _tokenStartCharIndex + keyword.characters.count {
|
||||
let offset = keyword.characters.count - 1
|
||||
if getInputStream()!.index() > _tokenStartCharIndex + keyword.count {
|
||||
let offset = keyword.count - 1
|
||||
(getInterpreter() as! PositionAdjustingLexerATNSimulator).resetAcceptPosition(getInputStream()!, _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static junit.framework.TestCase.failNotEquals;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
|
||||
/** This class represents a single runtime test. It pulls data from
|
||||
|
@ -48,10 +50,9 @@ public abstract class BaseRuntimeTest {
|
|||
"Go",
|
||||
"CSharp",
|
||||
"Python2", "Python3",
|
||||
"Node", "Safari", "Firefox", "Explorer", "Chrome"
|
||||
};
|
||||
public final static String[] JavaScriptTargets = {
|
||||
"Node", "Safari", "Firefox", "Explorer", "Chrome"
|
||||
"PHP",
|
||||
"Node",
|
||||
"Dart"
|
||||
};
|
||||
|
||||
static {
|
||||
|
@ -114,6 +115,7 @@ public abstract class BaseRuntimeTest {
|
|||
System.out.printf("Ignore "+descriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( descriptor.getTestType().contains("Parser") ) {
|
||||
testParser(descriptor);
|
||||
}
|
||||
|
@ -161,14 +163,7 @@ public abstract class BaseRuntimeTest {
|
|||
descriptor.getInput(),
|
||||
descriptor.showDiagnosticErrors()
|
||||
);
|
||||
if ( delegate instanceof SpecialRuntimeTestAssert ) {
|
||||
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
|
||||
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
|
||||
}
|
||||
else {
|
||||
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
|
||||
assertEquals(descriptor.getOutput(), found);
|
||||
}
|
||||
assertCorrectOutput(descriptor, delegate, found);
|
||||
}
|
||||
|
||||
public void testLexer(RuntimeTestDescriptor descriptor) throws Exception {
|
||||
|
@ -202,16 +197,7 @@ public abstract class BaseRuntimeTest {
|
|||
grammar = grammarST.render();
|
||||
|
||||
String found = delegate.execLexer(grammarName+".g4", grammar, grammarName, descriptor.getInput(), descriptor.showDFA());
|
||||
if ( delegate instanceof SpecialRuntimeTestAssert ) {
|
||||
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getOutput(), found);
|
||||
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
|
||||
((SpecialRuntimeTestAssert)delegate).assertEqualStrings(descriptor.getErrors(), delegate.getParseErrors());
|
||||
}
|
||||
else {
|
||||
assertEquals(descriptor.getOutput(), found);
|
||||
assertEquals(descriptor.getANTLRToolErrors(), delegate.getANTLRToolErrors());
|
||||
assertEquals(descriptor.getErrors(), delegate.getParseErrors());
|
||||
}
|
||||
assertCorrectOutput(descriptor, delegate, found);
|
||||
}
|
||||
|
||||
/** Write a grammar to tmpdir and run antlr */
|
||||
|
@ -313,4 +299,76 @@ public abstract class BaseRuntimeTest {
|
|||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public static String readFile(String dir, String fileName) {
|
||||
try {
|
||||
return String.copyValueOf(Utils.readFile(dir+"/"+fileName, "UTF-8"));
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't read file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void assertCorrectOutput(RuntimeTestDescriptor descriptor, RuntimeTestSupport delegate, String actualOutput) {
|
||||
String actualParseErrors = delegate.getParseErrors();
|
||||
String actualToolErrors = delegate.getANTLRToolErrors();
|
||||
String expectedOutput = descriptor.getOutput();
|
||||
String expectedParseErrors = descriptor.getErrors();
|
||||
String expectedToolErrors = descriptor.getANTLRToolErrors();
|
||||
|
||||
if (actualOutput == null) {
|
||||
actualOutput = "";
|
||||
}
|
||||
if (actualParseErrors == null) {
|
||||
actualParseErrors = "";
|
||||
}
|
||||
if (actualToolErrors == null) {
|
||||
actualToolErrors = "";
|
||||
}
|
||||
if (expectedOutput == null) {
|
||||
expectedOutput = "";
|
||||
}
|
||||
if (expectedParseErrors == null) {
|
||||
expectedParseErrors = "";
|
||||
}
|
||||
if (expectedToolErrors == null) {
|
||||
expectedToolErrors = "";
|
||||
}
|
||||
|
||||
if (actualOutput.equals(expectedOutput) &&
|
||||
actualParseErrors.equals(expectedParseErrors) &&
|
||||
actualToolErrors.equals(expectedToolErrors)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (actualOutput.equals(expectedOutput)) {
|
||||
if (actualParseErrors.equals(expectedParseErrors)) {
|
||||
failNotEquals("[" + descriptor.getTarget() + ":" + descriptor.getTestName() + "] " +
|
||||
"Parse output and parse errors are as expected, but tool errors are incorrect",
|
||||
expectedToolErrors, actualToolErrors);
|
||||
}
|
||||
else {
|
||||
fail("[" + descriptor.getTarget() + ":" + descriptor.getTestName() + "] " +
|
||||
"Parse output is as expected, but errors are not: " +
|
||||
"expectedParseErrors:<" + expectedParseErrors +
|
||||
">; actualParseErrors:<" + actualParseErrors +
|
||||
">; expectedToolErrors:<" + expectedToolErrors +
|
||||
">; actualToolErrors:<" + actualToolErrors +
|
||||
">.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
fail("[" + descriptor.getTarget() + ":" + descriptor.getTestName() + "] " +
|
||||
"Parse output is incorrect: " +
|
||||
"expectedOutput:<" + expectedOutput +
|
||||
">; actualOutput:<" + actualOutput +
|
||||
">; expectedParseErrors:<" + expectedParseErrors +
|
||||
">; actualParseErrors:<" + actualParseErrors +
|
||||
">; expectedToolErrors:<" + expectedToolErrors +
|
||||
">; actualToolErrors:<" + actualToolErrors +
|
||||
">.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,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.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime;
|
||||
|
||||
/** This interface acts like a tag on a Base*Test class that wants
|
||||
* to use its own assertEquals() instead of jUnit's.
|
||||
*/
|
||||
public interface SpecialRuntimeTestAssert {
|
||||
void assertEqualStrings(String expected, String actual);
|
||||
}
|
|
@ -56,7 +56,7 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTestAssert*/ {
|
||||
public class BaseCSharpTest implements RuntimeTestSupport {
|
||||
public static final String newline = System.getProperty("line.separator");
|
||||
public static final String pathSep = System.getProperty("path.separator");
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.explorer;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeLexersDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeLexers extends BaseRuntimeTest {
|
||||
public TestCompositeLexers(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseExplorerTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(CompositeLexersDescriptors.class, "Explorer");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(CompositeLexersDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.chrome;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeParsersDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeParsers extends BaseRuntimeTest {
|
||||
public TestCompositeParsers(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(CompositeParsersDescriptors.class, "Chrome");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(CompositeParsersDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.explorer;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.FullContextParsingDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestFullContextParsing extends BaseRuntimeTest {
|
||||
public TestFullContextParsing(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseExplorerTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(FullContextParsingDescriptors.class, "Explorer");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(FullContextParsingDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.explorer;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.LeftRecursionDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLeftRecursion extends BaseRuntimeTest {
|
||||
public TestLeftRecursion(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseExplorerTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LeftRecursionDescriptors.class, "Explorer");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LeftRecursionDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerErrorsDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerErrors extends BaseRuntimeTest {
|
||||
public TestLexerErrors(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LexerErrorsDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LexerErrorsDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.chrome;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerExecDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerExec extends BaseRuntimeTest {
|
||||
public TestLexerExec(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LexerExecDescriptors.class, "Chrome");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LexerExecDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ListenersDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestListeners extends BaseRuntimeTest {
|
||||
public TestListeners(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ListenersDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ListenersDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParseTreesDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParseTrees extends BaseRuntimeTest {
|
||||
public TestParseTrees(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParseTreesDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParseTreesDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.chrome;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserErrorsDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserErrors extends BaseRuntimeTest {
|
||||
public TestParserErrors(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParserErrorsDescriptors.class, "Chrome");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParserErrorsDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserExec extends BaseRuntimeTest {
|
||||
public TestParserExec(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParserExecDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParserExecDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestPerformance extends BaseRuntimeTest {
|
||||
public TestPerformance(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(PerformanceDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(PerformanceDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.firefox;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalLexerDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalLexer extends BaseRuntimeTest {
|
||||
public TestSemPredEvalLexer(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseFirefoxTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalLexerDescriptors.class, "Firefox");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalLexerDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.explorer;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalParserDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalParser extends BaseRuntimeTest {
|
||||
public TestSemPredEvalParser(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseExplorerTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalParserDescriptors.class, "Explorer");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalParserDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -4,22 +4,23 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.explorer;
|
||||
package org.antlr.v4.test.runtime.dart;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.SetsDescriptors;
|
||||
import org.antlr.v4.test.runtime.dart.BaseDartTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSets extends BaseRuntimeTest {
|
||||
public TestSets(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new BaseExplorerTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SetsDescriptors.class, "Explorer");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SetsDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -418,7 +418,7 @@ public class CompositeParsersDescriptors {
|
|||
parser grammar S;
|
||||
type_ : 'int' ;
|
||||
decl : type_ ID ';'
|
||||
| type_ ID init_ ';' {<write("\"JavaDecl: \" + $text")>};
|
||||
| type_ ID init_ ';' {<AppendStr("\"JavaDecl: \"","$text"):writeln()>};
|
||||
init_ : '=' INT;
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
|
@ -532,7 +532,7 @@ public class CompositeParsersDescriptors {
|
|||
|
||||
/**
|
||||
parser grammar S;
|
||||
a @after {<InitIntMember("x","0")>} : B;
|
||||
a @after {<InitIntVar("x","0")>} : B;
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String slaveGrammarS;
|
||||
|
|
|
@ -372,7 +372,7 @@ public class FullContextParsingDescriptors {
|
|||
: expr_or_assign*;
|
||||
expr_or_assign
|
||||
: expr '++' {<writeln("\"fail.\"")>}
|
||||
| expr {<writeln("\"pass: \"+$expr.text")>}
|
||||
| expr {<AppendStr("\"pass: \"","$expr.text"):writeln()>}
|
||||
;
|
||||
expr: expr_primary ('\<-' ID)?;
|
||||
expr_primary
|
||||
|
|
|
@ -529,8 +529,8 @@ public class LeftRecursionDescriptors {
|
|||
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
|
||||
| INT {$v = $INT.int;} # anInt
|
||||
| '(' e ')' {$v = $e.v;} # parens
|
||||
| left=e INC {<Cast("UnaryContext","$ctx"):Concat(".INC() != null"):Assert()>$v = $left.v + 1;} # unary
|
||||
| left=e DEC {<Cast("UnaryContext","$ctx"):Concat(".DEC() != null"):Assert()>$v = $left.v - 1;} # unary
|
||||
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
|
||||
| left=e DEC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "DEC()"):Concat(" != null"):Assert()>$v = $left.v - 1;} # unary
|
||||
| ID {<AssignLocal("$v","3")>} # anID
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
|
@ -636,9 +636,9 @@ public class LeftRecursionDescriptors {
|
|||
grammar T;
|
||||
s : e {<writeln("$e.result")>} ;
|
||||
e returns [<StringType()> result]
|
||||
: ID '=' e1=e {$result = "(" + $ID.text + "=" + $e1.result + ")";}
|
||||
: ID '=' e1=e {$result = <AppendStr("\"(\"", AppendStr("$ID.text", AppendStr("\"=\"", AppendStr("$e1.result", "\")\""))))>;}
|
||||
| ID {$result = $ID.text;}
|
||||
| e1=e '+' e2=e {$result = "(" + $e1.result + "+" + $e2.result + ")";}
|
||||
| e1=e '+' e2=e {$result = <AppendStr("\"(\"", AppendStr("$e1.result", AppendStr("\"+\"", AppendStr("$e2.result", "\")\""))))>;}
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
|
|
|
@ -766,6 +766,10 @@ public class LexerExecDescriptors {
|
|||
/**
|
||||
lexer grammar PositionAdjustingLexer;
|
||||
|
||||
@definitions {
|
||||
<PositionAdjustingLexerDef()>
|
||||
}
|
||||
|
||||
@members {
|
||||
<PositionAdjustingLexer()>
|
||||
}
|
||||
|
@ -1047,7 +1051,7 @@ public class LexerExecDescriptors {
|
|||
grammar = new String(Files.readAllBytes(Paths.get(stuff.toURI())));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("Cannot find grammar org/antlr/v4/test/runtime/LarseLexer.g4");
|
||||
System.err.println("Cannot find grammar org/antlr/v4/test/runtime/LargeLexer.g4");
|
||||
}
|
||||
|
||||
return new Pair<>(grammarName, grammar);
|
||||
|
|
|
@ -112,7 +112,7 @@ public class ParseTreesDescriptors {
|
|||
|
||||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
return !targetName.matches("Java|Python2|Python3|Node|Swift|CSharp");
|
||||
return !targetName.matches("Java|Python2|Python3|Node|Swift|CSharp|Dart");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ public class ParserErrorsDescriptors {
|
|||
|
||||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
return !"Java".equals(targetName);
|
||||
return !"Java".equals(targetName) && !"Swift".equals(targetName) && !"Dart".equals(targetName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -889,4 +889,32 @@ public class ParserExecDescriptors {
|
|||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a regression test for antlr/antlr4#2728
|
||||
* It should generate correct code for grammars with more than 65 tokens.
|
||||
* https://github.com/antlr/antlr4/pull/2728#issuecomment-622940562
|
||||
*/
|
||||
public static class TokenOffset extends BaseParserTestDescriptor {
|
||||
public String input = "12 34 56 66";
|
||||
public String output = "12345666\n";
|
||||
|
||||
public String errors = null;
|
||||
public String startRule = "a";
|
||||
public String grammarName = "L";
|
||||
|
||||
/**
|
||||
grammar L;
|
||||
a : ('1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|'13'|'14'|'15'|'16'
|
||||
|'17'|'18'|'19'|'20'|'21'|'22'|'23'|'24'|'25'|'26'|'27'|'28'|'29'|'30'|'31'|'32'
|
||||
|'33'|'34'|'35'|'36'|'37'|'38'|'39'|'40'|'41'|'42'|'43'|'44'|'45'|'46'|'47'|'48'
|
||||
|'49'|'50'|'51'|'52'|'53'|'54'|'55'|'56'|'57'|'58'|'59'|'60'|'61'|'62'|'63'|'64'
|
||||
|'65'|'66')+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
WS : (' '|'\n') -> skip;
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class PerformanceDescriptors {
|
|||
|
||||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
return !Arrays.asList("Java", "CSharp", "Python2", "Python3", "Node", "Cpp").contains(targetName);
|
||||
return !Arrays.asList("Java", "CSharp", "Python2", "Python3", "Node", "Cpp", "Swift", "Dart").contains(targetName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ public class PerformanceDescriptors {
|
|||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
// passes, but still too slow in Python and JavaScript
|
||||
return !Arrays.asList("Java", "CSharp", "Cpp").contains(targetName);
|
||||
return !Arrays.asList("Java", "CSharp", "Cpp", "Swift", "Dart").contains(targetName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,8 +144,8 @@ public class SemPredEvalParserDescriptors {
|
|||
/**
|
||||
grammar T;
|
||||
s : b[2] ';' | b[2] '.' ; // decision in s drills down to ctx-dependent pred in a;
|
||||
b[int i] : a[i] ;
|
||||
a[int i]
|
||||
b[<IntArg("i")>] : a[<VarRef("i")>] ;
|
||||
a[<IntArg("i")>]
|
||||
: {<ValEquals("$i","1")>}? ID {<writeln("\"alt 1\"")>}
|
||||
| {<ValEquals("$i","2")>}? ID {<writeln("\"alt 2\"")>}
|
||||
;
|
||||
|
@ -291,7 +291,7 @@ public class SemPredEvalParserDescriptors {
|
|||
|
||||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
return !"Java".equals(targetName);
|
||||
return !"Java".equals(targetName) && !"Swift".equals(targetName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ public class SemPredEvalParserDescriptors {
|
|||
grammar T;
|
||||
@parser::members {<InitBooleanMember("enumKeyword",True())>}
|
||||
primary
|
||||
: ID {<writeln("\"ID \"+$ID.text")>}
|
||||
: ID {<AppendStr("\"ID \"", "$ID.text"):writeln()>}
|
||||
| {<GetMember("enumKeyword"):Not()>}? 'enum' {<writeln("\"enum\"")>}
|
||||
;
|
||||
ID : [a-z]+ ;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* 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 org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.automata.ATNFactory;
|
||||
|
@ -626,23 +626,17 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
|||
+ "var <listenerName> = require('./<listenerName>').<listenerName>;\n"
|
||||
+ "var <visitorName> = require('./<visitorName>').<visitorName>;\n"
|
||||
+ "\n"
|
||||
+ "function TreeShapeListener() {\n"
|
||||
+ " antlr4.tree.ParseTreeListener.call(this);\n"
|
||||
+ " return this;\n"
|
||||
+ "}\n"
|
||||
+ "\n"
|
||||
+ "TreeShapeListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype);\n"
|
||||
+ "TreeShapeListener.prototype.constructor = TreeShapeListener;\n"
|
||||
+ "\n"
|
||||
+ "TreeShapeListener.prototype.enterEveryRule = function(ctx) {\n"
|
||||
+ " for(var i=0;i\\<ctx.getChildCount; i++) {\n"
|
||||
+ " var child = ctx.getChild(i);\n"
|
||||
+ " var parent = child.parentCtx;\n"
|
||||
+ " if(parent.getRuleContext() !== ctx || !(parent instanceof antlr4.tree.RuleNode)) {\n"
|
||||
+ " throw \"Invalid parse tree shape detected.\";\n"
|
||||
+ " }\n"
|
||||
+ " }\n"
|
||||
+ "};\n"
|
||||
+ "class TreeShapeListener extends antlr4.tree.ParseTreeListener {\n" +
|
||||
" enterEveryRule(ctx) {\n" +
|
||||
" for (let i = 0; i \\< ctx.getChildCount; i++) {\n" +
|
||||
" const child = ctx.getChild(i)\n" +
|
||||
" const parent = child.parentCtx\n" +
|
||||
" if (parent.getRuleContext() !== ctx || !(parent instanceof antlr4.tree.RuleNode)) {\n" +
|
||||
" throw `Invalid parse tree shape detected.`\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n"
|
||||
+ "\n"
|
||||
+ "function main(argv) {\n"
|
||||
+ " var input = new antlr4.FileStream(argv[2], true);\n"
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
|
@ -4,7 +4,7 @@
|
|||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
package org.antlr.v4.test.runtime.javascript;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue