forked from jasder/antlr
Merge branch 'master' into contributors.txt-sullis
This commit is contained in:
commit
118ad6be2b
|
@ -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/
|
||||
|
||||
|
@ -98,3 +98,6 @@ xcuserdata
|
|||
javac-services.0.log
|
||||
javac-services.0.log.lck
|
||||
test/
|
||||
|
||||
# Don't ignore python tests
|
||||
!runtime/Python3/test/
|
||||
|
|
33
.travis.yml
33
.travis.yml
|
@ -74,42 +74,42 @@ matrix:
|
|||
- clang-3.7
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=LEXER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=PARSER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=RECURSION
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=LEXER
|
||||
stage: main-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=PARSER
|
||||
stage: main-test
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=RECURSION
|
||||
|
@ -122,19 +122,19 @@ matrix:
|
|||
- GROUP=ALL
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=LEXER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=PARSER
|
||||
stage: extended-test
|
||||
- os: osx
|
||||
osx_image: xcode10.1
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=RECURSION
|
||||
|
@ -152,6 +152,10 @@ matrix:
|
|||
jdk: openjdk8
|
||||
env: TARGET=csharp
|
||||
stage: main-test
|
||||
- os: linux
|
||||
jdk: openjdk8
|
||||
env: TARGET=dart
|
||||
stage: main-test
|
||||
- os: linux
|
||||
language: php
|
||||
php:
|
||||
|
@ -192,13 +196,16 @@ matrix:
|
|||
sources:
|
||||
- deadsnakes # source required so it finds the package definition below
|
||||
packages:
|
||||
- python3.6
|
||||
- python3.7
|
||||
stage: main-test
|
||||
- os: linux
|
||||
dist: trusty
|
||||
jdk: openjdk8
|
||||
env: TARGET=javascript
|
||||
stage: main-test
|
||||
before_install:
|
||||
- nvm install 14 # otherwise it runs by default on node 8
|
||||
- f="./.travis/before-install-linux-javascript.sh"; ! [ -x "$f" ] || "$f"
|
||||
- os: linux
|
||||
dist: trusty
|
||||
jdk: openjdk8
|
||||
|
@ -211,7 +218,7 @@ before_install:
|
|||
script:
|
||||
- |
|
||||
cd runtime-testsuite;
|
||||
travis_wait 40 ../.travis/run-tests-$TARGET.sh;
|
||||
rc=$?;
|
||||
cat target/surefire-reports/*.dumpstream || true;
|
||||
travis_wait 40 ../.travis/run-tests-$TARGET.sh
|
||||
rc=$?
|
||||
cat target/surefire-reports/*.dumpstream || true
|
||||
exit $rc
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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,6 @@
|
|||
|
||||
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 -
|
||||
sudo apt-get install -qq nodejs
|
||||
node --version
|
||||
# use v14 and check
|
||||
echo node version: $(node --version)
|
||||
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
mvn -q -Dparallel=classes -DthreadCount=4 -Dtest=dart.* test
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=node.* test
|
||||
cd ../runtime/JavaScript
|
||||
npm install
|
||||
npm link
|
||||
cd ../../runtime-testsuite
|
||||
mvn -q -Dparallel=methods -DthreadCount=1 -Dtest=javascript.* test
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
python --version
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=python2.* test
|
||||
|
||||
cd ../runtime/Python2/tests
|
||||
|
||||
python run.py
|
||||
python run.py
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
python3 --version
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=python3.* test
|
||||
|
||||
cd ../runtime/Python3/test
|
||||
|
||||
python3.6 run.py
|
||||
python3 run.py
|
||||
|
|
|
@ -6,7 +6,7 @@ set -euo pipefail
|
|||
# here since environment variables doesn't pass
|
||||
# across scripts
|
||||
if [ $TRAVIS_OS_NAME == "linux" ]; then
|
||||
export SWIFT_VERSION=swift-4.2.1
|
||||
export SWIFT_VERSION=swift-5.0.1
|
||||
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu16.04/usr/bin/
|
||||
export PATH=$SWIFT_HOME:$PATH
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ ANTLR project lead and supreme dictator for life
|
|||
* [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.3-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
@ -120,7 +120,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
|
||||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||
|
|
|
@ -6,7 +6,9 @@ image: Visual Studio 2017
|
|||
build: off
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
- cinst -y php composer
|
||||
- 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
|
||||
|
@ -14,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-php-php="C:\tools\php73\php.exe" -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" --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
|
||||
|
@ -204,6 +208,7 @@ 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/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
|
||||
|
@ -214,16 +219,60 @@ YYYY/MM/DD, github id, Full name, email
|
|||
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/02, wkhemir, Wail Khemir, khemirwail@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/15, sullis, Sean Sullivan, github@seansullivan.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/05, listba, Ben List, ben.list89@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/17, quantumsheep, Nathanael Demacon, nathanael.dmc@outlook.fr
|
||||
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/08, lwehmeier, Leon Wehmeier, wehmeier@st.ovgu.de
|
||||
2020/04/10, agrabski, Adam Grabski, adam.gr@outlook.com
|
||||
2020/04/23, martinvw, Martin van Wingerden, martin@martinvw.nl
|
||||
2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com
|
||||
2020/05/06, iammosespaulr, Moses Paul R, iammosespaulr@gmail.com
|
||||
2020/05/10, gomerser, Erik Gomersbach, gomerser@gomersba.ch
|
||||
2020/05/22, keywan-ghadami-oxid, Keywan Ghadami, keywan.ghadami@oxid-esales.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/06/04, sigmasoldi3r, Pablo Blanco, pablobc.1995@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/10, Khailian, Arunav Sanyal, arunav.sanyal91@gmail.com
|
||||
2020/09/12, Clcanny, Charles Ruan, a837940593@gmail.com
|
||||
2020/09/15, rmcgregor1990, Robert McGregor, rmcgregor1990@gmail.com
|
||||
2020/09/16, trenki2, Markus Trenkwalder, trenki2[at]gmx[dot]net
|
||||
2020/10/08, Marti2203, Martin Mirchev, mirchevmartin2203@gmail.com
|
||||
2020/10/16, adarshbhat, Adarsh Bhat, adarshbhat@users.noreply.github.com
|
||||
2020/10/20, adamwojs, Adam Wójs, adam[at]wojs.pl
|
||||
2020/10/24, cliid, Jiwu Jang, jiwujang@naver.com
|
||||
2020/11/05, MichelHartmann, Michel Hartmann, MichelHartmann@users.noreply.github.com
|
|
@ -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](http://blorente.me/beyond-the-loop/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:
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ In order to execute this listener, you would simply add the following lines to t
|
|||
...
|
||||
IParseTree tree = parser.StartRule() - only repeated here for reference
|
||||
KeyPrinter printer = new KeyPrinter();
|
||||
ParseTreeWalker.DEFAULT.walk(printer, tree);
|
||||
ParseTreeWalker.Default.Walk(printer, tree);
|
||||
```
|
||||
|
||||
Further information can be found from The Definitive ANTLR Reference book.
|
||||
|
|
|
@ -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
|
||||
```
|
|
@ -38,8 +38,8 @@ This is the main landing page for the ANTLR 4 FAQ. The links below will take you
|
|||
|
||||
## Translation
|
||||
|
||||
* [ASTs vs parse trees](parse-trees.md)
|
||||
* [Decoupling input walking from output generation](parse-trees.md)
|
||||
* [ASTs vs parse trees](translation.md)
|
||||
* [Decoupling input walking from output generation](translation.md)
|
||||
|
||||
## Actions and semantic predicates
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ For writing a compiler, either generate [LLVM-type static-single-assignment](htt
|
|||
|
||||
### XPath
|
||||
|
||||
XPath works great when you need to find specific nodes, possibly in certain contexts. The context is limited to the parents on the way to the root of the tree. For example, if you want to find all ID nodes, use path `//ID`. If you want all variable declarations, you might use path `//vardecl`. If you only want fields declarations, then you can use some context information via path `/classdef/vardecl`, which would only find vardecls that our children of class definitions. You can merge the results of multiple XPath `findAll()`s simulating a set union for XPath. The only caveat is that the order from the original tree is not preserved when you union multiple `findAll()` sets.
|
||||
XPath works great when you need to find specific nodes, possibly in certain contexts. The context is limited to the parents on the way to the root of the tree. For example, if you want to find all ID nodes, use path `//ID`. If you want all variable declarations, you might use path `//vardecl`. If you only want fields declarations, then you can use some context information via path `/classdef/vardecl`, which would only find vardecls that are children of class definitions. You can merge the results of multiple XPath `findAll()`s simulating a set union for XPath. The only caveat is that the order from the original tree is not preserved when you union multiple `findAll()` sets.
|
||||
|
||||
### Tree pattern matching
|
||||
|
||||
|
@ -70,4 +70,4 @@ scopeStack.peek().define(new VariableSymbol("foo"))
|
|||
|
||||
That way each listener function does not have to compute its appropriate scope.
|
||||
|
||||
Examples: [DefScopesAndSymbols.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/DefScopesAndSymbols.java) and [SetScopeListener.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/SetScopeListener.java) and [VerifyListener.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/VerifyListener.java)
|
||||
Examples: [DefScopesAndSymbols.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/DefScopesAndSymbols.java) and [SetScopeListener.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/SetScopeListener.java) and [VerifyListener.java](https://github.com/mantra/compiler/blob/master/src/java/mantra/semantics/VerifyListener.java)
|
||||
|
|
|
@ -6,46 +6,46 @@ Hi and welcome to the version 4 release of ANTLR! It's named after the fearless
|
|||
|
||||
ANTLR is really two things: a tool that translates your grammar to a parser/lexer in Java (or other target language) and the runtime needed by the generated parsers/lexers. Even if you are using the ANTLR Intellij plug-in or ANTLRWorks to run the ANTLR tool, the generated code will still need the runtime library.
|
||||
|
||||
The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.7.1-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
|
||||
The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.9-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
|
||||
|
||||
If you are going to integrate ANTLR into your existing build system using mvn, ant, or want to get ANTLR into your IDE such as eclipse or intellij, see Integrating ANTLR into Development Systems.
|
||||
If you are going to integrate ANTLR into your existing build system using mvn, ant, or want to get ANTLR into your IDE such as eclipse or intellij, see [Integrating ANTLR into Development Systems](https://github.com/antlr/antlr4/blob/master/doc/IDEs.md).
|
||||
|
||||
### UNIX
|
||||
|
||||
0. Install Java (version 1.6 or higher)
|
||||
0. Install Java (version 1.7 or higher)
|
||||
1. Download
|
||||
```
|
||||
$ cd /usr/local/lib
|
||||
$ curl -O https://www.antlr.org/download/antlr-4.7.1-complete.jar
|
||||
$ curl -O https://www.antlr.org/download/antlr-4.9-complete.jar
|
||||
```
|
||||
Or just download in browser from website:
|
||||
[https://www.antlr.org/download.html](https://www.antlr.org/download.html)
|
||||
and put it somewhere rational like `/usr/local/lib`.
|
||||
|
||||
2. Add `antlr-4.7.1-complete.jar` to your `CLASSPATH`:
|
||||
2. Add `antlr-4.9-complete.jar` to your `CLASSPATH`:
|
||||
```
|
||||
$ export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH"
|
||||
$ export CLASSPATH=".:/usr/local/lib/antlr-4.9-complete.jar.jar:$CLASSPATH"
|
||||
```
|
||||
It's also a good idea to put this in your `.bash_profile` or whatever your startup script is.
|
||||
|
||||
3. Create aliases for the ANTLR Tool, and `TestRig`.
|
||||
```
|
||||
$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
|
||||
$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
|
||||
$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.9-complete.jar.jar:$CLASSPATH" org.antlr.v4.Tool'
|
||||
$ alias grun='java -Xmx500M -cp "/usr/local/lib/antlr-4.9-complete.jar.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'
|
||||
```
|
||||
|
||||
### WINDOWS
|
||||
|
||||
(*Thanks to Graham Wideman*)
|
||||
|
||||
0. Install Java (version 1.6 or higher)
|
||||
1. Download antlr-4.7.1-complete.jar (or whatever version) from [https://www.antlr.org/download/](https://www.antlr.org/download/)
|
||||
0. Install Java (version 1.7 or higher)
|
||||
1. Download antlr-4.9-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.7.1-complete.jar` to CLASSPATH, either:
|
||||
2. Add `antlr-4.9-complete.jar.jar` to CLASSPATH, either:
|
||||
* Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable
|
||||
* Temporarily, at command line:
|
||||
```
|
||||
SET CLASSPATH=.;C:\Javalib\antlr-4.7.1-complete.jar;%CLASSPATH%
|
||||
SET CLASSPATH=.;C:\Javalib\antlr-4.9-complete.jar;%CLASSPATH%
|
||||
```
|
||||
3. Create short convenient commands for the ANTLR Tool, and TestRig, using batch files or doskey commands:
|
||||
* Batch files (in directory in system PATH) antlr4.bat and grun.bat
|
||||
|
@ -71,7 +71,7 @@ Either launch org.antlr.v4.Tool directly:
|
|||
|
||||
```
|
||||
$ java org.antlr.v4.Tool
|
||||
ANTLR Parser Generator Version 4.7.1
|
||||
ANTLR Parser Generator Version 4.9
|
||||
-o ___ specify output directory where all output is generated
|
||||
-lib ___ specify location of .tokens files
|
||||
...
|
||||
|
@ -80,8 +80,8 @@ ANTLR Parser Generator Version 4.7.1
|
|||
or use -jar option on java:
|
||||
|
||||
```
|
||||
$ java -jar /usr/local/lib/antlr-4.7.1-complete.jar
|
||||
ANTLR Parser Generator Version 4.7.1
|
||||
$ java -jar /usr/local/lib/antlr-4.9-complete.jar
|
||||
ANTLR Parser Generator Version 4.9
|
||||
-o ___ specify output directory where all output is generated
|
||||
-lib ___ specify location of .tokens files
|
||||
...
|
||||
|
@ -138,3 +138,4 @@ The book has lots and lots of examples that should be useful too. You can downlo
|
|||
Also, there is a large collection of grammars for v4 at github:
|
||||
|
||||
[https://github.com/antlr/grammars-v4](https://github.com/antlr/grammars-v4)
|
||||
/
|
|
@ -11,11 +11,18 @@ In practice, this target has been extensively tested against:
|
|||
* Chrome 39.0.2171
|
||||
* Explorer 11.0.3
|
||||
|
||||
The tests were conducted using Selenium. No issue was found, so you should find that the runtime works pretty much against any recent JavaScript engine.
|
||||
The above tests were conducted using Selenium. No issue was found, so you should find that the runtime works pretty much against any recent JavaScript engine.
|
||||
|
||||
## 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 14 LTS. No issue was found.
|
||||
NodeJS together with a packaging tool is now the preferred development path, developers are encouraged to follow it.
|
||||
|
||||
## What about modules?
|
||||
|
||||
Starting with version 8.1, Antlr4 JavaScript runtime follows esm semantics (see https://tc39.es/ecma262/#sec-modules for details)
|
||||
Generated lexers, parsers, listeners and visitors also follow this new standard.
|
||||
If you have used previous versions of the runtime, you will need to migrate and make your parser a module.
|
||||
|
||||
## How to create a JavaScript lexer or parser?
|
||||
|
||||
|
@ -55,32 +62,20 @@ 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" }
|
||||
- For Webpack version 5,
|
||||
- in the `webpack.config` file, exclude node.js only modules using: `resolve: { fallback: { fs: false } }`
|
||||
- For older versions of Webpack,
|
||||
- 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:
|
||||
|
@ -95,18 +90,18 @@ Let's suppose that your grammar is named, as above, "MyGrammar". Let's suppose t
|
|||
Now a fully functioning script might look like the following:
|
||||
|
||||
```javascript
|
||||
var antlr4 = require('antlr4');
|
||||
var MyGrammarLexer = require('./MyGrammarLexer').MyGrammarLexer;
|
||||
var MyGrammarParser = require('./MyGrammarParser').MyGrammarParser;
|
||||
var MyGrammarListener = require('./MyGrammarListener').MyGrammarListener;
|
||||
import antlr4 from 'antlr4';
|
||||
import MyGrammarLexer from './MyGrammarLexer.js');
|
||||
import MyGrammarParser from './MyGrammarParser.js';
|
||||
import MyGrammarListener from './MyGrammarListener.js';
|
||||
|
||||
var input = "your text to parse here"
|
||||
var chars = new antlr4.InputStream(input);
|
||||
var lexer = new MyGrammarLexer(chars);
|
||||
var tokens = new antlr4.CommonTokenStream(lexer);
|
||||
var parser = new MyGrammarParser(tokens);
|
||||
const input = "your text to parse here"
|
||||
const chars = new antlr4.InputStream(input);
|
||||
const lexer = new MyGrammarLexer(chars);
|
||||
const tokens = new antlr4.CommonTokenStream(lexer);
|
||||
const parser = new MyGrammarParser(tokens);
|
||||
parser.buildParseTrees = true;
|
||||
var tree = parser.MyStartRule();
|
||||
const tree = parser.MyStartRule();
|
||||
```
|
||||
|
||||
This program will work. But it won't be useful unless you do one of the following:
|
||||
|
@ -120,19 +115,19 @@ This program will work. But it won't be useful unless you do one of the followin
|
|||
## 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;
|
||||
import antlr4 from 'antlr4';
|
||||
import MyGrammarLexer from './QueryLexer.js';
|
||||
import MyGrammarParser from './QueryParser.js';
|
||||
import MyGrammarListener from './QueryListener.js';
|
||||
|
||||
|
||||
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);
|
||||
const input = "field = 123 AND items in (1,2,3)"
|
||||
const chars = new antlr4.InputStream(input);
|
||||
const lexer = new MyGrammarLexer(chars);
|
||||
const tokens = new antlr4.CommonTokenStream(lexer);
|
||||
const parser = new MyGrammarParser(tokens);
|
||||
parser.buildParseTrees = true;
|
||||
var tree = parser.query();
|
||||
const tree = parser.query();
|
||||
|
||||
class Visitor {
|
||||
visitChildren(ctx) {
|
||||
|
@ -160,40 +155,37 @@ tree.accept(new Visitor());
|
|||
Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value". The antlr4 tool will have generated the following listener:
|
||||
|
||||
```javascript
|
||||
MyGrammarListener = function(ParseTreeListener) {
|
||||
// some code here
|
||||
}
|
||||
// some code here
|
||||
MyGrammarListener.prototype.enterKey = function(ctx) {};
|
||||
MyGrammarListener.prototype.exitKey = function(ctx) {};
|
||||
MyGrammarListener.prototype.enterValue = function(ctx) {};
|
||||
MyGrammarListener.prototype.exitValue = function(ctx) {};
|
||||
class MyGrammarListener extends ParseTreeListener {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
enterKey(ctx) {}
|
||||
exitKey(ctx) {}
|
||||
enterValue(ctx) {}
|
||||
exitValue(ctx) {}
|
||||
}
|
||||
```
|
||||
|
||||
In order to provide custom behavior, you might want to create the following class:
|
||||
|
||||
```javascript
|
||||
var KeyPrinter = function() {
|
||||
MyGrammarListener.call(this); // inherit default listener
|
||||
return this;
|
||||
};
|
||||
class KeyPrinter extends MyGrammarListener {
|
||||
|
||||
// continue inheriting default listener
|
||||
KeyPrinter.prototype = Object.create(MyGrammarListener.prototype);
|
||||
KeyPrinter.prototype.constructor = KeyPrinter;
|
||||
|
||||
// override default listener behavior
|
||||
KeyPrinter.prototype.exitKey = function(ctx) {
|
||||
console.log("Oh, a key!");
|
||||
};
|
||||
// override default listener behavior
|
||||
exitKey(ctx) {
|
||||
console.log("Oh, a key!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In order to execute this listener, you would simply add the following lines to the above code:
|
||||
|
||||
```javascript
|
||||
...
|
||||
tree = parser.StartRule() // only repeated here for reference
|
||||
var printer = new KeyPrinter();
|
||||
...
|
||||
tree = parser.StartRule() // only repeated here for reference
|
||||
const printer = new KeyPrinter();
|
||||
antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree);
|
||||
```
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ Match that character or sequence of characters. E.g., ’while’ or ’=’.</t
|
|||
|
||||
<tr>
|
||||
<td>[char set]</td><td>
|
||||
<p>Match one of the characters specified in the character set. Interpret <tt>x-y</tt> as the set of characters between range <tt>x</tt> and <tt>y</tt>, inclusively. The following escaped characters are interpreted as single special characters: <tt>\n</tt>, <tt>\r</tt>, <tt>\b</tt>, <tt>\t</tt>, <tt>\f</tt>, <tt>\uXXXX</tt>, and <tt>\u{XXXXXX}</tt>. To get <tt>]</tt>, <tt>\</tt>, or <tt>-</tt> you must escape them with <tt>\</tt>.</p>
|
||||
<p>Match one of the characters specified in the character set. Interpret <tt>x-y</tt> as the set of characters between range <tt>x</tt> and <tt>y</tt>, inclusively. The following escaped characters are interpreted as single special characters: <tt>\n</tt>, <tt>\r</tt>, <tt>\b</tt>, <tt>\t</tt>, <tt>\f</tt>, <tt>\uXXXX</tt>, and <tt>\u{XXXXXX}</tt>. To get <tt>]</tt> or <tt>\</tt> you must escape them with <tt>\</tt>. To get <tt>-</tt> you must escape it with <tt>\</tt> too, except for the case when <tt>-</tt> is the first or last character in the set.</p>
|
||||
|
||||
<p>You can also include all characters matching Unicode properties (general category, boolean, or enumerated including scripts and blocks) with <tt>\p{PropertyName}</tt> or <tt>\p{EnumProperty=Value}</tt>. (You can invert the test with <tt>\P{PropertyName}</tt> or <tt>\P{EnumProperty=Value}</tt>).</p>
|
||||
|
||||
|
@ -90,6 +90,8 @@ UNICODE_ID : [\p{Alpha}\p{General_Category=Other_Letter}] [\p{Alnum}\p{General_C
|
|||
EMOJI : [\u{1F4A9}\u{1F926}] ; // note Unicode code points > U+FFFF
|
||||
|
||||
DASHBRACK : [\-\]]+ ; // match - or ] one or more times
|
||||
|
||||
DASH : [---] ; // match a single -, i.e., "any character" between - and - (note first and last - not escaped)
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -123,7 +125,7 @@ ESC : '\\' . ; // match any escaped \x character
|
|||
|
||||
<tr>
|
||||
<td>{«action»}</td><td>
|
||||
Lexer actions can appear anywhere as of 4.2, not just at the end of the outermost alternative. The lexer executes the actions at the appropriate input position, according to the placement of the action within the rule. To execute a single action for a role that has multiple alternatives, you can enclose the alts in parentheses and put the action afterwards:
|
||||
Lexer actions can appear anywhere as of 4.2, not just at the end of the outermost alternative. The lexer executes the actions at the appropriate input position, according to the placement of the action within the rule. To execute a single action for a rule that has multiple alternatives, you can enclose the alts in parentheses and put the action afterwards:
|
||||
|
||||
<pre>
|
||||
END : ('endif'|'end') {System.out.println("found an end");} ;
|
||||
|
@ -244,7 +246,8 @@ The mode commands alter the mode stack and hence the mode of the lexer. The 'mor
|
|||
```
|
||||
// Default "mode": Everything OUTSIDE of a tag
|
||||
COMMENT : '<!--' .*? '-->' ;
|
||||
CDATA : '<![CDATA[' .*? ']]>' ;OPEN : '<' -> pushMode(INSIDE) ;
|
||||
CDATA : '<![CDATA[' .*? ']]>' ;
|
||||
OPEN : '<' -> pushMode(INSIDE) ;
|
||||
...
|
||||
XMLDeclOpen : '<?xml' S -> pushMode(INSIDE) ;
|
||||
SPECIAL_OPEN: '<?' Name -> more, pushMode(PROC_INSTR) ;
|
||||
|
|
|
@ -26,8 +26,8 @@ The Javadoc comments are hidden from the parser and are ignored at the moment.
|
|||
Token names always start with a capital letter and so do lexer rules as defined by Java’s `Character.isUpperCase` method. Parser rule names always start with a lowercase letter (those that fail `Character.isUpperCase`). The initial character can be followed by uppercase and lowercase letters, digits, and underscores. Here are some sample names:
|
||||
|
||||
```
|
||||
ID, LPAREN, RIGHT_CURLY // token names/rules
|
||||
expr, simpleDeclarator, d2, header_file // rule names
|
||||
ID, LPAREN, RIGHT_CURLY // token names/lexer rules
|
||||
expr, simpleDeclarator, d2, header_file // parser rule names
|
||||
```
|
||||
|
||||
Like Java, ANTLR accepts Unicode characters in ANTLR names:
|
||||
|
@ -96,7 +96,7 @@ The recognizers that ANTLR generates assume a character vocabulary containing al
|
|||
|
||||
## Actions
|
||||
|
||||
Actions are code blocks written in the target language. You can use actions in a number of places within a grammar, but the syntax is always the same: arbitrary text surrounded by curly braces. You don’t need to escape a closing curly character if it’s in a string or comment: `"}"` or `/*}*/`. If the curlies are balanced, you also don’t need to escape }: `{...}`. Otherwise, escape extra curlies with a backslash: `\{` or `\}`. The action text should conform to the target language as specified with thelanguage option.
|
||||
Actions are code blocks written in the target language. You can use actions in a number of places within a grammar, but the syntax is always the same: arbitrary text surrounded by curly braces. You don’t need to escape a closing curly character if it’s in a string or comment: `"}"` or `/*}*/`. If the curlies are balanced, you also don’t need to escape }: `{...}`. Otherwise, escape extra curlies with a backslash: `\{` or `\}`. The action text should conform to the target language as specified with the language option.
|
||||
|
||||
Embedded code can appear in: `@header` and `@members` named actions, parser and lexer rules, exception catching specifications, attribute sections for parser rules (return values, arguments, and locals), and some rule element options (currently predicates).
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ generated by ANTLR4. The runtime provides a common set of tools for using your p
|
|||
Install the runtime with Composer:
|
||||
|
||||
```bash
|
||||
composer install antlr/antlr4
|
||||
composer require antlr4-php-runtime
|
||||
```
|
||||
|
||||
#### 3. Generate your parser
|
||||
|
@ -108,4 +108,4 @@ The expected output is:
|
|||
{"a":1}
|
||||
"a":1
|
||||
1
|
||||
```
|
||||
```
|
||||
|
|
|
@ -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] ------------------------------------------------------------------------
|
||||
|
@ -192,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"
|
||||
|
@ -217,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:
|
||||
|
@ -238,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
|
||||
```
|
||||
|
||||
|
@ -247,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
|
||||
```
|
||||
|
@ -264,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
|
||||
|
@ -309,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**
|
||||
|
@ -371,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.
|
||||
|
@ -385,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:
|
||||
|
@ -393,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_**):
|
||||
|
@ -409,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:
|
||||
|
@ -433,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
|
||||
|
|
|
@ -10,12 +10,13 @@ This page lists the available and upcoming ANTLR runtimes. Please note that you
|
|||
* [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|PHP
|
||||
|---|---|---|---|---|---|---|---|---|---|
|
||||
|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.3-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>ANTLR 4</name>
|
||||
|
@ -151,7 +151,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.3-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.3-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.1</version>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -59,19 +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>
|
||||
<!-- stick to version 9 for jdk compatibility -->
|
||||
<version>9.4.19.v20190610</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
|
@ -112,10 +99,11 @@
|
|||
<include>**/csharp/Test*.java</include>
|
||||
<include>**/java/Test*.java</include>
|
||||
<include>**/go/Test*.java</include>
|
||||
<include>**/javascript/node/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>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.7.3-SNAPSHOT</version>
|
||||
<version>4.8-2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>antlr4-runtime-test-annotation-processors</artifactId>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= "System.Collections.IList __ttt__ = <v>;" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -78,7 +74,7 @@ LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
|||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<var <X>Listener = require('./<X>Listener').<X>Listener;>>
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@ Append(a,b) ::= "<a> + <b>->toString()"
|
|||
Concat(a,b) ::= "<a><b>"
|
||||
AppendStr(a,b) ::= "<a> + <b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually).
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
|
@ -25,7 +23,6 @@ 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>"
|
||||
|
|
|
@ -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>"
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array"}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -80,11 +76,7 @@ LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
|||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= "<a> + <b>"
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s, v) ::= "var <s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= ""
|
||||
|
||||
AssignLocal(s, v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -107,6 +103,8 @@ 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
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -78,11 +74,7 @@ LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
|||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
|
@ -192,18 +184,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; }
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= "<a> + <b>"
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= "<a> + <b>"
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -78,11 +74,7 @@ LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
|||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ AppendStr(a,b) ::= <%<Append(a,b)>%>
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "var __ttt__ = <v>;" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>"
|
||||
|
@ -40,8 +38,6 @@ 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>%>
|
||||
|
@ -133,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
|
||||
}
|
||||
|
||||
|
@ -147,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
|
||||
}
|
||||
|
|
|
@ -46,15 +46,14 @@ import static org.junit.Assume.assumeFalse;
|
|||
public abstract class BaseRuntimeTest {
|
||||
public final static String[] Targets = {
|
||||
"Cpp",
|
||||
"Java",
|
||||
"Go",
|
||||
"CSharp",
|
||||
"Python2", "Python3",
|
||||
"Dart",
|
||||
"Go",
|
||||
"Java",
|
||||
"Node",
|
||||
"PHP",
|
||||
"Node", "Safari", "Firefox", "Explorer", "Chrome"
|
||||
};
|
||||
public final static String[] JavaScriptTargets = {
|
||||
"Node", "Safari", "Firefox", "Explorer", "Chrome"
|
||||
"Python2", "Python3",
|
||||
"Swift"
|
||||
};
|
||||
|
||||
static {
|
||||
|
@ -97,10 +96,17 @@ public abstract class BaseRuntimeTest {
|
|||
public void setUp() throws Exception {
|
||||
// From http://junit.sourceforge.net/javadoc/org/junit/Assume.html
|
||||
// "The default JUnit runner treats tests with failing assumptions as ignored"
|
||||
assumeFalse(descriptor.ignore(descriptor.getTarget()));
|
||||
assumeFalse(checkIgnored());
|
||||
delegate.testSetUp();
|
||||
}
|
||||
|
||||
public boolean checkIgnored() {
|
||||
boolean ignored = !TestContext.isSupportedTarget(descriptor.getTarget()) || descriptor.ignore(descriptor.getTarget());
|
||||
if(ignored)
|
||||
System.out.println("Ignore " + descriptor);
|
||||
return ignored;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final TestRule testWatcher = new TestWatcher() {
|
||||
@Override
|
||||
|
@ -114,7 +120,7 @@ public abstract class BaseRuntimeTest {
|
|||
public void testOne() throws Exception {
|
||||
// System.out.println(delegate.getTmpDir());
|
||||
if ( descriptor.ignore(descriptor.getTarget()) ) {
|
||||
System.out.printf("Ignore "+descriptor);
|
||||
System.out.println("Ignore " + descriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -275,6 +281,8 @@ public abstract class BaseRuntimeTest {
|
|||
// ---- support ----
|
||||
|
||||
public static RuntimeTestDescriptor[] getRuntimeTestDescriptors(Class<?> clazz, String targetName) {
|
||||
if(!TestContext.isSupportedTarget(targetName))
|
||||
return new RuntimeTestDescriptor[0];
|
||||
Class<?>[] nestedClasses = clazz.getClasses();
|
||||
List<RuntimeTestDescriptor> descriptors = new ArrayList<RuntimeTestDescriptor>();
|
||||
for (Class<?> nestedClass : nestedClasses) {
|
||||
|
@ -282,8 +290,10 @@ public abstract class BaseRuntimeTest {
|
|||
if ( RuntimeTestDescriptor.class.isAssignableFrom(nestedClass) && !Modifier.isAbstract(modifiers) ) {
|
||||
try {
|
||||
RuntimeTestDescriptor d = (RuntimeTestDescriptor) nestedClass.newInstance();
|
||||
d.setTarget(targetName);
|
||||
descriptors.add(d);
|
||||
if(!d.ignore(targetName)) {
|
||||
d.setTarget(targetName);
|
||||
descriptors.add(d);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
@ -302,6 +312,16 @@ public abstract class BaseRuntimeTest {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.antlr.v4.test.runtime;
|
||||
|
||||
public abstract class TestContext {
|
||||
|
||||
public static boolean isTravisCI() {
|
||||
return "true".equals(String.valueOf(System.getenv("TRAVIS")).toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean isAppVeyorCI() {
|
||||
return "true".equals(String.valueOf(System.getenv("APPVEYOR")).toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean isSupportedTarget(String target) {
|
||||
if(isAppVeyorCI())
|
||||
return !target.matches("Swift|Node");
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
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.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.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 BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LexerErrorsDescriptors.class, "Chrome");
|
||||
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.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.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 BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParseTreesDescriptors.class, "Chrome");
|
||||
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.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.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 BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalParserDescriptors.class, "Chrome");
|
||||
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.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.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 BaseChromeTest());
|
||||
super(descriptor,new BaseDartTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SetsDescriptors.class, "Chrome");
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SetsDescriptors.class, "Dart");
|
||||
}
|
||||
}
|
|
@ -1051,10 +1051,39 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a regression test for antlr/antlr4#2709 "PHP target generates
|
||||
* invalid output when $ is used as part of the literal in lexer rule"
|
||||
* https://github.com/antlr/antlr4/issues/2709
|
||||
*/
|
||||
public static class EscapeTargetStringLiteral extends BaseLexerTestDescriptor {
|
||||
/**
|
||||
[@0,0:-1='<EOF>',<-1>,1:0]
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String output;
|
||||
|
||||
public String errors = null;
|
||||
public String startRule = "";
|
||||
public String grammarName = "L";
|
||||
|
||||
/**
|
||||
lexer grammar L;
|
||||
ACTION_WITH_DOLLAR: '$ACTION';
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
|
||||
@Override
|
||||
public boolean ignore(String targetName) {
|
||||
return !targetName.equals("PHP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) && !"Swift".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", "Swift").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", "Swift").contains(targetName);
|
||||
return !Arrays.asList("Java", "CSharp", "Cpp", "Swift", "Dart").contains(targetName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,533 @@
|
|||
/*
|
||||
* 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.javascript;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.automata.ATNFactory;
|
||||
import org.antlr.v4.automata.ATNPrinter;
|
||||
import org.antlr.v4.automata.LexerATNFactory;
|
||||
import org.antlr.v4.automata.ParserATNFactory;
|
||||
import org.antlr.v4.codegen.CodeGenerator;
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.IntStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.RuleContext;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenSource;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.WritableToken;
|
||||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNDeserializer;
|
||||
import org.antlr.v4.runtime.atn.ATNSerializer;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||
import org.antlr.v4.test.runtime.TestContext;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupString;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BaseNodeTest implements RuntimeTestSupport {
|
||||
// -J-Dorg.antlr.v4.test.BaseTest.level=FINE
|
||||
// private static final Logger LOGGER =
|
||||
// Logger.getLogger(BaseTest.class.getName());
|
||||
|
||||
public static final String newline = System.getProperty("line.separator");
|
||||
public static final String pathSep = System.getProperty("path.separator");
|
||||
|
||||
public String tmpdir = null;
|
||||
|
||||
/**
|
||||
* If error during parser execution, store stderr here; can't return stdout
|
||||
* and stderr. This doesn't trap errors from running antlr.
|
||||
*/
|
||||
protected String stderrDuringParse;
|
||||
|
||||
/** Errors found while running antlr */
|
||||
protected StringBuilder antlrToolErrors;
|
||||
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
// new output dir for each test
|
||||
String prop = System.getProperty("antlr-javascript-test-dir");
|
||||
if (prop != null && prop.length() > 0) {
|
||||
tmpdir = prop;
|
||||
}
|
||||
else {
|
||||
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass()
|
||||
.getSimpleName()+"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis())
|
||||
.getAbsolutePath();
|
||||
}
|
||||
File dir = new File(tmpdir);
|
||||
if (dir.exists())
|
||||
this.eraseFiles(dir);
|
||||
antlrToolErrors = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testTearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpDir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStdout() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParseErrors() {
|
||||
return stderrDuringParse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getANTLRToolErrors() {
|
||||
if ( antlrToolErrors.length()==0 ) {
|
||||
return null;
|
||||
}
|
||||
return antlrToolErrors.toString();
|
||||
}
|
||||
|
||||
protected ATN createATN(Grammar g, boolean useSerializer) {
|
||||
if (g.atn == null) {
|
||||
semanticProcess(g);
|
||||
assertEquals(0, g.tool.getNumErrors());
|
||||
|
||||
ParserATNFactory f;
|
||||
if (g.isLexer()) {
|
||||
f = new LexerATNFactory((LexerGrammar) g);
|
||||
}
|
||||
else {
|
||||
f = new ParserATNFactory(g);
|
||||
}
|
||||
|
||||
g.atn = f.createATN();
|
||||
assertEquals(0, g.tool.getNumErrors());
|
||||
}
|
||||
|
||||
ATN atn = g.atn;
|
||||
if (useSerializer) {
|
||||
char[] serialized = ATNSerializer.getSerializedAsChars(atn);
|
||||
return new ATNDeserializer().deserialize(serialized);
|
||||
}
|
||||
|
||||
return atn;
|
||||
}
|
||||
|
||||
protected void semanticProcess(Grammar g) {
|
||||
if (g.ast != null && !g.ast.hasErrors) {
|
||||
System.out.println(g.ast.toStringTree());
|
||||
Tool antlr = new Tool();
|
||||
SemanticPipeline sem = new SemanticPipeline(g);
|
||||
sem.process();
|
||||
if (g.getImportedGrammars() != null) { // process imported grammars
|
||||
// (if any)
|
||||
for (Grammar imp : g.getImportedGrammars()) {
|
||||
antlr.processNonCombinedGrammar(imp, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String execLexer(String grammarFileName, String grammarStr,
|
||||
String lexerName, String input) {
|
||||
return execLexer(grammarFileName, grammarStr, lexerName, input, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execLexer(String grammarFileName, String grammarStr,
|
||||
String lexerName, String input, boolean showDFA) {
|
||||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr, null, lexerName, "-no-listener");
|
||||
assertTrue(success);
|
||||
writeFile(tmpdir, "input", input);
|
||||
writeLexerTestFile(lexerName, showDFA);
|
||||
writeFile(tmpdir, "package.json", "{\"type\": \"module\"}");
|
||||
String output = execModule("Test.js");
|
||||
if ( output!=null && output.length()==0 ) {
|
||||
output = null;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execParser(String grammarFileName, String grammarStr,
|
||||
String parserName, String lexerName, String listenerName,
|
||||
String visitorName, String startRuleName, String input,
|
||||
boolean showDiagnosticErrors)
|
||||
{
|
||||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr, parserName, lexerName, "-visitor");
|
||||
assertTrue(success);
|
||||
writeFile(tmpdir, "input", input);
|
||||
rawBuildRecognizerTestFile(parserName, lexerName, listenerName,
|
||||
visitorName, startRuleName, showDiagnosticErrors);
|
||||
writeFile(tmpdir, "package.json", "{\"type\": \"module\"}");
|
||||
return execRecognizer();
|
||||
}
|
||||
|
||||
/** Return true if all is well */
|
||||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr, String parserName, String lexerName,
|
||||
String... extraOptions) {
|
||||
return rawGenerateAndBuildRecognizer(grammarFileName, grammarStr,
|
||||
parserName, lexerName, false, extraOptions);
|
||||
}
|
||||
|
||||
/** Return true if all is well */
|
||||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr, String parserName, String lexerName,
|
||||
boolean defaultListener, String... extraOptions) {
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "JavaScript", grammarFileName, grammarStr,
|
||||
defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> files = new ArrayList<String>();
|
||||
if (lexerName != null) {
|
||||
files.add(lexerName + ".js");
|
||||
}
|
||||
if (parserName != null) {
|
||||
files.add(parserName + ".js");
|
||||
Set<String> optionsSet = new HashSet<String>(
|
||||
Arrays.asList(extraOptions));
|
||||
if (!optionsSet.contains("-no-listener")) {
|
||||
files.add(grammarFileName.substring(0,
|
||||
grammarFileName.lastIndexOf('.'))
|
||||
+ "Listener.js");
|
||||
}
|
||||
if (optionsSet.contains("-visitor")) {
|
||||
files.add(grammarFileName.substring(0,
|
||||
grammarFileName.lastIndexOf('.'))
|
||||
+ "Visitor.js");
|
||||
}
|
||||
}
|
||||
return true; // allIsWell: no compile
|
||||
}
|
||||
|
||||
protected void rawBuildRecognizerTestFile(String parserName,
|
||||
String lexerName, String listenerName, String visitorName,
|
||||
String parserStartRuleName, boolean debug) {
|
||||
this.stderrDuringParse = null;
|
||||
if (parserName == null) {
|
||||
writeLexerTestFile(lexerName, false);
|
||||
}
|
||||
else {
|
||||
writeParserTestFile(parserName, lexerName, listenerName,
|
||||
visitorName, parserStartRuleName, debug);
|
||||
}
|
||||
}
|
||||
|
||||
public String execRecognizer() {
|
||||
return execModule("Test.js");
|
||||
}
|
||||
|
||||
public String execModule(String fileName) {
|
||||
try {
|
||||
String npmPath = locateNpm();
|
||||
if(!TestContext.isTravisCI()) {
|
||||
installRuntime(npmPath);
|
||||
registerRuntime(npmPath);
|
||||
}
|
||||
String modulePath = new File(new File(tmpdir), fileName)
|
||||
.getAbsolutePath();
|
||||
linkRuntime(npmPath);
|
||||
String nodejsPath = locateNodeJS();
|
||||
String inputPath = new File(new File(tmpdir), "input")
|
||||
.getAbsolutePath();
|
||||
ProcessBuilder builder = new ProcessBuilder(nodejsPath, modulePath,
|
||||
inputPath);
|
||||
builder.environment().put("NODE_PATH", tmpdir);
|
||||
builder.directory(new File(tmpdir));
|
||||
Process process = builder.start();
|
||||
StreamVacuum stdoutVacuum = new StreamVacuum(
|
||||
process.getInputStream());
|
||||
StreamVacuum stderrVacuum = new StreamVacuum(
|
||||
process.getErrorStream());
|
||||
stdoutVacuum.start();
|
||||
stderrVacuum.start();
|
||||
// TODO switch to jdk 8
|
||||
process.waitFor();
|
||||
// if(!process.waitFor(1L, TimeUnit.MINUTES))
|
||||
// process.destroyForcibly();
|
||||
stdoutVacuum.join();
|
||||
stderrVacuum.join();
|
||||
String output = stdoutVacuum.toString();
|
||||
if ( output.length()==0 ) {
|
||||
output = null;
|
||||
}
|
||||
if (stderrVacuum.toString().length() > 0) {
|
||||
this.stderrDuringParse = stderrVacuum.toString();
|
||||
}
|
||||
return output;
|
||||
} catch (Exception e) {
|
||||
System.err.println("can't exec recognizer");
|
||||
e.printStackTrace(System.err);
|
||||
System.err.println();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void installRuntime(String npmPath) throws IOException, InterruptedException {
|
||||
String runtimePath = locateRuntime();
|
||||
ProcessBuilder builder = new ProcessBuilder(npmPath, "install");
|
||||
builder.directory(new File(runtimePath));
|
||||
builder.redirectError(new File(tmpdir, "error.txt"));
|
||||
builder.redirectOutput(new File(tmpdir, "output.txt"));
|
||||
Process process = builder.start();
|
||||
// TODO switch to jdk 8
|
||||
process.waitFor();
|
||||
// if(!process.waitFor(30L, TimeUnit.SECONDS))
|
||||
// process.destroyForcibly();
|
||||
int error = process.exitValue();
|
||||
if(error!=0)
|
||||
throw new IOException("'npm install' failed");
|
||||
}
|
||||
|
||||
private void registerRuntime(String npmPath) throws IOException, InterruptedException {
|
||||
String runtimePath = locateRuntime();
|
||||
ProcessBuilder builder = new ProcessBuilder(npmPath, "link");
|
||||
builder.directory(new File(runtimePath));
|
||||
builder.redirectError(new File(tmpdir, "error.txt"));
|
||||
builder.redirectOutput(new File(tmpdir, "output.txt"));
|
||||
Process process = builder.start();
|
||||
// TODO switch to jdk 8
|
||||
process.waitFor();
|
||||
// if(!process.waitFor(30L, TimeUnit.SECONDS))
|
||||
// process.destroyForcibly();
|
||||
int error = process.exitValue();
|
||||
if(error!=0)
|
||||
throw new IOException("'npm link' failed");
|
||||
}
|
||||
|
||||
private void linkRuntime(String npmPath) throws IOException, InterruptedException {
|
||||
ProcessBuilder builder = new ProcessBuilder(npmPath, "link", "antlr4");
|
||||
builder.directory(new File(tmpdir));
|
||||
builder.redirectError(new File(tmpdir, "error.txt"));
|
||||
builder.redirectOutput(new File(tmpdir, "output.txt"));
|
||||
Process process = builder.start();
|
||||
// TODO switch to jdk 8
|
||||
process.waitFor();
|
||||
// if(!process.waitFor(30L, TimeUnit.SECONDS))
|
||||
// process.destroyForcibly();
|
||||
int error = process.exitValue();
|
||||
if(error!=0)
|
||||
throw new IOException("'npm link antlr4' failed");
|
||||
}
|
||||
|
||||
private boolean canExecute(String tool) {
|
||||
try {
|
||||
ProcessBuilder builder = new ProcessBuilder(tool, "--version");
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = builder.start();
|
||||
StreamVacuum vacuum = new StreamVacuum(process.getInputStream());
|
||||
vacuum.start();
|
||||
// TODO switch to jdk 8
|
||||
process.waitFor();
|
||||
// if(!process.waitFor(30L, TimeUnit.SECONDS))
|
||||
// process.destroyForcibly();
|
||||
vacuum.join();
|
||||
return process.exitValue() == 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String locateNpm() {
|
||||
// typically /usr/local/bin/npm
|
||||
String prop = System.getProperty("antlr-javascript-npm");
|
||||
if ( prop!=null && prop.length()!=0 ) {
|
||||
return prop;
|
||||
}
|
||||
return "npm"; // everywhere
|
||||
}
|
||||
|
||||
private String locateNodeJS() {
|
||||
// typically /usr/local/bin/node
|
||||
String prop = System.getProperty("antlr-javascript-nodejs");
|
||||
if ( prop!=null && prop.length()!=0 ) {
|
||||
return prop;
|
||||
}
|
||||
if (canExecute("nodejs")) {
|
||||
return "nodejs"; // nodejs on Debian without node-legacy package
|
||||
}
|
||||
return "node"; // everywhere else
|
||||
}
|
||||
|
||||
private String locateRuntime() {
|
||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
final URL runtimeSrc = loader.getResource("JavaScript");
|
||||
if ( runtimeSrc==null ) {
|
||||
throw new RuntimeException("Cannot find JavaScript runtime");
|
||||
}
|
||||
if(isWindows()){
|
||||
return runtimeSrc.getPath().replaceFirst("/", "");
|
||||
}
|
||||
return runtimeSrc.getPath();
|
||||
}
|
||||
|
||||
private boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().contains("windows");
|
||||
}
|
||||
|
||||
|
||||
protected void writeParserTestFile(String parserName, String lexerName,
|
||||
String listenerName, String visitorName,
|
||||
String parserStartRuleName, boolean debug) {
|
||||
ST outputFileST = new ST(
|
||||
"import antlr4 from 'antlr4';\n"
|
||||
+ "import <lexerName> from './<lexerName>.js';\n"
|
||||
+ "import <parserName> from './<parserName>.js';\n"
|
||||
+ "import <listenerName> from './<listenerName>.js';\n"
|
||||
+ "import <visitorName> from './<visitorName>.js';\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"
|
||||
+ " var lexer = new <lexerName>(input);\n"
|
||||
+ " var stream = new antlr4.CommonTokenStream(lexer);\n"
|
||||
+ "<createParser>"
|
||||
+ " parser.buildParseTrees = true;\n"
|
||||
+ " const printer = function() {\n"
|
||||
+ " this.println = function(s) { console.log(s); }\n"
|
||||
+ " this.print = function(s) { process.stdout.write(s); }\n"
|
||||
+ " return this;\n"
|
||||
+ " };\n"
|
||||
+ " parser.printer = new printer();\n"
|
||||
+ " var tree = parser.<parserStartRuleName>();\n"
|
||||
+ " antlr4.tree.ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n"
|
||||
+ "}\n" + "\n" + "main(process.argv);\n" + "\n");
|
||||
ST createParserST = new ST(
|
||||
" var parser = new <parserName>(stream);\n");
|
||||
if (debug) {
|
||||
createParserST = new ST(
|
||||
" var parser = new <parserName>(stream);\n"
|
||||
+ " parser.addErrorListener(new antlr4.error.DiagnosticErrorListener());\n");
|
||||
}
|
||||
outputFileST.add("createParser", createParserST);
|
||||
outputFileST.add("parserName", parserName);
|
||||
outputFileST.add("lexerName", lexerName);
|
||||
outputFileST.add("listenerName", listenerName);
|
||||
outputFileST.add("visitorName", visitorName);
|
||||
outputFileST.add("parserStartRuleName", parserStartRuleName);
|
||||
writeFile(tmpdir, "Test.js", outputFileST.render());
|
||||
}
|
||||
|
||||
protected void writeLexerTestFile(String lexerName, boolean showDFA) {
|
||||
ST outputFileST = new ST(
|
||||
"import antlr4 from 'antlr4';\n"
|
||||
+ "import <lexerName> from './<lexerName>.js';\n"
|
||||
+ "\n"
|
||||
+ "function main(argv) {\n"
|
||||
+ " var input = new antlr4.FileStream(argv[2], true);\n"
|
||||
+ " var lexer = new <lexerName>(input);\n"
|
||||
+ " var stream = new antlr4.CommonTokenStream(lexer);\n"
|
||||
+ " stream.fill();\n"
|
||||
+ " for(var i=0; i\\<stream.tokens.length; i++) {\n"
|
||||
+ " console.log(stream.tokens[i].toString());\n"
|
||||
+ " }\n"
|
||||
+ (showDFA ? " process.stdout.write(lexer._interp.decisionToDFA[antlr4.Lexer.DEFAULT_MODE].toLexerString());\n"
|
||||
: "") + "}\n" + "\n" + "main(process.argv);\n"
|
||||
+ "\n");
|
||||
outputFileST.add("lexerName", lexerName);
|
||||
writeFile(tmpdir, "Test.js", outputFileST.render());
|
||||
}
|
||||
|
||||
protected void eraseFiles(File dir) {
|
||||
String[] files = dir.list();
|
||||
for (int i = 0; files != null && i < files.length; i++) {
|
||||
new File(dir, files[i]).delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseTempDir() {
|
||||
boolean doErase = true;
|
||||
String propName = "antlr-javascript-erase-test-dir";
|
||||
String prop = System.getProperty(propName);
|
||||
if (prop != null && prop.length() > 0)
|
||||
doErase = Boolean.getBoolean(prop);
|
||||
if (doErase) {
|
||||
File tmpdirF = new File(tmpdir);
|
||||
if (tmpdirF.exists()) {
|
||||
eraseFiles(tmpdirF);
|
||||
tmpdirF.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Sort a list */
|
||||
public <T extends Comparable<? super T>> List<T> sort(List<T> data) {
|
||||
List<T> dup = new ArrayList<T>(data);
|
||||
Collections.sort(dup);
|
||||
return dup;
|
||||
}
|
||||
|
||||
/** Return map sorted by key */
|
||||
public <K extends Comparable<? super K>, V> LinkedHashMap<K, V> sort(
|
||||
Map<K, V> data) {
|
||||
LinkedHashMap<K, V> dup = new LinkedHashMap<K, V>();
|
||||
List<K> keys = new ArrayList<K>(data.keySet());
|
||||
Collections.sort(keys);
|
||||
for (K k : keys) {
|
||||
dup.put(k, data.get(k));
|
||||
}
|
||||
return dup;
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -1,967 +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.javascript.browser;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.automata.ATNFactory;
|
||||
import org.antlr.v4.automata.ATNPrinter;
|
||||
import org.antlr.v4.automata.LexerATNFactory;
|
||||
import org.antlr.v4.automata.ParserATNFactory;
|
||||
import org.antlr.v4.codegen.CodeGenerator;
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.IntStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.RuleContext;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenSource;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.WritableToken;
|
||||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNDeserializer;
|
||||
import org.antlr.v4.runtime.atn.ATNSerializer;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.IntegerList;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
import org.antlr.v4.semantics.SemanticPipeline;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.tool.ANTLRMessage;
|
||||
import org.antlr.v4.tool.DOTGenerator;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.GrammarSemanticsMessage;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.openqa.selenium.By.ById;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupString;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.BindException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
||||
// -J-Dorg.antlr.v4.test.BaseTest.level=FINE
|
||||
// private static final Logger LOGGER = Logger.getLogger(BaseTest.class.getName());
|
||||
|
||||
public static final String newline = System.getProperty("line.separator");
|
||||
public static final String pathSep = System.getProperty("path.separator");
|
||||
|
||||
public String httpdir = null;
|
||||
public String tmpdir = null;
|
||||
|
||||
/** If error during parser execution, store stderr here; can't return
|
||||
* stdout and stderr. This doesn't trap errors from running antlr.
|
||||
*/
|
||||
protected String stderrDuringParse;
|
||||
|
||||
/** Errors found while running antlr */
|
||||
protected StringBuilder antlrToolErrors;
|
||||
|
||||
@org.junit.Rule
|
||||
public final TestRule testWatcher = new TestWatcher() {
|
||||
|
||||
@Override
|
||||
protected void succeeded(Description description) {
|
||||
// remove tmpdir if no error.
|
||||
eraseTempDir();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
// new output dir for each test
|
||||
String prop = System.getProperty("antlr-javascript-test-dir");
|
||||
if(prop!=null && prop.length()>0) {
|
||||
httpdir = prop;
|
||||
}
|
||||
else {
|
||||
httpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()+"-"+Thread.currentThread().getName()+"-"+System.currentTimeMillis()).getAbsolutePath();
|
||||
}
|
||||
File dir = new File(httpdir);
|
||||
if(dir.exists())
|
||||
this.eraseFiles(dir);
|
||||
tmpdir = new File(httpdir, "parser").getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpDir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStdout() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParseErrors() {
|
||||
return stderrDuringParse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getANTLRToolErrors() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected org.antlr.v4.Tool newTool(String[] args) {
|
||||
Tool tool = new Tool(args);
|
||||
return tool;
|
||||
}
|
||||
|
||||
protected Tool newTool() {
|
||||
org.antlr.v4.Tool tool = new Tool(new String[] {"-o", tmpdir});
|
||||
return tool;
|
||||
}
|
||||
|
||||
protected ATN createATN(Grammar g, boolean useSerializer) {
|
||||
if ( g.atn==null ) {
|
||||
semanticProcess(g);
|
||||
assertEquals(0, g.tool.getNumErrors());
|
||||
|
||||
ParserATNFactory f;
|
||||
if ( g.isLexer() ) {
|
||||
f = new LexerATNFactory((LexerGrammar)g);
|
||||
}
|
||||
else {
|
||||
f = new ParserATNFactory(g);
|
||||
}
|
||||
|
||||
g.atn = f.createATN();
|
||||
assertEquals(0, g.tool.getNumErrors());
|
||||
}
|
||||
|
||||
ATN atn = g.atn;
|
||||
if (useSerializer) {
|
||||
char[] serialized = ATNSerializer.getSerializedAsChars(atn);
|
||||
return new ATNDeserializer().deserialize(serialized);
|
||||
}
|
||||
|
||||
return atn;
|
||||
}
|
||||
|
||||
protected void semanticProcess(Grammar g) {
|
||||
if ( g.ast!=null && !g.ast.hasErrors ) {
|
||||
System.out.println(g.ast.toStringTree());
|
||||
Tool antlr = new Tool();
|
||||
SemanticPipeline sem = new SemanticPipeline(g);
|
||||
sem.process();
|
||||
if ( g.getImportedGrammars()!=null ) { // process imported grammars (if any)
|
||||
for (Grammar imp : g.getImportedGrammars()) {
|
||||
antlr.processNonCombinedGrammar(imp, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IntegerList getTypesFromString(Grammar g, String expecting) {
|
||||
IntegerList expectingTokenTypes = new IntegerList();
|
||||
if ( expecting!=null && !expecting.trim().isEmpty() ) {
|
||||
for (String tname : expecting.replace(" ", "").split(",")) {
|
||||
int ttype = g.getTokenType(tname);
|
||||
expectingTokenTypes.add(ttype);
|
||||
}
|
||||
}
|
||||
return expectingTokenTypes;
|
||||
}
|
||||
|
||||
public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
|
||||
ANTLRInputStream in = new ANTLRInputStream(input);
|
||||
IntegerList tokenTypes = new IntegerList();
|
||||
int ttype;
|
||||
do {
|
||||
ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
|
||||
tokenTypes.add(ttype);
|
||||
} while ( ttype!= Token.EOF );
|
||||
return tokenTypes;
|
||||
}
|
||||
|
||||
public List<String> getTokenTypes(LexerGrammar lg,
|
||||
ATN atn,
|
||||
CharStream input)
|
||||
{
|
||||
LexerATNSimulator interp = new LexerATNSimulator(atn,new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) },null);
|
||||
List<String> tokenTypes = new ArrayList<String>();
|
||||
int ttype;
|
||||
boolean hitEOF = false;
|
||||
do {
|
||||
if ( hitEOF ) {
|
||||
tokenTypes.add("EOF");
|
||||
break;
|
||||
}
|
||||
int t = input.LA(1);
|
||||
ttype = interp.match(input, Lexer.DEFAULT_MODE);
|
||||
if ( ttype == Token.EOF ) {
|
||||
tokenTypes.add("EOF");
|
||||
}
|
||||
else {
|
||||
tokenTypes.add(lg.typeToTokenList.get(ttype));
|
||||
}
|
||||
|
||||
if ( t==IntStream.EOF ) {
|
||||
hitEOF = true;
|
||||
}
|
||||
} while ( ttype!=Token.EOF );
|
||||
return tokenTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execLexer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String lexerName,
|
||||
String input, boolean showDFA)
|
||||
{
|
||||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr,
|
||||
null,
|
||||
lexerName,"-no-listener");
|
||||
assertTrue(success);
|
||||
writeLexerTestFile(lexerName, showDFA);
|
||||
String output = null;
|
||||
try {
|
||||
output = execHtmlPage("Test.html", input);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execParser(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
String listenerName,
|
||||
String visitorName,
|
||||
String startRuleName,
|
||||
String input,
|
||||
boolean showDiagnosticErrors)
|
||||
{
|
||||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr,
|
||||
parserName,
|
||||
lexerName,
|
||||
"-visitor");
|
||||
assertTrue(success);
|
||||
rawBuildRecognizerTestFile(parserName,
|
||||
lexerName,
|
||||
listenerName,
|
||||
visitorName,
|
||||
startRuleName,
|
||||
showDiagnosticErrors);
|
||||
String result = null;
|
||||
try {
|
||||
result = execRecognizer(input);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testTearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
/** Return true if all is well */
|
||||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
String... extraOptions)
|
||||
{
|
||||
return rawGenerateAndBuildRecognizer(grammarFileName, grammarStr, parserName, lexerName, false, extraOptions);
|
||||
}
|
||||
|
||||
/** Return true if all is well */
|
||||
protected boolean rawGenerateAndBuildRecognizer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
boolean defaultListener,
|
||||
String... extraOptions)
|
||||
{
|
||||
ErrorQueue equeue =
|
||||
antlrOnString(getTmpDir(), "JavaScript", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> files = new ArrayList<String>();
|
||||
if ( lexerName!=null ) {
|
||||
files.add(lexerName+".js");
|
||||
}
|
||||
if ( parserName!=null ) {
|
||||
files.add(parserName+".js");
|
||||
Set<String> optionsSet = new HashSet<String>(Arrays.asList(extraOptions));
|
||||
if (!optionsSet.contains("-no-listener")) {
|
||||
files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.'))+"Listener.js");
|
||||
}
|
||||
if (optionsSet.contains("-visitor")) {
|
||||
files.add(grammarFileName.substring(0, grammarFileName.lastIndexOf('.'))+"Visitor.js");
|
||||
}
|
||||
}
|
||||
return true; // allIsWell: no compile
|
||||
}
|
||||
|
||||
protected void rawBuildRecognizerTestFile(String parserName,
|
||||
String lexerName,
|
||||
String listenerName,
|
||||
String visitorName,
|
||||
String parserStartRuleName, boolean debug)
|
||||
{
|
||||
this.stderrDuringParse = null;
|
||||
if ( parserName==null ) {
|
||||
writeLexerTestFile(lexerName, false);
|
||||
}
|
||||
else {
|
||||
writeParserTestFile(parserName,
|
||||
lexerName,
|
||||
listenerName,
|
||||
visitorName,
|
||||
parserStartRuleName,
|
||||
debug);
|
||||
}
|
||||
}
|
||||
|
||||
public String execRecognizer(String input) throws Exception {
|
||||
return execHtmlPage("Test.html", input);
|
||||
}
|
||||
|
||||
static int httpPort = 8080;
|
||||
|
||||
class ServerThread extends Thread {
|
||||
|
||||
Server server;
|
||||
String runtimePath;
|
||||
String fileName;
|
||||
Exception ex;
|
||||
|
||||
public ServerThread(String fileName) {
|
||||
this.runtimePath = locateRuntime();
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Server server = new Server(httpPort);
|
||||
ResourceHandler rh1 = new ResourceHandler();
|
||||
rh1.setDirectoriesListed(false);
|
||||
rh1.setResourceBase(httpdir);
|
||||
rh1.setWelcomeFiles(new String[] { fileName });
|
||||
ResourceHandler rh2 = new ResourceHandler();
|
||||
rh2.setDirectoriesListed(false);
|
||||
rh2.setResourceBase(runtimePath);
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { rh1, rh2, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
server.start();
|
||||
this.server = server;
|
||||
this.server.join();
|
||||
} catch(BindException e) {
|
||||
httpPort++;
|
||||
run();
|
||||
} catch (Exception e) {
|
||||
ex = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static WebDriver driver;
|
||||
|
||||
public String execHtmlPage(String fileName, String input) throws Exception {
|
||||
// 'file' protocol is not supported by Selenium drivers
|
||||
// so we run an embedded Jetty server
|
||||
ServerThread thread = new ServerThread(fileName);
|
||||
thread.start();
|
||||
try {
|
||||
while(thread.server==null && thread.ex==null)
|
||||
Thread.sleep(10);
|
||||
if(thread.ex!=null)
|
||||
throw thread.ex;
|
||||
while(thread.server.isStarting())
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(400); // despite all the above precautions, driver.get often fails if you don't give time to Jetty
|
||||
driver.get("http://localhost:" + httpPort + "/" + fileName);
|
||||
driver.findElement(new ById("input")).clear();
|
||||
driver.findElement(new ById("output")).clear();
|
||||
driver.findElement(new ById("errors")).clear();
|
||||
driver.navigate().refresh();
|
||||
driver.findElement(new ById("input")).sendKeys(input);
|
||||
driver.findElement(new ById("load")).click();
|
||||
driver.findElement(new ById("submit")).click();
|
||||
String errors = driver.findElement(new ById("errors")).getAttribute("value");
|
||||
if(errors!=null && errors.length()>0) {
|
||||
this.stderrDuringParse = errors;
|
||||
System.err.print(errors);
|
||||
}
|
||||
String value = driver.findElement(new ById("output")).getAttribute("value");
|
||||
// mimic stdout which adds a NL
|
||||
if(value.length()>0 && !value.endsWith("\n"))
|
||||
value = value + "\n";
|
||||
return value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("can't exec recognizer");
|
||||
e.printStackTrace(System.err);
|
||||
} finally {
|
||||
if(thread.server!=null) {
|
||||
thread.server.stop();
|
||||
while(!thread.server.isStopped())
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(100); // ensure the port is freed
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String locateRuntime() {
|
||||
String propName = "antlr-javascript-runtime";
|
||||
String prop = System.getProperty(propName);
|
||||
if(prop==null || prop.length()==0)
|
||||
prop = "../runtime/JavaScript/src";
|
||||
File file = new File(prop);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
if(!file.exists())
|
||||
throw new RuntimeException("Missing system property:" + propName);
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class<? extends ANTLRMessage> c) {
|
||||
List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
|
||||
for (ANTLRMessage m : msgs) {
|
||||
if ( m.getClass() == c ) filtered.add(m);
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
void checkRuleATN(Grammar g, String ruleName, String expecting) {
|
||||
ParserATNFactory f = new ParserATNFactory(g);
|
||||
ATN atn = f.createATN();
|
||||
|
||||
DOTGenerator dot = new DOTGenerator(g);
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));
|
||||
|
||||
Rule r = g.getRule(ruleName);
|
||||
ATNState startState = atn.ruleToStartState[r.index];
|
||||
ATNPrinter serializer = new ATNPrinter(g, startState);
|
||||
String result = serializer.asString();
|
||||
|
||||
//System.out.print(result);
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
||||
public void testActions(String templates, String actionName, String action, String expected) throws org.antlr.runtime.RecognitionException {
|
||||
int lp = templates.indexOf('(');
|
||||
String name = templates.substring(0, lp);
|
||||
STGroup group = new STGroupString(templates);
|
||||
ST st = group.getInstanceOf(name);
|
||||
st.add(actionName, action);
|
||||
String grammar = st.render();
|
||||
ErrorQueue equeue = new ErrorQueue();
|
||||
Grammar g = new Grammar(grammar, equeue);
|
||||
if ( g.ast!=null && !g.ast.hasErrors ) {
|
||||
SemanticPipeline sem = new SemanticPipeline(g);
|
||||
sem.process();
|
||||
|
||||
ATNFactory factory = new ParserATNFactory(g);
|
||||
if ( g.isLexer() ) factory = new LexerATNFactory((LexerGrammar)g);
|
||||
g.atn = factory.createATN();
|
||||
|
||||
CodeGenerator gen = new CodeGenerator(g);
|
||||
ST outputFileST = gen.generateParser();
|
||||
String output = outputFileST.render();
|
||||
//System.out.println(output);
|
||||
String b = "#" + actionName + "#";
|
||||
int start = output.indexOf(b);
|
||||
String e = "#end-" + actionName + "#";
|
||||
int end = output.indexOf(e);
|
||||
String snippet = output.substring(start+b.length(),end);
|
||||
assertEquals(expected, snippet);
|
||||
}
|
||||
if ( equeue.size()>0 ) {
|
||||
System.err.println(equeue.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkGrammarSemanticsError(ErrorQueue equeue,
|
||||
GrammarSemanticsMessage expectedMessage)
|
||||
throws Exception
|
||||
{
|
||||
ANTLRMessage foundMsg = null;
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage m = equeue.errors.get(i);
|
||||
if (m.getErrorType()==expectedMessage.getErrorType() ) {
|
||||
foundMsg = m;
|
||||
}
|
||||
}
|
||||
assertNotNull("no error; "+expectedMessage.getErrorType()+" expected", foundMsg);
|
||||
assertTrue("error is not a GrammarSemanticsMessage",
|
||||
foundMsg instanceof GrammarSemanticsMessage);
|
||||
assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs()));
|
||||
if ( equeue.size()!=1 ) {
|
||||
System.err.println(equeue);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkGrammarSemanticsWarning(ErrorQueue equeue,
|
||||
GrammarSemanticsMessage expectedMessage)
|
||||
throws Exception
|
||||
{
|
||||
ANTLRMessage foundMsg = null;
|
||||
for (int i = 0; i < equeue.warnings.size(); i++) {
|
||||
ANTLRMessage m = equeue.warnings.get(i);
|
||||
if (m.getErrorType()==expectedMessage.getErrorType() ) {
|
||||
foundMsg = m;
|
||||
}
|
||||
}
|
||||
assertNotNull("no error; "+expectedMessage.getErrorType()+" expected", foundMsg);
|
||||
assertTrue("error is not a GrammarSemanticsMessage",
|
||||
foundMsg instanceof GrammarSemanticsMessage);
|
||||
assertEquals(Arrays.toString(expectedMessage.getArgs()), Arrays.toString(foundMsg.getArgs()));
|
||||
if ( equeue.size()!=1 ) {
|
||||
System.err.println(equeue);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkError(ErrorQueue equeue,
|
||||
ANTLRMessage expectedMessage)
|
||||
throws Exception
|
||||
{
|
||||
//System.out.println("errors="+equeue);
|
||||
ANTLRMessage foundMsg = null;
|
||||
for (int i = 0; i < equeue.errors.size(); i++) {
|
||||
ANTLRMessage m = equeue.errors.get(i);
|
||||
if (m.getErrorType()==expectedMessage.getErrorType() ) {
|
||||
foundMsg = m;
|
||||
}
|
||||
}
|
||||
assertTrue("no error; "+expectedMessage.getErrorType()+" expected", !equeue.errors.isEmpty());
|
||||
assertTrue("too many errors; "+equeue.errors, equeue.errors.size()<=1);
|
||||
assertNotNull("couldn't find expected error: "+expectedMessage.getErrorType(), foundMsg);
|
||||
/*
|
||||
assertTrue("error is not a GrammarSemanticsMessage",
|
||||
foundMsg instanceof GrammarSemanticsMessage);
|
||||
*/
|
||||
assertArrayEquals(expectedMessage.getArgs(), foundMsg.getArgs());
|
||||
}
|
||||
|
||||
public static class FilteringTokenStream extends CommonTokenStream {
|
||||
public FilteringTokenStream(TokenSource src) { super(src); }
|
||||
Set<Integer> hide = new HashSet<Integer>();
|
||||
@Override
|
||||
protected boolean sync(int i) {
|
||||
if (!super.sync(i)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Token t = get(i);
|
||||
if ( hide.contains(t.getType()) ) {
|
||||
((WritableToken)t).setChannel(Token.HIDDEN_CHANNEL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public void setTokenTypeChannel(int ttype, int channel) {
|
||||
hide.add(ttype);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
protected void writeParserTestFile(String parserName,
|
||||
String lexerName,
|
||||
String listenerName,
|
||||
String visitorName,
|
||||
String parserStartRuleName, boolean debug) {
|
||||
String html = "<!DOCTYPE html>\r\n" +
|
||||
"<html>\r\n" +
|
||||
" <head>\r\n" +
|
||||
" <script src='lib/require.js'></script>\r\n" +
|
||||
" <script>\r\n" +
|
||||
" antlr4 = null;\r\n" +
|
||||
" listener = null;\r\n" +
|
||||
" TreeShapeListener = null;\r\n" +
|
||||
" " + lexerName + " = null;\r\n" +
|
||||
" " + parserName + " = null;\r\n" +
|
||||
" " + listenerName + " = null;\r\n" +
|
||||
" " + visitorName + " = null;\r\n" +
|
||||
" printer = function() {\r\n" +
|
||||
" this.println = function(s) { document.getElementById('output').value += s + '\\n'; }\r\n" +
|
||||
" this.print = function(s) { document.getElementById('output').value += s; }\r\n" +
|
||||
" return this;\r\n" +
|
||||
" };\r\n" +
|
||||
"\r\n" +
|
||||
" loadParser = function() {\r\n" +
|
||||
" try {\r\n" +
|
||||
" antlr4 = require('antlr4/index');\r\n" +
|
||||
" " + lexerName + " = require('./parser/" + lexerName + "');\n" +
|
||||
" " + parserName + " = require('./parser/" + parserName + "');\n" +
|
||||
" " + listenerName + " = require('./parser/" + listenerName + "');\n" +
|
||||
" " + visitorName + " = require('./parser/" + visitorName + "');\n" +
|
||||
" } catch (ex) {\r\n" +
|
||||
" document.getElementById('errors').value = ex.toString();\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" listener = function() {\r\n" +
|
||||
" antlr4.error.ErrorListener.call(this);\r\n" +
|
||||
" return this;\r\n" +
|
||||
" }\r\n" +
|
||||
" listener.prototype = Object.create(antlr4.error.ErrorListener.prototype);\r\n" +
|
||||
" listener.prototype.constructor = listener;\r\n" +
|
||||
" listener.prototype.syntaxError = function(recognizer, offendingSymbol, line, column, msg, e) {\r\n" +
|
||||
" document.getElementById('errors').value += 'line ' + line + ':' + column + ' ' + msg + '\\r\\n';\r\n" +
|
||||
" };\r\n" +
|
||||
"\r\n" +
|
||||
" TreeShapeListener = function() {\r\n" +
|
||||
" antlr4.tree.ParseTreeListener.call(this);\r\n" +
|
||||
" return this;\r\n" +
|
||||
" };\r\n" +
|
||||
"\r\n" +
|
||||
" TreeShapeListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype);\r\n" +
|
||||
" TreeShapeListener.prototype.constructor = TreeShapeListener;\r\n" +
|
||||
"\r\n" +
|
||||
" TreeShapeListener.prototype.enterEveryRule = function(ctx) {\r\n" +
|
||||
" for(var i=0;i<ctx.getChildCount; i++) {\r\n" +
|
||||
" var child = ctx.getChild(i);\r\n" +
|
||||
" var parent = child.parentCtx;\r\n" +
|
||||
" if(parent.getRuleContext() !== ctx || !(parent instanceof antlr4.tree.RuleNode)) {\r\n" +
|
||||
" throw 'Invalid parse tree shape detected.';\r\n" +
|
||||
" }\r\n" +
|
||||
" }\r\n" +
|
||||
" };\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" test = function() {\r\n" +
|
||||
" document.getElementById('output').value = ''\r\n" +
|
||||
" var input = document.getElementById('input').value;\r\n" +
|
||||
" var stream = antlr4.CharStreams.fromString(input);\n" +
|
||||
" var lexer = new " + lexerName + "." + lexerName + "(stream);\n" +
|
||||
" lexer._listeners = [new listener()];\r\n" +
|
||||
" var tokens = new antlr4.CommonTokenStream(lexer);\n" +
|
||||
" var parser = new " + parserName + "." + parserName + "(tokens);\n" +
|
||||
" parser._listeners.push(new listener());\n" +
|
||||
(debug ?
|
||||
" parser._listeners.push(new antlr4.error.DiagnosticErrorListener());\n" : "") +
|
||||
" parser.buildParseTrees = true;\n" +
|
||||
" parser.printer = new printer();\n" +
|
||||
" var tree = parser." + parserStartRuleName + "();\n" +
|
||||
" antlr4.tree.ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n" +
|
||||
" };\r\n" +
|
||||
"\r\n" +
|
||||
" </script>\r\n" +
|
||||
" </head>\r\n" +
|
||||
" <body>\r\n" +
|
||||
" <textarea id='input'></textarea><br>\r\n" +
|
||||
" <button id='load' type='button' onclick='loadParser()'>Load</button><br>\r\n" +
|
||||
" <button id='submit' type='button' onclick='test()'>Test</button><br>\r\n" +
|
||||
" <textarea id='output'></textarea><br>\r\n" +
|
||||
" <textarea id='errors'></textarea><br>\r\n" +
|
||||
" </body>\r\n" +
|
||||
"</html>\r\n";
|
||||
writeFile(httpdir, "Test.html", html);
|
||||
};
|
||||
|
||||
|
||||
protected void writeLexerTestFile(String lexerName, boolean showDFA) {
|
||||
String html = "<!DOCTYPE html>\r\n" +
|
||||
"<html>\r\n" +
|
||||
" <head>\r\n" +
|
||||
" <script src='lib/require.js'></script>\r\n" +
|
||||
" <script>\r\n" +
|
||||
" antlr4 = null;\r\n" +
|
||||
" listener = null;\r\n" +
|
||||
" " + lexerName + " = null;\r\n" +
|
||||
"\r\n" +
|
||||
" loadLexer = function() {\r\n" +
|
||||
" try {\r\n" +
|
||||
" antlr4 = require('antlr4/index');\r\n" +
|
||||
" " + lexerName + " = require('./parser/" + lexerName + "');\r\n" +
|
||||
" } catch (ex) {\r\n" +
|
||||
" document.getElementById('errors').value = ex.toString();\r\n" +
|
||||
" }\r\n" +
|
||||
" listener = function() {\r\n" +
|
||||
" antlr4.error.ErrorListener.call(this);\r\n" +
|
||||
" return this;\r\n" +
|
||||
" }\r\n" +
|
||||
" listener.prototype = Object.create(antlr4.error.ErrorListener.prototype);\r\n" +
|
||||
" listener.prototype.constructor = listener;\r\n" +
|
||||
" listener.prototype.syntaxError = function(recognizer, offendingSymbol, line, column, msg, e) {\r\n" +
|
||||
" document.getElementById('errors').value += 'line ' + line + ':' + column + ' ' + msg + '\\r\\n';\r\n" +
|
||||
" };\r\n" +
|
||||
" }\r\n" +
|
||||
"\r\n" +
|
||||
" test = function() {\r\n" +
|
||||
" document.getElementById('output').value = ''\r\n" +
|
||||
" var input = document.getElementById('input').value;\r\n" +
|
||||
" var chars = antlr4.CharStreams.fromString(input);\r\n" +
|
||||
" var lexer = new " + lexerName + "." + lexerName + "(chars);\r\n" +
|
||||
" lexer._listeners = [new listener()];\r\n" +
|
||||
" var stream = new antlr4.CommonTokenStream(lexer);\r\n" +
|
||||
" stream.fill();\r\n" +
|
||||
" for(var i=0; i<stream.tokens.length; i++) {\r\n" +
|
||||
" document.getElementById('output').value += stream.tokens[i].toString() + '\\r\\n';\r\n" +
|
||||
" }\n" +
|
||||
(showDFA ?
|
||||
" document.getElementById('output').value += lexer._interp.decisionToDFA[antlr4.Lexer.DEFAULT_MODE].toLexerString();\r\n"
|
||||
:"") +
|
||||
" };\r\n" +
|
||||
"\r\n" +
|
||||
" </script>\r\n" +
|
||||
" </head>\r\n" +
|
||||
" <body>\r\n" +
|
||||
" <textarea id='input'></textarea><br>\r\n" +
|
||||
" <button id='load' type='button' onclick='loadLexer()'>Load</button><br>\r\n" +
|
||||
" <button id='submit' type='button' onclick='test()'>Test</button><br>\r\n" +
|
||||
" <textarea id='output'></textarea><br>\r\n" +
|
||||
" <textarea id='errors'></textarea><br>\r\n" +
|
||||
" </body>\r\n" +
|
||||
"</html>\r\n";
|
||||
writeFile(httpdir, "Test.html", html);
|
||||
}
|
||||
|
||||
public void writeRecognizer(String parserName, String lexerName,
|
||||
String listenerName, String visitorName,
|
||||
String parserStartRuleName, boolean debug) {
|
||||
if ( parserName==null )
|
||||
writeLexerTestFile(lexerName, debug);
|
||||
else
|
||||
writeParserTestFile(parserName,
|
||||
lexerName,
|
||||
listenerName,
|
||||
visitorName,
|
||||
parserStartRuleName,
|
||||
debug);
|
||||
}
|
||||
|
||||
|
||||
protected void eraseFiles(final String filesEndingWith) {
|
||||
File tmpdirF = new File(httpdir);
|
||||
String[] files = tmpdirF.list();
|
||||
for(int i = 0; files!=null && i < files.length; i++) {
|
||||
if ( files[i].endsWith(filesEndingWith) ) {
|
||||
new File(httpdir+"/"+files[i]).delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void eraseFiles(File dir) {
|
||||
String[] files = dir.list();
|
||||
for(int i = 0; files!=null && i < files.length; i++) {
|
||||
new File(dir,files[i]).delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseTempDir() {
|
||||
boolean doErase = true;
|
||||
String propName = "antlr-javascript-erase-test-dir";
|
||||
String prop = System.getProperty(propName);
|
||||
if(prop!=null && prop.length()>0)
|
||||
doErase = Boolean.getBoolean(prop);
|
||||
if(doErase) {
|
||||
File tmpdirF = new File(httpdir);
|
||||
if ( tmpdirF.exists() ) {
|
||||
eraseFiles(tmpdirF);
|
||||
tmpdirF.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFirstLineOfException() {
|
||||
if ( this.stderrDuringParse ==null ) {
|
||||
return null;
|
||||
}
|
||||
String[] lines = this.stderrDuringParse.split("\n");
|
||||
String prefix="Exception in thread \"main\" ";
|
||||
return lines[0].substring(prefix.length(),lines[0].length());
|
||||
}
|
||||
|
||||
/**
|
||||
* When looking at a result set that consists of a Map/HashTable
|
||||
* we cannot rely on the output order, as the hashing algorithm or other aspects
|
||||
* of the implementation may be different on differnt JDKs or platforms. Hence
|
||||
* we take the Map, convert the keys to a List, sort them and Stringify the Map, which is a
|
||||
* bit of a hack, but guarantees that we get the same order on all systems. We assume that
|
||||
* the keys are strings.
|
||||
*
|
||||
* @param m The Map that contains keys we wish to return in sorted order
|
||||
* @return A string that represents all the keys in sorted order.
|
||||
*/
|
||||
public <K, V> String sortMapToString(Map<K, V> m) {
|
||||
// Pass in crap, and get nothing back
|
||||
//
|
||||
if (m == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("Map toString looks like: " + m.toString());
|
||||
|
||||
// Sort the keys in the Map
|
||||
//
|
||||
TreeMap<K, V> nset = new TreeMap<K, V>(m);
|
||||
|
||||
System.out.println("Tree map looks like: " + nset.toString());
|
||||
return nset.toString();
|
||||
}
|
||||
|
||||
public List<String> realElements(List<String> elements) {
|
||||
return elements.subList(Token.MIN_USER_TOKEN_TYPE, elements.size());
|
||||
}
|
||||
|
||||
public void assertNotNullOrEmpty(String message, String text) {
|
||||
assertNotNull(message, text);
|
||||
assertFalse(message, text.isEmpty());
|
||||
}
|
||||
|
||||
public void assertNotNullOrEmpty(String text) {
|
||||
assertNotNull(text);
|
||||
assertFalse(text.isEmpty());
|
||||
}
|
||||
|
||||
public static class IntTokenStream implements TokenStream {
|
||||
IntegerList types;
|
||||
int p=0;
|
||||
public IntTokenStream(IntegerList types) { this.types = types; }
|
||||
|
||||
@Override
|
||||
public void consume() { p++; }
|
||||
|
||||
@Override
|
||||
public int LA(int i) { return LT(i).getType(); }
|
||||
|
||||
@Override
|
||||
public int mark() {
|
||||
return index();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int index() { return p; }
|
||||
|
||||
@Override
|
||||
public void release(int marker) {
|
||||
seek(marker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(int index) {
|
||||
p = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return types.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token LT(int i) {
|
||||
CommonToken t;
|
||||
int rawIndex = p + i - 1;
|
||||
if ( rawIndex>=types.size() ) t = new CommonToken(Token.EOF);
|
||||
else t = new CommonToken(types.get(rawIndex));
|
||||
t.setTokenIndex(rawIndex);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token get(int i) {
|
||||
return new org.antlr.v4.runtime.CommonToken(types.get(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenSource getTokenSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
throw new UnsupportedOperationException("can't give strings");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText(Interval interval) {
|
||||
throw new UnsupportedOperationException("can't give strings");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText(RuleContext ctx) {
|
||||
throw new UnsupportedOperationException("can't give strings");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText(Token start, Token stop) {
|
||||
throw new UnsupportedOperationException("can't give strings");
|
||||
}
|
||||
}
|
||||
|
||||
/** Sort a list */
|
||||
public <T extends Comparable<? super T>> List<T> sort(List<T> data) {
|
||||
List<T> dup = new ArrayList<T>();
|
||||
dup.addAll(data);
|
||||
Collections.sort(dup);
|
||||
return dup;
|
||||
}
|
||||
|
||||
/** Return map sorted by key */
|
||||
public <K extends Comparable<? super K>,V> LinkedHashMap<K,V> sort(Map<K,V> data) {
|
||||
LinkedHashMap<K,V> dup = new LinkedHashMap<K, V>();
|
||||
List<K> keys = new ArrayList<K>();
|
||||
keys.addAll(data.keySet());
|
||||
Collections.sort(keys);
|
||||
for (K k : keys) {
|
||||
dup.put(k, data.get(k));
|
||||
}
|
||||
return dup;
|
||||
}
|
||||
}
|
|
@ -1,23 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.javascript.browser.BaseBrowserTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class BaseChromeTest extends BaseBrowserTest {
|
||||
@BeforeClass
|
||||
public static void initWebDriver() {
|
||||
driver = SharedWebDriver.init();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeWebDriver() {
|
||||
SharedWebDriver.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +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.javascript.chrome;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SharedWebDriver {
|
||||
|
||||
static WebDriver driver;
|
||||
static Timer timer;
|
||||
|
||||
public static WebDriver init() {
|
||||
if(driver==null) {
|
||||
String path = SharedWebDriver.class.getPackage().getName().replace(".", "/") + "/chromedriver.bin";
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(path);
|
||||
File file = new File(url.toExternalForm().substring(5)); // skip 'file:'
|
||||
assertTrue(file.exists());
|
||||
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
|
||||
driver = new ChromeDriver();
|
||||
} else if(timer!=null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
if(driver!=null) {
|
||||
if(timer!=null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override public void run() {
|
||||
driver.quit();
|
||||
driver = null;
|
||||
}
|
||||
}, 2000); // close with delay to allow next Test to start
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeLexersDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(CompositeLexersDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.FullContextParsingDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(FullContextParsingDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.LeftRecursionDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(LeftRecursionDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ListenersDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ListenersDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(ParserExecDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(PerformanceDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
|
@ -1,25 +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.javascript.chrome;
|
||||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalLexerDescriptors;
|
||||
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 BaseChromeTest());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return BaseRuntimeTest.getRuntimeTestDescriptors(SemPredEvalLexerDescriptors.class, "Chrome");
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue