forked from jasder/antlr
Merge branch 'master' into interpreter2
This commit is contained in:
commit
aa2d34bdfd
89
.travis.yml
89
.travis.yml
|
@ -10,6 +10,7 @@ matrix:
|
|||
env:
|
||||
- TARGET=cpp
|
||||
- CXX=g++-5
|
||||
- GROUP=ALL
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
@ -22,7 +23,9 @@ matrix:
|
|||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env: TARGET=cpp
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=LEXER
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
@ -35,7 +38,71 @@ matrix:
|
|||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env: TARGET=swift
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=PARSER
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
packages:
|
||||
- g++-5
|
||||
- uuid-dev
|
||||
- clang-3.7
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env:
|
||||
- TARGET=cpp
|
||||
- GROUP=RECURSION
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
packages:
|
||||
- g++-5
|
||||
- uuid-dev
|
||||
- clang-3.7
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=LEXER
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=PARSER
|
||||
- os: osx
|
||||
compiler: clang
|
||||
osx_image: xcode8.1
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=RECURSION
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- TARGET=swift
|
||||
- GROUP=ALL
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=LEXER
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=PARSER
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=RECURSION
|
||||
- os: linux
|
||||
jdk: oraclejdk7
|
||||
env: TARGET=java
|
||||
|
@ -46,9 +113,23 @@ matrix:
|
|||
jdk: oraclejdk7
|
||||
env: TARGET=csharp
|
||||
- os: linux
|
||||
jdk: oraclejdk7
|
||||
jdk: oraclejdk8
|
||||
dist: trusty
|
||||
env: TARGET=dotnet
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=LEXER
|
||||
- os: linux
|
||||
jdk: oraclejdk8
|
||||
dist: trusty
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=PARSER
|
||||
- os: linux
|
||||
jdk: oraclejdk8
|
||||
dist: trusty
|
||||
env:
|
||||
- TARGET=dotnet
|
||||
- GROUP=RECURSION
|
||||
- os: linux
|
||||
jdk: oraclejdk7
|
||||
env: TARGET=python2
|
||||
|
|
|
@ -6,17 +6,5 @@ set -euo pipefail
|
|||
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
|
||||
sudo apt-get update
|
||||
|
||||
sudo apt-get install dotnet-dev-1.0.0-preview2.1-003177
|
||||
|
||||
# install mvn
|
||||
wget http://apache.mirrors.lucidnetworks.net/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz && \
|
||||
wget https://www.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz.md5 && \
|
||||
echo "$(cat apache-maven-3.3.9-bin.tar.gz.md5) apache-maven-3.3.9-bin.tar.gz" > apache-maven-3.3.9-bin.tar.gz.md5 && \
|
||||
md5sum -c *.md5
|
||||
|
||||
sudo rm -rf /usr/local/maven/ && sudo mkdir -p /usr/local/maven && \
|
||||
sudo tar xzvf apache-maven-3.3.9-bin.tar.gz -C /usr/local/maven --strip-components=1
|
||||
|
||||
mvn -v
|
||||
sudo apt-get install dotnet-dev-1.0.4
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
set -euo pipefail
|
||||
|
||||
# make sure we use trusty repositories (travis by default uses precise)
|
||||
curl https://repogen.simplylinux.ch/txt/trusty/sources_c4aa56bd26c0f54f391d8fae3e687ef5f6e97c26.txt | sudo tee /etc/apt/sources.list
|
||||
|
||||
# install dependencies
|
||||
# some packages below will be update, swift assumes newer versions
|
||||
# of, for example, sqlite3 and libicu, without the update some
|
||||
# tools will not work
|
||||
sudo apt-get update
|
||||
sudo apt-get install clang libicu-dev libxml2 sqlite3
|
||||
|
||||
# This would fix a know linker issue mentioned in:
|
||||
# https://bugs.swift.org/browse/SR-2299
|
||||
sudo ln -sf ld.gold /usr/bin/ld
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
thisdir=$(dirname "$0")
|
||||
|
||||
# pre-requisites for dotnet core
|
||||
brew update
|
||||
brew install openssl
|
||||
mkdir -p /usr/local/lib
|
||||
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
|
||||
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
|
||||
|
||||
# download dotnet core
|
||||
curl https://download.microsoft.com/download/B/9/F/B9F1AF57-C14A-4670-9973-CDF47209B5BF/dotnet-dev-osx-x64.1.0.4.pkg -o /tmp/dotnet-dev-osx-x64.1.0.4.pkg
|
||||
|
||||
# install dotnet core
|
||||
sudo installer -pkg /tmp/dotnet-dev-osx-x64.1.0.4.pkg -target /
|
||||
|
||||
# make the link
|
||||
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
|
||||
|
||||
# Work around apparent rvm bug that is in Travis's Xcode image.
|
||||
# https://github.com/direnv/direnv/issues/210
|
||||
# https://github.com/travis-ci/travis-ci/issues/6307
|
||||
shell_session_update() { :; }
|
||||
|
|
@ -1,3 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
mvn -q -Dtest=cpp.* test # timeout due to no output for 10 min on travis if in parallel
|
||||
if [ $GROUP == "LEXER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LexerTests" -Dtest=cpp.* test
|
||||
elif [ $GROUP == "PARSER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.ParserTests" -Dtest=cpp.* test
|
||||
elif [ $GROUP == "RECURSION" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LeftRecursionTests" -Dtest=cpp.* test
|
||||
else
|
||||
mvn -q -Dtest=cpp.* test
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
mvn -q -Dparallel=methods -DthreadCount=4 -Dtest=csharp.* -Dantlr-csharp-netstandard=true test
|
||||
# we need to build the runtime before test run, since we used "--no-dependencies"
|
||||
# when we call dotnet cli for restore and build, in order to speed up
|
||||
|
||||
dotnet restore ../runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
dotnet build -c Release ../runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
|
||||
|
||||
# call test
|
||||
|
||||
if [ $GROUP == "LEXER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LexerTests" -Dparallel=classes -DthreadCount=4 -Dtest=csharp.* -Dantlr-csharp-netstandard=true test
|
||||
elif [ $GROUP == "PARSER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.ParserTests" -Dparallel=classes -DthreadCount=4 -Dtest=csharp.* -Dantlr-csharp-netstandard=true test
|
||||
elif [ $GROUP == "RECURSION" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LeftRecursionTests" -Dparallel=classes -DthreadCount=4 -Dtest=csharp.* -Dantlr-csharp-netstandard=true test
|
||||
else
|
||||
mvn -q -Dparallel=classes -DthreadCount=4 -Dtest=csharp.* -Dantlr-csharp-netstandard=true test
|
||||
fi
|
||||
|
|
|
@ -1,4 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
# only test swift as we develop on os x so likely well tested and its dog slow on travis
|
||||
mvn -q -Dtest=swift.* test
|
||||
# linux specific setup, those setup have to be
|
||||
# here since environment variables doesn't pass
|
||||
# across scripts
|
||||
if [ $TRAVIS_OS_NAME == "linux" ]; then
|
||||
export SWIFT_VERSION=swift-3.1.1
|
||||
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu14.04/usr/bin/
|
||||
export PATH=$SWIFT_HOME:$PATH
|
||||
|
||||
# download swift
|
||||
mkdir swift
|
||||
curl https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1404/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu14.04.tar.gz -s | tar xz -C swift &> /dev/null
|
||||
fi
|
||||
|
||||
# check swift
|
||||
swift --version
|
||||
swift build --version
|
||||
|
||||
if [ $GROUP == "LEXER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LexerTests" -Dtest=swift.* test
|
||||
elif [ $GROUP == "PARSER" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.ParserTests" -Dtest=swift.* test
|
||||
elif [ $GROUP == "RECURSION" ]; then
|
||||
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LeftRecursionTests" -Dtest=swift.* test
|
||||
else
|
||||
mvn -q -Dtest=swift.* test
|
||||
fi
|
||||
|
|
|
@ -143,3 +143,11 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2017/03/03, chund, Christian Hund, christian.hund@gmail.com
|
||||
2017/03/15, robertvanderhulst, Robert van der Hulst, robert@xsharp.eu
|
||||
2017/03/28, cmd-johnson, Jonas Auer, jonas.auer.94@gmail.com
|
||||
2017/04/12, lys0716, Yishuang Lu, luyscmu@gmail.com
|
||||
2017/04/30, shravanrn, Shravan Narayan, shravanrn@gmail.com
|
||||
2017/05/11, jimallman, Jim Allman, jim@ibang.com
|
||||
2017/05/26, waf, Will Fuqua, wafuqua@gmail.com
|
||||
2017/05/29, kosak, Corey Kosak, kosak@kosak.com
|
||||
2017/06/11, erikbra, Erik A. Brandstadmoen, erik@brandstadmoen.net
|
||||
2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, janm@transactionware.com
|
||||
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
|
|
@ -49,7 +49,7 @@ using namespace org::antlr::v4::runtime;
|
|||
|
||||
class TreeShapeListener : public MyGrammarBaseListener {
|
||||
public:
|
||||
void enterKey(Ref<ParserRuleContext> ctx) {
|
||||
void enterKey(ParserRuleContext *ctx) override {
|
||||
// Do something when entering the key rule.
|
||||
}
|
||||
};
|
||||
|
@ -63,16 +63,16 @@ int main(int argc, const char* argv[]) {
|
|||
CommonTokenStream tokens(&lexer);
|
||||
MyGrammarParser parser(&tokens);
|
||||
|
||||
Ref<tree::ParseTree> tree = parser.key();
|
||||
Ref<TreeShapeListener> listener(new TreeShapeListener());
|
||||
tree::ParseTreeWalker::DEFAULT->walk(listener, tree);
|
||||
tree::ParseTree *tree = parser.key();
|
||||
TreeShapeListener listener;
|
||||
tree::ParseTreeWalker::DEFAULT->walk(&listener, tree);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
This example assumes your grammar contains a parser rule named `key` for which the enterKey function was generated. The `Ref<>` template is an alias for `std::shared_ptr<>` to simplify the runtime source code which often makes use of smart pointers.
|
||||
This example assumes your grammar contains a parser rule named `key` for which the enterKey function was generated.
|
||||
|
||||
## Specialities of this ANTLR target
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ Let's suppose that your grammar is named `MyGrammar`. The tool will generate for
|
|||
* MyGrammarLexer.cs
|
||||
* MyGrammarParser.cs
|
||||
* MyGrammarListener.cs (if you have not activated the -no-listener option)
|
||||
* MyGrammarBaseListener.js (if you have not activated the -no-listener option)
|
||||
* MyGrammarVisitor.js (if you have activated the -visitor option)
|
||||
* MyGrammarBaseVisitor.js (if you have activated the -visitor option)
|
||||
* MyGrammarBaseListener.cs (if you have not activated the -no-listener option)
|
||||
* MyGrammarVisitor.cs (if you have activated the -visitor option)
|
||||
* MyGrammarBaseVisitor.cs (if you have activated the -visitor option)
|
||||
|
||||
Now a fully functioning code might look like the following for start rule `StartRule`:
|
||||
|
||||
|
@ -35,7 +35,7 @@ using Antlr4.Runtime;
|
|||
|
||||
public void MyParseMethod() {
|
||||
String input = "your text to parse here";
|
||||
ICharStream stream = CharStreams.fromString(input);
|
||||
ICharStream stream = CharStreams.fromstring(input);
|
||||
ITokenSource lexer = new MyGrammarLexer(stream);
|
||||
ITokenStream tokens = new CommonTokenStream(lexer);
|
||||
MyGrammarParser parser = new MyGrammarParser(tokens);
|
||||
|
|
|
@ -122,7 +122,7 @@ That pops up a dialog box showing that rule `r` matched keyword `hello` followed
|
|||
|
||||
## Book source code
|
||||
|
||||
The book has lots and lots of examples that should be useful to. You can download them here for free:
|
||||
The book has lots and lots of examples that should be useful too. You can download them here for free:
|
||||
|
||||
[http://pragprog.com/titles/tpantlr2/source_code](http://pragprog.com/titles/tpantlr2/source_code)
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func (this *TreeShapeListener) EnterEveryRule(ctx antlr.ParserRuleContext) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
input := antlr.NewFileStream(os.Args[1])
|
||||
input, _ := antlr.NewFileStream(os.Args[1])
|
||||
lexer := parser.NewJSONLexer(input)
|
||||
stream := antlr.NewCommonTokenStream(lexer,0)
|
||||
p := parser.NewJSONParser(stream)
|
||||
|
|
|
@ -96,7 +96,7 @@ Now a fully functioning script might look like the following:
|
|||
|
||||
```javascript
|
||||
var input = "your text to parse here"
|
||||
var chars = CharStreams.fromString(input);
|
||||
var chars = new antlr4.InputStream(input);
|
||||
var lexer = new MyGrammarLexer.MyGrammarLexer(chars);
|
||||
var tokens = new antlr4.CommonTokenStream(lexer);
|
||||
var parser = new MyGrammarParser.MyGrammarParser(tokens);
|
||||
|
@ -154,6 +154,10 @@ In order to execute this listener, you would simply add the following lines to t
|
|||
antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree);
|
||||
```
|
||||
|
||||
## What about TypeScript?
|
||||
|
||||
We currently do not have a TypeScript target, but Sam Harwell is [working on a port](https://github.com/tunnelvisionlabs/antlr4ts). [Here](https://github.com/ChuckJonas/extract-interface-ts) is Section 4.3 of [ANTLR 4 book](http://a.co/5jUJYmh) converted to typescript.
|
||||
|
||||
## How do I integrate my parser with ACE editor?
|
||||
|
||||
This specific task is described in this [dedicated page](ace-javascript-target.md).
|
||||
|
|
|
@ -79,7 +79,7 @@ These more or less correspond to `isJavaIdentifierPart` and `isJavaIdentifierSta
|
|||
|
||||
## Literals
|
||||
|
||||
ANTLR does not distinguish between character and string literals as most languages do. All literal strings one or more characters in length are enclosed in single quotes such as `’;’`, `’if’`, `’>=’`, and `’\’'` (refers to the one-character string containing the single quote character). Literals never contain regular expressions.
|
||||
ANTLR does not distinguish between character and string literals as most languages do. All literal strings one or more characters in length are enclosed in single quotes such as `’;’`, `’if’`, `’>=’`, and `’\’` (refers to the one-character string containing the single quote character). Literals never contain regular expressions.
|
||||
|
||||
Literals can contain Unicode escape sequences of the form `’\uXXXX’` (for Unicode code points up to `’U+FFFF’`) or `’\u{XXXXXX}’` (for all Unicode code points), where `’XXXX’` is the hexadecimal Unicode code point value.
|
||||
|
||||
|
|
|
@ -247,16 +247,13 @@ popd
|
|||
|
||||
*Publishing to Nuget from Linux/MacOSX*
|
||||
|
||||
**Getting ready to run Nuget**
|
||||
**Install the pre-requisites**
|
||||
|
||||
Of course you need Mono and `nuget` to be installed. On mac:
|
||||
|
||||
```bash
|
||||
brew install mono
|
||||
brew install nuget
|
||||
```
|
||||
|
||||
Or, you can [download nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe).
|
||||
- mono - on mac, `brew install mono`
|
||||
- nuget - on mac, `brew install nuget` or you can [download nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe)
|
||||
- dotnet - follow [the instructions here](https://www.microsoft.com/net/core)
|
||||
|
||||
From the shell on mac, you can check all is ok by typing
|
||||
|
||||
|
@ -266,36 +263,23 @@ nuget
|
|||
|
||||
This should display the nuget help.
|
||||
|
||||
**Creating the assembly**
|
||||
**Creating and packaging the assembly**
|
||||
|
||||
```bash
|
||||
$ cd runtime/CSharp/runtime/CSharp/Antlr4.Runtime
|
||||
$ xbuild /p:Configuration=Release Antlr4.Runtime.mono.csproj
|
||||
$ cd runtime/CSharp/runtime/CSharp
|
||||
$ ./build-nuget-package.sh
|
||||
...
|
||||
Copying file from '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.Standard.dll' to '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/lib/Release/Antlr4.Runtime.Standard.dll'
|
||||
Done building project "/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj".
|
||||
```
|
||||
|
||||
Alternately, you may want to build ANTLR using Xamarin Studio Community (free).
|
||||
|
||||
**Packaging for NuGet**
|
||||
|
||||
```bash
|
||||
cd runtime/CSharp/runtime/CSharp
|
||||
```
|
||||
|
||||
which is where the `Package.nuspec` file resides.
|
||||
|
||||
Type the following command:
|
||||
|
||||
```bash
|
||||
$ nuget pack Package.nuspec
|
||||
Build succeeded.
|
||||
0 Warning(s)
|
||||
0 Error(s)
|
||||
Attempting to build package from 'Package.nuspec'.
|
||||
Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime.Standard.4.7.0.nupkg'.
|
||||
Successfully created package '/path/to/antlr/.../Antlr4.Runtime.Standard.4.7.0.nupkg'.
|
||||
```
|
||||
|
||||
This should display: Successfully created package *<package-path>*
|
||||
|
||||
Alternately, you may want to build ANTLR using Xamarin Studio Community (free).
|
||||
|
||||
**Publishing to NuGet**
|
||||
|
||||
You need to be a NuGet owner for "ANTLR 4 Standard Runtime"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.antlr.v4.test.runtime.category;
|
||||
|
||||
/**
|
||||
* Created by ericvergnaud on 27/06/2017.
|
||||
*/
|
||||
public class LeftRecursionTests {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.antlr.v4.test.runtime.category;
|
||||
|
||||
/**
|
||||
* Created by ericvergnaud on 27/06/2017.
|
||||
*/
|
||||
public class LexerTests {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.antlr.v4.test.runtime.category;
|
||||
|
||||
/**
|
||||
* Created by ericvergnaud on 27/06/2017.
|
||||
*/
|
||||
public class ParserTests {
|
||||
}
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeLexersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeLexers extends BaseRuntimeTest {
|
||||
public TestCompositeLexers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
|
||||
package org.antlr.v4.test.runtime.cpp;
|
||||
|
||||
import org.antlr.v4.codegen.model.Parser;
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeParsersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeParsers extends BaseRuntimeTest {
|
||||
public TestCompositeParsers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.FullContextParsingDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestFullContextParsing extends BaseRuntimeTest {
|
||||
public TestFullContextParsing(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LeftRecursionTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LeftRecursionDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LeftRecursionTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLeftRecursion extends BaseRuntimeTest {
|
||||
public TestLeftRecursion(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerErrors extends BaseRuntimeTest {
|
||||
public TestLexerErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerExec extends BaseRuntimeTest {
|
||||
public TestLexerExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ListenersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestListeners extends BaseRuntimeTest {
|
||||
public TestListeners(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParseTreesDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParseTrees extends BaseRuntimeTest {
|
||||
public TestParseTrees(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserErrors extends BaseRuntimeTest {
|
||||
public TestParserErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserExec extends BaseRuntimeTest {
|
||||
public TestParserExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestPerformance extends BaseRuntimeTest {
|
||||
public TestPerformance(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalLexerDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalLexer extends BaseRuntimeTest {
|
||||
public TestSemPredEvalLexer(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalParserDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalParser extends BaseRuntimeTest {
|
||||
public TestSemPredEvalParser(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.cpp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SetsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSets extends BaseRuntimeTest {
|
||||
public TestSets(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||
<NoWarn>$(NoWarn);CS3021</NoWarn>
|
||||
<AssemblyName>Test</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageId>Antlr4.Test.dotnet</PackageId>
|
||||
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
|
||||
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
|
||||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
|
||||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -127,19 +127,6 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
/** 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.
|
||||
if (!PRESERVE_TEST_DIR) {
|
||||
eraseTempDir();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
if (CREATE_PER_TEST_DIRECTORIES) {
|
||||
|
@ -150,7 +137,7 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
else {
|
||||
tmpdir = new File(BASE_TEST_DIR).getAbsolutePath();
|
||||
if (!PRESERVE_TEST_DIR && new File(tmpdir).exists()) {
|
||||
eraseFiles();
|
||||
eraseDirectory(new File(tmpdir));
|
||||
}
|
||||
}
|
||||
antlrToolErrors = new StringBuilder();
|
||||
|
@ -373,7 +360,7 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
else
|
||||
{
|
||||
try {
|
||||
return createDotnetProject() && buildDotnetProject();
|
||||
return buildDotnetProject();
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -426,7 +413,7 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
if (!NETSTANDARD)
|
||||
return new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath();
|
||||
|
||||
return new File(tmpdir, "src/bin/Debug/netcoreapp1.0/Test.dll").getAbsolutePath();
|
||||
return new File(tmpdir, "bin/Release/netcoreapp1.0/Test.dll").getAbsolutePath();
|
||||
}
|
||||
|
||||
private String locateTool(String tool) {
|
||||
|
@ -493,82 +480,56 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
}
|
||||
}
|
||||
|
||||
public boolean createDotnetProject() {
|
||||
public boolean buildDotnetProject() {
|
||||
try {
|
||||
mkdir(tmpdir + "/src");
|
||||
|
||||
// move files to /src, since global.json need to be one level higher
|
||||
File source = new File(tmpdir);
|
||||
File[] files = source.listFiles();
|
||||
for (File thisSource : files) {
|
||||
if (!thisSource.isDirectory()) {
|
||||
File thisDest = new File(tmpdir + "/src/" + thisSource.getName());
|
||||
boolean success = thisSource.renameTo(thisDest);
|
||||
|
||||
if (!success) {
|
||||
throw new RuntimeException("Moving file " + thisSource + " to " + thisDest + " failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save auxiliary files
|
||||
String pack = BaseCSharpTest.class.getPackage().getName().replace(".", "/") + "/";
|
||||
saveResourceAsFile(pack + "global.json", new File(tmpdir, "global.json"));
|
||||
saveResourceAsFile(pack + "project.json", new File(tmpdir, "src/project.json"));
|
||||
return true;
|
||||
saveResourceAsFile(pack + "Antlr4.Test.dotnet.csproj", new File(tmpdir, "Antlr4.Test.dotnet.csproj"));
|
||||
|
||||
// find runtime package
|
||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
final URL runtimeProj = loader.getResource("CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj");
|
||||
if ( runtimeProj==null ) {
|
||||
throw new RuntimeException("C# runtime project file not found!");
|
||||
}
|
||||
File runtimeProjFile = new File(runtimeProj.getFile());
|
||||
String runtimeProjPath = runtimeProjFile.getPath();
|
||||
|
||||
// add Runtime project reference
|
||||
String dotnetcli = locateTool("dotnet");
|
||||
String[] args = new String[] {
|
||||
dotnetcli,
|
||||
"add",
|
||||
"Antlr4.Test.dotnet.csproj",
|
||||
"reference",
|
||||
runtimeProjPath
|
||||
};
|
||||
boolean success = runProcess(args, tmpdir);
|
||||
|
||||
// restore project
|
||||
args = new String[] {
|
||||
dotnetcli,
|
||||
"restore",
|
||||
"Antlr4.Test.dotnet.csproj",
|
||||
"--no-dependencies"
|
||||
};
|
||||
success = runProcess(args, tmpdir);
|
||||
|
||||
// build test
|
||||
args = new String[] {
|
||||
dotnetcli,
|
||||
"build",
|
||||
"Antlr4.Test.dotnet.csproj",
|
||||
"-c",
|
||||
"Release",
|
||||
"--no-dependencies"
|
||||
};
|
||||
success = runProcess(args, tmpdir);
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean buildDotnetProject() {
|
||||
// find runtime package
|
||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
final URL runtimeProj = loader.getResource("CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.xproj");
|
||||
if ( runtimeProj==null ) {
|
||||
throw new RuntimeException("C# runtime project file not found!");
|
||||
}
|
||||
File runtimeProjFile = new File(runtimeProj.getFile());
|
||||
String runtimeProjPath = runtimeProjFile.getParentFile().getParentFile().getPath();
|
||||
String projectRefPath = runtimeProjPath.substring(0, runtimeProjPath.lastIndexOf("/"));
|
||||
|
||||
// update global.json to reference runtime path
|
||||
try {
|
||||
String content = new java.util.Scanner(new File(tmpdir + "/global.json")).useDelimiter("\\Z").next();
|
||||
content = content.replaceAll("replace_this", projectRefPath);
|
||||
java.io.PrintWriter out = new java.io.PrintWriter(tmpdir + "/global.json");
|
||||
out.write(content);
|
||||
out.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// build test
|
||||
String dotnetcli = locateTool("dotnet");
|
||||
String[] args = new String[] {
|
||||
dotnetcli,
|
||||
"restore",
|
||||
".",
|
||||
projectRefPath
|
||||
};
|
||||
|
||||
try {
|
||||
boolean success = runProcess(args, tmpdir);
|
||||
|
||||
args = new String[] {
|
||||
dotnetcli,
|
||||
"build",
|
||||
"src"
|
||||
};
|
||||
success = runProcess(args, tmpdir);
|
||||
}
|
||||
catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -648,7 +609,7 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
|
||||
String dotnet = locateTool("dotnet");
|
||||
return new String[] {
|
||||
dotnet, exec, new File(tmpdir, "src/input").getAbsolutePath(),
|
||||
dotnet, exec, new File(tmpdir, "input").getAbsolutePath(),
|
||||
output.toAbsolutePath().toString(),
|
||||
errorOutput.toAbsolutePath().toString()
|
||||
};
|
||||
|
@ -825,25 +786,30 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
}
|
||||
}
|
||||
|
||||
protected void eraseFiles() {
|
||||
if (tmpdir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
File tmpdirF = new File(tmpdir);
|
||||
String[] files = tmpdirF.list();
|
||||
if(files!=null) for(String file : files) {
|
||||
new File(tmpdir+"/"+file).delete();
|
||||
}
|
||||
protected void eraseDirectory(File dir) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
eraseDirectory(file);
|
||||
}
|
||||
else {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseTempDir() {
|
||||
File tmpdirF = new File(tmpdir);
|
||||
if ( tmpdirF.exists() ) {
|
||||
eraseFiles();
|
||||
tmpdirF.delete();
|
||||
}
|
||||
if (!PRESERVE_TEST_DIR) {
|
||||
File tmpdirF = new File(tmpdir);
|
||||
if ( tmpdirF.exists() ) {
|
||||
eraseDirectory(tmpdirF);
|
||||
tmpdirF.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFirstLineOfException() {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeLexersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeLexers extends BaseRuntimeTest {
|
||||
public TestCompositeLexers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeParsersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeParsers extends BaseRuntimeTest {
|
||||
public TestCompositeParsers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.FullContextParsingDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestFullContextParsing extends BaseRuntimeTest {
|
||||
public TestFullContextParsing(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LeftRecursionTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LeftRecursionDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LeftRecursionTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLeftRecursion extends BaseRuntimeTest {
|
||||
public TestLeftRecursion(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerErrors extends BaseRuntimeTest {
|
||||
public TestLexerErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerExec extends BaseRuntimeTest {
|
||||
public TestLexerExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ListenersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestListeners extends BaseRuntimeTest {
|
||||
public TestListeners(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParseTreesDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParseTrees extends BaseRuntimeTest {
|
||||
public TestParseTrees(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserErrors extends BaseRuntimeTest {
|
||||
public TestParserErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserExec extends BaseRuntimeTest {
|
||||
public TestParserExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestPerformance extends BaseRuntimeTest {
|
||||
public TestPerformance(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalLexerDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalLexer extends BaseRuntimeTest {
|
||||
public TestSemPredEvalLexer(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalParserDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalParser extends BaseRuntimeTest {
|
||||
public TestSemPredEvalParser(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.csharp;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SetsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSets extends BaseRuntimeTest {
|
||||
public TestSets(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"projects": [
|
||||
"replace_this"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dnxcore50"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.1.0"
|
||||
},
|
||||
"CSharp": {
|
||||
"target": "Project",
|
||||
"version": "*"
|
||||
}
|
||||
},
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"outputName": "Test",
|
||||
"nowarn": [
|
||||
"CS3021"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -73,6 +73,29 @@ public class LexerExecDescriptors {
|
|||
|
||||
}
|
||||
|
||||
/* regression test for antlr/antlr4#1925 */
|
||||
public static class UnicodeCharSet extends BaseLexerTestDescriptor {
|
||||
public String input = "均";
|
||||
/**
|
||||
[@0,0:0='均',<1>,1:0]
|
||||
[@1,1:0='<EOF>',<-1>,1:1]
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String output;
|
||||
|
||||
public String errors = null;
|
||||
public String startRule = "";
|
||||
public String grammarName = "L";
|
||||
|
||||
/**
|
||||
lexer grammar L;
|
||||
ID : ([A-Z_]|'\u0100'..'\uFFFE') ([A-Z_0-9]|'\u0100'..'\uFFFE')*;
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
|
||||
}
|
||||
|
||||
public static class CharSetInSet extends BaseLexerTestDescriptor {
|
||||
public String input = "a x";
|
||||
/**
|
||||
|
|
|
@ -581,4 +581,41 @@ public class ParserErrorsDescriptors {
|
|||
public String grammar;
|
||||
|
||||
}
|
||||
|
||||
public static class TokenMismatch3 extends BaseParserTestDescriptor {
|
||||
public String input = "";
|
||||
public String output = null;
|
||||
public String errors = "line 1:0 mismatched input '<EOF>' expecting {'(', BOOLEAN_LITERAL, ID, '$'}\n";
|
||||
public String startRule = "expression";
|
||||
public String grammarName = "T";
|
||||
|
||||
/**
|
||||
grammar T;
|
||||
|
||||
expression
|
||||
: value
|
||||
| expression op=AND expression
|
||||
| expression op=OR expression
|
||||
;
|
||||
value
|
||||
: BOOLEAN_LITERAL
|
||||
| ID
|
||||
| ID1
|
||||
| '(' expression ')'
|
||||
;
|
||||
|
||||
AND : '&&';
|
||||
OR : '||';
|
||||
|
||||
BOOLEAN_LITERAL : 'true' | 'false';
|
||||
|
||||
ID : [a-z]+;
|
||||
ID1 : '$';
|
||||
|
||||
WS : [ \t\r\n]+ -> skip ;
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -674,6 +674,7 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
"import (\n"
|
||||
+" \"github.com/antlr/antlr4/runtime/Go/antlr\"\n"
|
||||
+" \"./parser\"\n"
|
||||
+" \"fmt\"\n"
|
||||
+" \"os\"\n"
|
||||
+")\n"
|
||||
+ "\n"
|
||||
|
@ -696,7 +697,11 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
+ "}\n"
|
||||
+ "\n"
|
||||
+ "func main() {\n"
|
||||
+ " input := antlr.NewFileStream(os.Args[1])\n"
|
||||
+ " input, err := antlr.NewFileStream(os.Args[1])\n"
|
||||
+ " if err != nil {\n"
|
||||
+ " fmt.Printf(\"Failed to find file: %v\", err)\n"
|
||||
+ " return\n"
|
||||
+ " }\n"
|
||||
+ " lexer := parser.New<lexerName>(input)\n"
|
||||
+ " stream := antlr.NewCommonTokenStream(lexer,0)\n"
|
||||
+ "<createParser>"
|
||||
|
@ -734,7 +739,11 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
+ ")\n"
|
||||
+ "\n"
|
||||
+ "func main() {\n"
|
||||
+ " input := antlr.NewFileStream(os.Args[1])\n"
|
||||
+ " input, err := antlr.NewFileStream(os.Args[1])\n"
|
||||
+ " if err != nil {\n"
|
||||
+ " fmt.Printf(\"Failed to find file: %v\", err)\n"
|
||||
+ " return\n"
|
||||
+ " }\n"
|
||||
+ " lexer := parser.New<lexerName>(input)\n"
|
||||
+ " stream := antlr.NewCommonTokenStream(lexer,0)\n"
|
||||
+ " stream.Fill()\n"
|
||||
|
|
|
@ -38,7 +38,7 @@ public class BasePython2Test extends BasePythonTest {
|
|||
+ " lexer = <lexerName>(input, output)\n"
|
||||
+ " stream = CommonTokenStream(lexer)\n"
|
||||
+ " stream.fill()\n"
|
||||
+ " [ print(t, file=output) for t in stream.tokens ]\n"
|
||||
+ " [ print(unicode(t), file=output) for t in stream.tokens ]\n"
|
||||
+ (showDFA ? " print(lexer._interp.decisionToDFA[Lexer.DEFAULT_MODE].toLexerString(), end='', file=output)\n"
|
||||
: "") + "\n" + "if __name__ == '__main__':\n"
|
||||
+ " main(sys.argv)\n" + "\n");
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
package org.antlr.v4.test.runtime.swift;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.runtime.misc.Pair;
|
||||
import org.antlr.v4.test.runtime.ErrorQueue;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestSupport;
|
||||
import org.antlr.v4.test.runtime.StreamVacuum;
|
||||
|
@ -20,113 +20,70 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.mkdir;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BaseSwiftTest implements RuntimeTestSupport {
|
||||
|
||||
/**
|
||||
* The base test directory is the directory where generated files get placed
|
||||
* during unit test execution.
|
||||
* Path of the ANTLR runtime.
|
||||
*/
|
||||
private static final String BASE_TEST_DIR;
|
||||
|
||||
private static String ANTLR_FRAMEWORK_DIR;
|
||||
private static String ANTLR_RUNTIME_PATH;
|
||||
|
||||
/**
|
||||
* Common routine to setup the ANTLR4 runtime.
|
||||
* Absolute path to swift command.
|
||||
*/
|
||||
private static String SWIFT_CMD;
|
||||
|
||||
/**
|
||||
* Environment variable name for swift home.
|
||||
*/
|
||||
private static final String SWIFT_HOME_ENV_KEY = "SWIFT_HOME";
|
||||
|
||||
static {
|
||||
String baseTestDir = System.getProperty("antlr-swift-test-dir");
|
||||
if (baseTestDir == null || baseTestDir.isEmpty()) {
|
||||
baseTestDir = System.getProperty("java.io.tmpdir");
|
||||
}
|
||||
Map<String, String> env = System.getenv();
|
||||
String swiftHome = env.containsKey(SWIFT_HOME_ENV_KEY) ? env.get(SWIFT_HOME_ENV_KEY) : "";
|
||||
SWIFT_CMD = swiftHome + "swift";
|
||||
|
||||
if (!new File(baseTestDir).isDirectory()) {
|
||||
throw new UnsupportedOperationException("The specified base test directory does not exist: " + baseTestDir);
|
||||
}
|
||||
|
||||
BASE_TEST_DIR = baseTestDir;
|
||||
|
||||
//add antlr.swift
|
||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
final URL swiftRuntime = loader.getResource("Swift/Sources/Antlr4");
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
// build swift runtime
|
||||
URL swiftRuntime = loader.getResource("Swift");
|
||||
if (swiftRuntime == null) {
|
||||
throw new RuntimeException("Swift runtime file not found at:" + swiftRuntime.getPath());
|
||||
}
|
||||
String swiftRuntimePath = swiftRuntime.getPath();
|
||||
ANTLR_RUNTIME_PATH = swiftRuntime.getPath();
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, SWIFT_CMD, "build");
|
||||
|
||||
try {
|
||||
String commandLine = "find " + swiftRuntimePath + "/ -iname *.swift -not -name merge.swift -exec cat {} ;";
|
||||
ProcessBuilder builder = new ProcessBuilder(commandLine.split(" "));
|
||||
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
Process p = builder.start();
|
||||
StreamVacuum stdoutVacuum = new StreamVacuum(p.getInputStream());
|
||||
stdoutVacuum.start();
|
||||
p.waitFor();
|
||||
stdoutVacuum.join();
|
||||
|
||||
String antlrSwift = stdoutVacuum.toString();
|
||||
//write to Antlr4
|
||||
ANTLR_FRAMEWORK_DIR = new File(BASE_TEST_DIR, "Antlr4").getAbsolutePath();
|
||||
mkdir(ANTLR_FRAMEWORK_DIR);
|
||||
writeFile(ANTLR_FRAMEWORK_DIR, "Antlr4.swift", antlrSwift);
|
||||
//compile Antlr4 module
|
||||
buildAntlr4Framework();
|
||||
String argsString;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
// shutdown logic
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
public void run() {
|
||||
// shutdown logic
|
||||
eraseAntlrFrameWorkDir();
|
||||
fastFailRunProcess(ANTLR_RUNTIME_PATH, SWIFT_CMD, "package", "clean");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void eraseFilesIn(String dirName) {
|
||||
if (dirName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
File dir = new File(dirName);
|
||||
String[] files = dir.list();
|
||||
if (files != null) for (String file : files) {
|
||||
new File(dirName + "/" + file).delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static void eraseAntlrFrameWorkDir() {
|
||||
File frameworkdir = new File(ANTLR_FRAMEWORK_DIR);
|
||||
if (frameworkdir.exists()) {
|
||||
eraseFilesIn(ANTLR_FRAMEWORK_DIR);
|
||||
frameworkdir.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean buildAntlr4Framework() throws Exception {
|
||||
String argsString = "xcrun -sdk macosx swiftc -emit-library -emit-module Antlr4.swift -module-name Antlr4 -module-link-name Antlr4 -Xlinker -install_name -Xlinker " + ANTLR_FRAMEWORK_DIR + "/libAntlr4.dylib ";
|
||||
return runProcess(argsString, ANTLR_FRAMEWORK_DIR);
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
private String stderrDuringParse;
|
||||
|
||||
/**
|
||||
* Errors found while running antlr
|
||||
*/
|
||||
private StringBuilder antlrToolErrors;
|
||||
|
||||
/**
|
||||
* If error during parser execution, store stderr here; can't return
|
||||
* stdout and stderr. This doesn't trap errors from running antlr.
|
||||
* Source files used in each small swift project.
|
||||
*/
|
||||
protected String stderrDuringParse;
|
||||
private Set<String> sourceFiles = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void testSetUp() throws Exception {
|
||||
|
@ -137,21 +94,20 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
tmpdir = prop;
|
||||
}
|
||||
else {
|
||||
tmpdir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName() +
|
||||
"-" + Thread.currentThread().getName() + "-" + System.currentTimeMillis()).getAbsolutePath();
|
||||
String classSimpleName = getClass().getSimpleName();
|
||||
String threadName = Thread.currentThread().getName();
|
||||
String childPath = String.format("%s-%s-%s", classSimpleName, threadName, System.currentTimeMillis());
|
||||
tmpdir = new File(System.getProperty("java.io.tmpdir"), childPath).getAbsolutePath();
|
||||
}
|
||||
antlrToolErrors = new StringBuilder();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testTearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eraseTempDir() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,78 +135,80 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
|
||||
@Override
|
||||
public String execLexer(String grammarFileName, String grammarStr, String lexerName, String input, boolean showDFA) {
|
||||
boolean success = rawGenerateRecognizer(grammarFileName,
|
||||
generateParser(grammarFileName,
|
||||
grammarStr,
|
||||
null,
|
||||
lexerName);
|
||||
assertTrue(success);
|
||||
writeFile(tmpdir, "input", input);
|
||||
writeLexerTestFile(lexerName, showDFA);
|
||||
addSourceFiles("main.swift");
|
||||
|
||||
compile();
|
||||
String output = execTest();
|
||||
return output;
|
||||
String projectName = "testcase-" + System.currentTimeMillis();
|
||||
String projectDir = getTmpDir() + "/" + projectName;
|
||||
buildProject(projectDir);
|
||||
return execTest(projectDir, projectName);
|
||||
}
|
||||
|
||||
private String execTest() {
|
||||
@Override
|
||||
public String execParser(String grammarFileName, String grammarStr, String parserName, String lexerName, String listenerName, String visitorName, String startRuleName, String input, boolean showDiagnosticErrors) {
|
||||
generateParser(grammarFileName,
|
||||
grammarStr,
|
||||
parserName,
|
||||
lexerName,
|
||||
"-visitor");
|
||||
writeFile(getTmpDir(), "input", input);
|
||||
return execParser(parserName,
|
||||
lexerName,
|
||||
startRuleName,
|
||||
showDiagnosticErrors,false);
|
||||
}
|
||||
|
||||
private String execTest(String projectDir, String projectName) {
|
||||
try {
|
||||
String exec = tmpdir + "/" + EXEC_NAME;
|
||||
String[] args =
|
||||
new String[]{exec, "input"};//new File(tmpdir, "input").getAbsolutePath()
|
||||
ProcessBuilder pb = new ProcessBuilder(args);
|
||||
pb.directory(new File(tmpdir));
|
||||
Process p = pb.start();
|
||||
StreamVacuum stdoutVacuum = new StreamVacuum(p.getInputStream());
|
||||
StreamVacuum stderrVacuum = new StreamVacuum(p.getErrorStream());
|
||||
stdoutVacuum.start();
|
||||
stderrVacuum.start();
|
||||
p.waitFor();
|
||||
stdoutVacuum.join();
|
||||
stderrVacuum.join();
|
||||
String output = stdoutVacuum.toString();
|
||||
if ( output.length()==0 ) {
|
||||
output = null;
|
||||
Pair<String, String> output = runProcess(projectDir, "./.build/debug/" + projectName, "input");
|
||||
if (output.b.length() > 0) {
|
||||
stderrDuringParse = output.b;
|
||||
}
|
||||
if (stderrVacuum.toString().length() > 0) {
|
||||
this.stderrDuringParse = stderrVacuum.toString();
|
||||
}
|
||||
return output;
|
||||
String stdout = output.a;
|
||||
return stdout.length() > 0 ? stdout : null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("can't exec recognizer");
|
||||
System.err.println("Execution of testcase failed.");
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Set<String> sourceFiles = new HashSet<String>();
|
||||
|
||||
private void addSourceFiles(String... files) {
|
||||
Collections.addAll(this.sourceFiles, files);
|
||||
}
|
||||
|
||||
public boolean compile() {
|
||||
private void buildProject(String projectDir) {
|
||||
mkdir(projectDir);
|
||||
fastFailRunProcess(projectDir, SWIFT_CMD, "package", "init", "--type", "executable");
|
||||
for (String sourceFile: sourceFiles) {
|
||||
String absPath = getTmpDir() + "/" + sourceFile;
|
||||
fastFailRunProcess(getTmpDir(), "mv", "-f", absPath, projectDir + "/Sources/");
|
||||
}
|
||||
fastFailRunProcess(getTmpDir(), "mv", "-f", "input", projectDir);
|
||||
|
||||
try {
|
||||
return buildProject();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
String dylibPath = ANTLR_RUNTIME_PATH + "/.build/debug/";
|
||||
Pair<String, String> buildResult = runProcess(projectDir, SWIFT_CMD, "build",
|
||||
"-Xswiftc", "-I"+dylibPath,
|
||||
"-Xlinker", "-L"+dylibPath,
|
||||
"-Xlinker", "-lAntlr4",
|
||||
"-Xlinker", "-rpath",
|
||||
"-Xlinker", dylibPath);
|
||||
if (buildResult.b.length() > 0) {
|
||||
throw new RuntimeException("unit test build failed: " + buildResult.b);
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String EXEC_NAME = "Test";
|
||||
|
||||
private boolean buildProject() throws Exception {
|
||||
String fileList = sourceFiles.toString().replace("[", "").replace("]", "")
|
||||
.replace(", ", " ");
|
||||
|
||||
String argsString = "xcrun -sdk macosx swiftc " + fileList + " -o " + EXEC_NAME + " -I " + ANTLR_FRAMEWORK_DIR + " -L " + ANTLR_FRAMEWORK_DIR + " -module-link-name Antlr4 -suppress-warnings";
|
||||
return runProcess(argsString, tmpdir);
|
||||
}
|
||||
|
||||
private static boolean runProcess(String argsString, String execPath) throws IOException, InterruptedException {
|
||||
String[] args = argsString.split(" ");
|
||||
// System.err.println("Starting build " + argsString);//Utils.join(args, " "))
|
||||
private static Pair<String,String> runProcess(String execPath, String... args) throws IOException, InterruptedException {
|
||||
Process process = Runtime.getRuntime().exec(args, null, new File(execPath));
|
||||
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
|
||||
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
|
||||
|
@ -259,46 +217,26 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
process.waitFor();
|
||||
stdoutVacuum.join();
|
||||
stderrVacuum.join();
|
||||
if (stderrVacuum.toString().length() > 0) {
|
||||
//this.stderrDuringParse = stderrVacuum.toString();
|
||||
System.err.println("buildProject stderrVacuum: " + stderrVacuum);
|
||||
return new Pair<>(stdoutVacuum.toString(), stderrVacuum.toString());
|
||||
}
|
||||
|
||||
private static void fastFailRunProcess(String workingDir, String... command) {
|
||||
ProcessBuilder builder = new ProcessBuilder(command);
|
||||
builder.directory(new File(workingDir));
|
||||
try {
|
||||
Process p = builder.start();
|
||||
p.waitFor();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return process.exitValue() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execParser(String grammarFileName, String grammarStr, String parserName, String lexerName, String listenerName, String visitorName, String startRuleName, String input, boolean showDiagnosticErrors) {
|
||||
return execParser(grammarFileName, grammarStr, parserName,
|
||||
lexerName, startRuleName, input, showDiagnosticErrors, false);
|
||||
}
|
||||
|
||||
protected String execParser(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
String startRuleName,
|
||||
String input, boolean debug,boolean profile)
|
||||
private String execParser(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
boolean debug,
|
||||
boolean profile)
|
||||
{
|
||||
boolean success = rawGenerateRecognizer(grammarFileName,
|
||||
grammarStr,
|
||||
parserName,
|
||||
lexerName,
|
||||
"-visitor");
|
||||
assertTrue(success);
|
||||
writeFile(tmpdir, "input", input);
|
||||
return rawExecRecognizer(parserName,
|
||||
lexerName,
|
||||
startRuleName,
|
||||
debug,profile);
|
||||
}
|
||||
|
||||
protected String rawExecRecognizer(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
boolean debug,
|
||||
boolean profile)
|
||||
{
|
||||
this.stderrDuringParse = null;
|
||||
if ( parserName==null ) {
|
||||
writeLexerTestFile(lexerName, false);
|
||||
}
|
||||
|
@ -311,24 +249,22 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
}
|
||||
|
||||
addSourceFiles("main.swift");
|
||||
return execRecognizer();
|
||||
String projectName = "testcase-" + System.currentTimeMillis();
|
||||
String projectDir = getTmpDir() + "/" + projectName;
|
||||
buildProject(projectDir);
|
||||
return execTest(projectDir, projectName);
|
||||
}
|
||||
|
||||
public String execRecognizer() {
|
||||
compile();
|
||||
return execTest();
|
||||
}
|
||||
|
||||
protected void writeParserTestFile(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
boolean debug,
|
||||
boolean profile) {
|
||||
private void writeParserTestFile(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
boolean debug,
|
||||
boolean profile) {
|
||||
|
||||
ST outputFileST = new ST(
|
||||
"import Antlr4\n" +
|
||||
"import Foundation\n" +
|
||||
"setbuf(__stdoutp, nil)\n" +
|
||||
"setbuf(stdout, nil)\n" +
|
||||
"class TreeShapeListener: ParseTreeListener{\n" +
|
||||
" func visitTerminal(_ node: TerminalNode){ }\n" +
|
||||
" func visitErrorNode(_ node: ErrorNode){ }\n" +
|
||||
|
@ -384,12 +320,12 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
writeFile(tmpdir, "main.swift", outputFileST.render());
|
||||
}
|
||||
|
||||
protected void writeLexerTestFile(String lexerName, boolean showDFA) {
|
||||
private void writeLexerTestFile(String lexerName, boolean showDFA) {
|
||||
ST outputFileST = new ST(
|
||||
"import Antlr4\n" +
|
||||
"import Antlr4\n" +
|
||||
"import Foundation\n" +
|
||||
|
||||
"setbuf(__stdoutp, nil)\n" +
|
||||
"setbuf(stdout, nil)\n" +
|
||||
"let args = CommandLine.arguments\n" +
|
||||
"let input = ANTLRFileStream(args[1])\n" +
|
||||
"let lex = <lexerName>(input)\n" +
|
||||
|
@ -415,39 +351,27 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return true if all is well
|
||||
* Generates the parser for one test case.
|
||||
*/
|
||||
private boolean rawGenerateRecognizer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
String... extraOptions) {
|
||||
return rawGenerateRecognizer(grammarFileName, grammarStr, parserName, lexerName, false, extraOptions);
|
||||
}
|
||||
private void generateParser(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
String... extraOptions) {
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "Swift", grammarFileName, grammarStr, false, extraOptions);
|
||||
assertTrue(equeue.errors.isEmpty());
|
||||
// System.out.println(getTmpDir());
|
||||
|
||||
/**
|
||||
* Return true if all is well
|
||||
*/
|
||||
private boolean rawGenerateRecognizer(String grammarFileName,
|
||||
String grammarStr,
|
||||
String parserName,
|
||||
String lexerName,
|
||||
boolean defaultListener,
|
||||
String... extraOptions) {
|
||||
ErrorQueue equeue = antlrOnString(getTmpDir(), "Swift", grammarFileName, grammarStr, defaultListener, extraOptions);
|
||||
if (!equeue.errors.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> files = new ArrayList<String>();
|
||||
List<String> files = new ArrayList<>();
|
||||
if (lexerName != null) {
|
||||
files.add(lexerName + ".swift");
|
||||
files.add(lexerName + "ATN.swift");
|
||||
}
|
||||
|
||||
if (parserName != null) {
|
||||
files.add(parserName + ".swift");
|
||||
files.add(parserName + "ATN.swift");
|
||||
Set<String> optionsSet = new HashSet<String>(Arrays.asList(extraOptions));
|
||||
Set<String> optionsSet = new HashSet<>(Arrays.asList(extraOptions));
|
||||
String grammarName = grammarFileName.substring(0, grammarFileName.lastIndexOf('.'));
|
||||
if (!optionsSet.contains("-no-listener")) {
|
||||
files.add(grammarName + "Listener.swift");
|
||||
|
@ -459,19 +383,5 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
addSourceFiles(files.toArray(new String[files.size()]));
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
protected Tool newTool(String[] args) {
|
||||
return new Tool(args);
|
||||
}
|
||||
|
||||
protected Tool newTool() {
|
||||
return new Tool(new String[]{"-o", tmpdir});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeLexersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeLexers extends BaseRuntimeTest {
|
||||
public TestCompositeLexers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.CompositeParsersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestCompositeParsers extends BaseRuntimeTest {
|
||||
public TestCompositeParsers(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.FullContextParsingDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestFullContextParsing extends BaseRuntimeTest {
|
||||
public TestFullContextParsing(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LeftRecursionTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LeftRecursionDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LeftRecursionTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLeftRecursion extends BaseRuntimeTest {
|
||||
public TestLeftRecursion(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerErrors extends BaseRuntimeTest {
|
||||
public TestLexerErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.LexerExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestLexerExec extends BaseRuntimeTest {
|
||||
public TestLexerExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ListenersDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestListeners extends BaseRuntimeTest {
|
||||
public TestListeners(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParseTreesDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParseTrees extends BaseRuntimeTest {
|
||||
public TestParseTrees(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserErrorsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserErrors extends BaseRuntimeTest {
|
||||
public TestParserErrors(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.ParserExecDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestParserExec extends BaseRuntimeTest {
|
||||
public TestParserExec(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestPerformance extends BaseRuntimeTest {
|
||||
public TestPerformance(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -9,10 +9,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalLexerDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalLexer extends BaseRuntimeTest {
|
||||
public TestSemPredEvalLexer(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.ParserTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SemPredEvalParserDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(ParserTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSemPredEvalParser extends BaseRuntimeTest {
|
||||
public TestSemPredEvalParser(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.antlr.v4.test.runtime.swift;
|
|||
|
||||
import org.antlr.v4.test.runtime.BaseRuntimeTest;
|
||||
import org.antlr.v4.test.runtime.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.category.LexerTests;
|
||||
import org.antlr.v4.test.runtime.descriptors.SetsDescriptors;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@Category(LexerTests.class)
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestSets extends BaseRuntimeTest {
|
||||
public TestSets(RuntimeTestDescriptor descriptor) {
|
||||
|
|
|
@ -51,7 +51,7 @@ This is just a quick start. The tool has many useful options to control generati
|
|||
|
||||
The Antlr 4 standard runtime for C# is now available from NuGet.
|
||||
We trust that you know how to do add NuGet references to your project :-).
|
||||
The package id is Antlr.4.Runtime. We do not support other packages.
|
||||
The package id is Antlr4.Runtime.Standard. We do not support other packages.
|
||||
|
||||
|
||||
### Step 6: You're done!
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Company>The ANTLR Organization</Company>
|
||||
<Version>4.7.1</Version>
|
||||
<TargetFramework>netstandard1.3</TargetFramework>
|
||||
<DefineConstants>$(DefineConstants);DOTNETCORE;NET35PLUS;NET40PLUS;NET45PLUS</DefineConstants>
|
||||
<NoWarn>$(NoWarn);CS1591;CS1574;CS1580</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<AssemblyName>Antlr4.Runtime.Core</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>../../Antlr4.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
<PackageId>Antlr4.Runtime.Core</PackageId>
|
||||
<Title>ANTLR 4 .NET Core Runtime</Title>
|
||||
<Authors>Eric Vergnaud, Terence Parr, Sam Harwell</Authors>
|
||||
<Description>The .NET Core C# ANTLR 4 runtime from the ANTLR Organization</Description>
|
||||
<Copyright>Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.</Copyright>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<PackageLicenseUrl>https://github.com/antlr/antlr4/blob/master/LICENSE.txt</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/antlr/antlr4</PackageProjectUrl>
|
||||
<PackageIconUrl>https://raw.github.com/antlr/website-antlr4/master/images/icons/antlr.png</PackageIconUrl>
|
||||
<PackageReleaseNotes>https://github.com/antlr/antlr4/releases</PackageReleaseNotes>
|
||||
<PackageTags>antlr parsing grammar</PackageTags>
|
||||
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
|
||||
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
|
||||
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
|
||||
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
|
||||
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
|
||||
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>lib\Debug</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>lib\Release</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>12962409-846e-4b80-933a-bc484d264132</ProjectGuid>
|
||||
<RootNamespace>Antlr4.Runtime.dotnet</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -1,20 +1,32 @@
|
|||
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26114.2
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Antlr4.Runtime.dotnet", "Antlr4.Runtime\Antlr4.Runtime.dotnet.xproj", "{12962409-846E-4B80-933A-BC484D264132}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.dotnet", "Antlr4.Runtime\Antlr4.Runtime.dotnet.csproj", "{0F9F8436-A767-4407-8E81-F9C6270E2B5A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{12962409-846E-4B80-933A-BC484D264132}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{12962409-846E-4B80-933A-BC484D264132}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{12962409-846E-4B80-933A-BC484D264132}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{12962409-846E-4B80-933A-BC484D264132}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|x64.Build.0 = Debug|x64
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Debug|x86.Build.0 = Debug|x86
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|x64.ActiveCfg = Release|x64
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|x64.Build.0 = Release|x64
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|x86.ActiveCfg = Release|x86
|
||||
{0F9F8436-A767-4407-8E81-F9C6270E2B5A}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Antlr4.Runtime.Standard</id>
|
||||
<version>4.7</version>
|
||||
<version>4.7.1</version>
|
||||
<language>en-us</language>
|
||||
<title>ANTLR 4 Standard Runtime</title>
|
||||
<description>The standard C# ANTLR 4 runtime from the ANTLR Organization</description>
|
||||
|
@ -20,5 +20,6 @@
|
|||
</metadata>
|
||||
<files>
|
||||
<file src="Antlr4.Runtime/lib/Release/Antlr4.Runtime.Standard.dll" target="lib/net35/"/>
|
||||
<file src="Antlr4.Runtime/lib/Release/netstandard1.3/Antlr4.Runtime.Core.dll" target="lib/netstandard/"/>
|
||||
</files>
|
||||
</package>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Build a .NET 3.5 compatible DLL using mono
|
||||
# This step can be done by the `dotnet` cli once https://github.com/Microsoft/msbuild/issues/1333 is resolved.
|
||||
echo "Step 1: Building .NET 3.5 DLL"
|
||||
xbuild /p:Configuration=Release Antlr4.mono.sln
|
||||
|
||||
# Build a .NET core DLL using the `dotnet` cli from microsoft
|
||||
echo "Step 2: Building .NET Core DLL"
|
||||
dotnet restore Antlr4.dotnet.sln
|
||||
dotnet build -c Release Antlr4.dotnet.sln
|
||||
|
||||
echo "Step 3: Packaging both DLLs into a single nuget package"
|
||||
nuget pack Package.nuspec
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"version": "4.7-*",
|
||||
"frameworks": {
|
||||
"netstandard1.3": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {},
|
||||
"buildOptions": {
|
||||
"outputName": "Antlr4.Runtime.Standard",
|
||||
"xmlDoc": true,
|
||||
"keyFile": "../Antlr4.snk",
|
||||
"define": [
|
||||
"DOTNETCORE",
|
||||
"NET35PLUS",
|
||||
"NET40PLUS",
|
||||
"NET45PLUS"
|
||||
],
|
||||
"nowarn": [
|
||||
"CS1591",
|
||||
"CS1574",
|
||||
"CS1580"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -28,6 +28,10 @@ if(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
|
|||
CMAKE_POLICY(SET CMP0026 OLD)
|
||||
CMAKE_POLICY(SET CMP0045 OLD)
|
||||
CMAKE_POLICY(SET CMP0042 OLD)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_EQUAL "3.3.0" OR
|
||||
CMAKE_VERSION VERSION_GREATER "3.3.0")
|
||||
CMAKE_POLICY(SET CMP0059 OLD)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#include "ANTLRErrorListener.h"
|
||||
|
||||
antlr4::ANTLRErrorListener::~ANTLRErrorListener()
|
||||
{
|
||||
}
|
|
@ -16,7 +16,7 @@ namespace antlr4 {
|
|||
/// How to emit recognition errors (an interface in Java).
|
||||
class ANTLR4CPP_PUBLIC ANTLRErrorListener {
|
||||
public:
|
||||
virtual ~ANTLRErrorListener() {};
|
||||
virtual ~ANTLRErrorListener();
|
||||
|
||||
/// <summary>
|
||||
/// Upon syntax error, notify any interested parties. This is not how to
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#include "ANTLRErrorStrategy.h"
|
||||
|
||||
antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy()
|
||||
{
|
||||
}
|
|
@ -32,7 +32,7 @@ namespace antlr4 {
|
|||
/// <summary>
|
||||
/// Reset the error handler state for the specified {@code recognizer}. </summary>
|
||||
/// <param name="recognizer"> the parser instance </param>
|
||||
virtual ~ANTLRErrorStrategy() {};
|
||||
virtual ~ANTLRErrorStrategy();
|
||||
|
||||
virtual void reset(Parser *recognizer) = 0;
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ void ANTLRInputStream::load(const std::string &input) {
|
|||
// Remove the UTF-8 BOM if present.
|
||||
const char bom[4] = "\xef\xbb\xbf";
|
||||
if (input.compare(0, 3, bom, 3) == 0)
|
||||
_data = antlrcpp::utfConverter.from_bytes(input.data() + 3, input.data() + input.size());
|
||||
_data = antlrcpp::utf8_to_utf32(input.data() + 3, input.data() + input.size());
|
||||
else
|
||||
_data = antlrcpp::utfConverter.from_bytes(input);
|
||||
_data = antlrcpp::utf8_to_utf32(input.data(), input.data() + input.size());
|
||||
p = 0;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ size_t ANTLRInputStream::LA(ssize_t i) {
|
|||
return 0; // undefined
|
||||
}
|
||||
|
||||
ssize_t position = (ssize_t)p;
|
||||
ssize_t position = static_cast<ssize_t>(p);
|
||||
if (i < 0) {
|
||||
i++; // e.g., translate LA(-1) to use offset i=0; then _data[p+0-1]
|
||||
if ((position + i - 1) < 0) {
|
||||
|
@ -79,11 +79,11 @@ size_t ANTLRInputStream::LA(ssize_t i) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((position + i - 1) >= (ssize_t)_data.size()) {
|
||||
if ((position + i - 1) >= static_cast<ssize_t>(_data.size())) {
|
||||
return IntStream::EOF;
|
||||
}
|
||||
|
||||
return _data[(size_t)(position + i - 1)];
|
||||
return _data[static_cast<size_t>((position + i - 1))];
|
||||
}
|
||||
|
||||
size_t ANTLRInputStream::LT(ssize_t i) {
|
||||
|
@ -123,8 +123,8 @@ std::string ANTLRInputStream::getText(const Interval &interval) {
|
|||
return "";
|
||||
}
|
||||
|
||||
size_t start = interval.a;
|
||||
size_t stop = interval.b;
|
||||
size_t start = static_cast<size_t>(interval.a);
|
||||
size_t stop = static_cast<size_t>(interval.b);
|
||||
|
||||
|
||||
if (stop >= _data.size()) {
|
||||
|
@ -136,7 +136,7 @@ std::string ANTLRInputStream::getText(const Interval &interval) {
|
|||
return "";
|
||||
}
|
||||
|
||||
return antlrcpp::utfConverter.to_bytes(_data.substr(start, count));
|
||||
return antlrcpp::utf32_to_utf8(_data.substr(start, count));
|
||||
}
|
||||
|
||||
std::string ANTLRInputStream::getSourceName() const {
|
||||
|
@ -147,7 +147,7 @@ std::string ANTLRInputStream::getSourceName() const {
|
|||
}
|
||||
|
||||
std::string ANTLRInputStream::toString() const {
|
||||
return antlrcpp::utfConverter.to_bytes(_data);
|
||||
return antlrcpp::utf32_to_utf8(_data);
|
||||
}
|
||||
|
||||
void ANTLRInputStream::InitializeInstanceFields() {
|
||||
|
|
|
@ -16,11 +16,7 @@ namespace antlr4 {
|
|||
protected:
|
||||
/// The data being scanned.
|
||||
// UTF-32
|
||||
#if defined(_MSC_VER) && _MSC_VER == 1900
|
||||
i32string _data; // Custom type for VS 2015.
|
||||
#else
|
||||
std::u32string _data;
|
||||
#endif
|
||||
UTF32String _data;
|
||||
|
||||
/// 0..n-1 index into string of next char </summary>
|
||||
size_t p;
|
||||
|
|
|
@ -18,7 +18,7 @@ void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) {
|
|||
context->exception = e;
|
||||
if (context->parent == nullptr)
|
||||
break;
|
||||
context = (ParserRuleContext *)context->parent;
|
||||
context = static_cast<ParserRuleContext *>(context->parent);
|
||||
} while (true);
|
||||
|
||||
try {
|
||||
|
@ -42,7 +42,7 @@ Token* BailErrorStrategy::recoverInline(Parser *recognizer) {
|
|||
context->exception = exception;
|
||||
if (context->parent == nullptr)
|
||||
break;
|
||||
context = (ParserRuleContext *)context->parent;
|
||||
context = static_cast<ParserRuleContext *>(context->parent);
|
||||
} while (true);
|
||||
|
||||
try {
|
||||
|
|
|
@ -96,7 +96,7 @@ size_t BufferedTokenStream::fetch(size_t n) {
|
|||
std::unique_ptr<Token> t(_tokenSource->nextToken());
|
||||
|
||||
if (is<WritableToken *>(t.get())) {
|
||||
(static_cast<WritableToken *>(t.get()))->setTokenIndex((int)_tokens.size());
|
||||
(static_cast<WritableToken *>(t.get()))->setTokenIndex(_tokens.size());
|
||||
}
|
||||
|
||||
_tokens.push_back(std::move(t));
|
||||
|
@ -272,7 +272,7 @@ ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, size_t channel) {
|
|||
}
|
||||
|
||||
if (i == 0)
|
||||
return i;
|
||||
break;
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
|
@ -289,7 +289,7 @@ std::vector<Token *> BufferedTokenStream::getHiddenTokensToRight(size_t tokenInd
|
|||
size_t from = tokenIndex + 1;
|
||||
// if none onchannel to right, nextOnChannel=-1 so set to = last token
|
||||
if (nextOnChannel == -1) {
|
||||
to = (ssize_t)size() - 1;
|
||||
to = static_cast<ssize_t>(size() - 1);
|
||||
} else {
|
||||
to = nextOnChannel;
|
||||
}
|
||||
|
@ -313,11 +313,11 @@ std::vector<Token *> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenInde
|
|||
}
|
||||
|
||||
ssize_t prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
if (prevOnChannel == (ssize_t)tokenIndex - 1) {
|
||||
if (prevOnChannel == static_cast<ssize_t>(tokenIndex - 1)) {
|
||||
return { };
|
||||
}
|
||||
// if none onchannel to left, prevOnChannel=-1 then from=0
|
||||
size_t from = (size_t)(prevOnChannel + 1);
|
||||
size_t from = static_cast<size_t>(prevOnChannel + 1);
|
||||
size_t to = tokenIndex - 1;
|
||||
|
||||
return filterForChannel(from, to, channel);
|
||||
|
@ -336,7 +336,7 @@ std::vector<Token *> BufferedTokenStream::filterForChannel(size_t from, size_t t
|
|||
hidden.push_back(t);
|
||||
}
|
||||
} else {
|
||||
if (t->getChannel() == (size_t)channel) {
|
||||
if (t->getChannel() == static_cast<size_t>(channel)) {
|
||||
hidden.push_back(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace antlr4 {
|
|||
/// A source of characters for an ANTLR lexer.
|
||||
class ANTLR4CPP_PUBLIC CharStream : public IntStream {
|
||||
public:
|
||||
virtual ~CharStream() = 0;
|
||||
virtual ~CharStream();
|
||||
|
||||
/// This method returns the text for a range of characters within this input
|
||||
/// stream. This method is guaranteed to not throw an exception if the
|
||||
|
|
|
@ -35,7 +35,7 @@ CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> source, size_t typ
|
|||
_start = start;
|
||||
_stop = stop;
|
||||
if (_source.first != nullptr) {
|
||||
_line = (int)source.first->getLine();
|
||||
_line = static_cast<int>(source.first->getLine());
|
||||
_charPositionInLine = source.first->getCharPositionInLine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ using namespace antlr4;
|
|||
|
||||
const Ref<TokenFactory<CommonToken>> CommonTokenFactory::DEFAULT = std::make_shared<CommonTokenFactory>();
|
||||
|
||||
CommonTokenFactory::CommonTokenFactory(bool copyText) : copyText(copyText) {
|
||||
CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) {
|
||||
}
|
||||
|
||||
CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) {
|
||||
|
|
|
@ -9,12 +9,11 @@
|
|||
|
||||
using namespace antlr4;
|
||||
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : BufferedTokenStream(tokenSource) {
|
||||
InitializeInstanceFields();
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : CommonTokenStream(tokenSource, Token::DEFAULT_CHANNEL) {
|
||||
}
|
||||
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel) : BufferedTokenStream(tokenSource) {
|
||||
this->channel = channel;
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel_)
|
||||
: BufferedTokenStream(tokenSource), channel(channel_) {
|
||||
}
|
||||
|
||||
ssize_t CommonTokenStream::adjustSeekIndex(size_t i) {
|
||||
|
@ -26,7 +25,7 @@ Token* CommonTokenStream::LB(size_t k) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ssize_t i = (ssize_t)_p;
|
||||
ssize_t i = static_cast<ssize_t>(_p);
|
||||
size_t n = 1;
|
||||
// find k good tokens looking backwards
|
||||
while (n <= k) {
|
||||
|
@ -47,7 +46,7 @@ Token* CommonTokenStream::LT(ssize_t k) {
|
|||
return nullptr;
|
||||
}
|
||||
if (k < 0) {
|
||||
return LB((size_t)-k);
|
||||
return LB(static_cast<size_t>(-k));
|
||||
}
|
||||
size_t i = _p;
|
||||
ssize_t n = 1; // we know tokens[p] is a good one
|
||||
|
@ -77,7 +76,3 @@ int CommonTokenStream::getNumberOfOnChannelTokens() {
|
|||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void CommonTokenStream::InitializeInstanceFields() {
|
||||
channel = Token::DEFAULT_CHANNEL;
|
||||
}
|
||||
|
|
|
@ -34,16 +34,6 @@ namespace antlr4 {
|
|||
* channel.</p>
|
||||
*/
|
||||
class ANTLR4CPP_PUBLIC CommonTokenStream : public BufferedTokenStream {
|
||||
protected:
|
||||
/**
|
||||
* Specifies the channel to use for filtering tokens.
|
||||
*
|
||||
* <p>
|
||||
* The default value is {@link Token#DEFAULT_CHANNEL}, which matches the
|
||||
* default channel assigned to tokens created by the lexer.</p>
|
||||
*/
|
||||
size_t channel;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new {@link CommonTokenStream} using the specified token
|
||||
|
@ -63,21 +53,27 @@ namespace antlr4 {
|
|||
* @param tokenSource The token source.
|
||||
* @param channel The channel to use for filtering tokens.
|
||||
*/
|
||||
CommonTokenStream(TokenSource *tokenSource, int channel);
|
||||
CommonTokenStream(TokenSource *tokenSource, size_t channel);
|
||||
|
||||
protected:
|
||||
virtual ssize_t adjustSeekIndex(size_t i) override;
|
||||
|
||||
virtual Token* LB(size_t k) override;
|
||||
|
||||
public:
|
||||
virtual Token* LT(ssize_t k) override;
|
||||
|
||||
/// Count EOF just once.
|
||||
virtual int getNumberOfOnChannelTokens();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Specifies the channel to use for filtering tokens.
|
||||
*
|
||||
* <p>
|
||||
* The default value is {@link Token#DEFAULT_CHANNEL}, which matches the
|
||||
* default channel assigned to tokens created by the lexer.</p>
|
||||
*/
|
||||
size_t channel;
|
||||
|
||||
virtual ssize_t adjustSeekIndex(size_t i) override;
|
||||
|
||||
virtual Token* LB(size_t k) override;
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
} // namespace antlr4
|
||||
|
|
|
@ -62,18 +62,18 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, const RecognitionExce
|
|||
|
||||
beginErrorCondition(recognizer);
|
||||
if (is<const NoViableAltException *>(&e)) {
|
||||
reportNoViableAlternative(recognizer, (const NoViableAltException &)e);
|
||||
reportNoViableAlternative(recognizer, static_cast<const NoViableAltException &>(e));
|
||||
} else if (is<const InputMismatchException *>(&e)) {
|
||||
reportInputMismatch(recognizer, (const InputMismatchException &)e);
|
||||
reportInputMismatch(recognizer, static_cast<const InputMismatchException &>(e));
|
||||
} else if (is<const FailedPredicateException *>(&e)) {
|
||||
reportFailedPredicate(recognizer, (const FailedPredicateException &)e);
|
||||
reportFailedPredicate(recognizer, static_cast<const FailedPredicateException &>(e));
|
||||
} else if (is<const RecognitionException *>(&e)) {
|
||||
recognizer->notifyErrorListeners(e.getOffendingToken(), e.what(), std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::recover(Parser *recognizer, std::exception_ptr /*e*/) {
|
||||
if (lastErrorIndex == (int)recognizer->getInputStream()->index() &&
|
||||
if (lastErrorIndex == static_cast<int>(recognizer->getInputStream()->index()) &&
|
||||
lastErrorStates.contains(recognizer->getState())) {
|
||||
|
||||
// uh oh, another error at same token index and previously-visited
|
||||
|
@ -82,7 +82,7 @@ void DefaultErrorStrategy::recover(Parser *recognizer, std::exception_ptr /*e*/)
|
|||
// at least to prevent an infinite loop; this is a failsafe.
|
||||
recognizer->consume();
|
||||
}
|
||||
lastErrorIndex = (int)recognizer->getInputStream()->index();
|
||||
lastErrorIndex = static_cast<int>(recognizer->getInputStream()->index());
|
||||
lastErrorStates.add(recognizer->getState());
|
||||
misc::IntervalSet followSet = getErrorRecoverySet(recognizer);
|
||||
consumeUntil(recognizer, followSet);
|
||||
|
@ -312,7 +312,7 @@ misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer)
|
|||
|
||||
if (ctx->parent == nullptr)
|
||||
break;
|
||||
ctx = (RuleContext *)ctx->parent;
|
||||
ctx = static_cast<RuleContext *>(ctx->parent);
|
||||
}
|
||||
recoverSet.remove(Token::EPSILON);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ using namespace antlr4;
|
|||
DiagnosticErrorListener::DiagnosticErrorListener() : DiagnosticErrorListener(true) {
|
||||
}
|
||||
|
||||
DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly) : exactOnly(exactOnly) {
|
||||
DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly_) : exactOnly(exactOnly_) {
|
||||
}
|
||||
|
||||
void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
|
||||
|
@ -53,7 +53,7 @@ void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, const
|
|||
|
||||
std::string DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa) {
|
||||
size_t decision = dfa.decision;
|
||||
size_t ruleIndex = ((atn::ATNState*)dfa.atnStartState)->ruleIndex;
|
||||
size_t ruleIndex = (reinterpret_cast<atn::ATNState*>(dfa.atnStartState))->ruleIndex;
|
||||
|
||||
const std::vector<std::string>& ruleNames = recognizer->getRuleNames();
|
||||
if (ruleIndex == INVALID_INDEX || ruleIndex >= ruleNames.size()) {
|
||||
|
|
|
@ -22,3 +22,43 @@ IOException::IOException(const std::string &msg) : std::exception(), _message(ms
|
|||
const char* IOException::what() const NOEXCEPT {
|
||||
return _message.c_str();
|
||||
}
|
||||
|
||||
//------------------ IllegalStateException -----------------------------------------------------------------------------
|
||||
|
||||
IllegalStateException::~IllegalStateException() {
|
||||
}
|
||||
|
||||
//------------------ IllegalArgumentException --------------------------------------------------------------------------
|
||||
|
||||
IllegalArgumentException::~IllegalArgumentException() {
|
||||
}
|
||||
|
||||
//------------------ NullPointerException ------------------------------------------------------------------------------
|
||||
|
||||
NullPointerException::~NullPointerException() {
|
||||
}
|
||||
|
||||
//------------------ IndexOutOfBoundsException -------------------------------------------------------------------------
|
||||
|
||||
IndexOutOfBoundsException::~IndexOutOfBoundsException() {
|
||||
}
|
||||
|
||||
//------------------ UnsupportedOperationException ---------------------------------------------------------------------
|
||||
|
||||
UnsupportedOperationException::~UnsupportedOperationException() {
|
||||
}
|
||||
|
||||
//------------------ EmptyStackException -------------------------------------------------------------------------------
|
||||
|
||||
EmptyStackException::~EmptyStackException() {
|
||||
}
|
||||
|
||||
//------------------ CancellationException -----------------------------------------------------------------------------
|
||||
|
||||
CancellationException::~CancellationException() {
|
||||
}
|
||||
|
||||
//------------------ ParseCancellationException ------------------------------------------------------------------------
|
||||
|
||||
ParseCancellationException::~ParseCancellationException() {
|
||||
}
|
||||
|
|
|
@ -21,32 +21,51 @@ namespace antlr4 {
|
|||
|
||||
class ANTLR4CPP_PUBLIC IllegalStateException : public RuntimeException {
|
||||
public:
|
||||
IllegalStateException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
IllegalStateException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
IllegalStateException(IllegalStateException const&) = default;
|
||||
~IllegalStateException();
|
||||
IllegalStateException& operator=(IllegalStateException const&) = default;
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC IllegalArgumentException : public RuntimeException {
|
||||
public:
|
||||
IllegalArgumentException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
IllegalArgumentException(IllegalArgumentException const&) = default;
|
||||
IllegalArgumentException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
~IllegalArgumentException();
|
||||
IllegalArgumentException& operator=(IllegalArgumentException const&) = default;
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC NullPointerException : public RuntimeException {
|
||||
public:
|
||||
NullPointerException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
NullPointerException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
NullPointerException(NullPointerException const&) = default;
|
||||
~NullPointerException();
|
||||
NullPointerException& operator=(NullPointerException const&) = default;
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC IndexOutOfBoundsException : public RuntimeException {
|
||||
public:
|
||||
IndexOutOfBoundsException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
IndexOutOfBoundsException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
IndexOutOfBoundsException(IndexOutOfBoundsException const&) = default;
|
||||
~IndexOutOfBoundsException();
|
||||
IndexOutOfBoundsException& operator=(IndexOutOfBoundsException const&) = default;
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC UnsupportedOperationException : public RuntimeException {
|
||||
public:
|
||||
UnsupportedOperationException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
UnsupportedOperationException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
UnsupportedOperationException(UnsupportedOperationException const&) = default;
|
||||
~UnsupportedOperationException();
|
||||
UnsupportedOperationException& operator=(UnsupportedOperationException const&) = default;
|
||||
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC EmptyStackException : public RuntimeException {
|
||||
public:
|
||||
EmptyStackException(const std::string &msg = "") : RuntimeException(msg) {};
|
||||
EmptyStackException(const std::string &msg = "") : RuntimeException(msg) {}
|
||||
EmptyStackException(EmptyStackException const&) = default;
|
||||
~EmptyStackException();
|
||||
EmptyStackException& operator=(EmptyStackException const&) = default;
|
||||
};
|
||||
|
||||
// IOException is not a runtime exception (in the java hierarchy).
|
||||
|
@ -63,12 +82,18 @@ namespace antlr4 {
|
|||
|
||||
class ANTLR4CPP_PUBLIC CancellationException : public IllegalStateException {
|
||||
public:
|
||||
CancellationException(const std::string &msg = "") : IllegalStateException(msg) {};
|
||||
CancellationException(const std::string &msg = "") : IllegalStateException(msg) {}
|
||||
CancellationException(CancellationException const&) = default;
|
||||
~CancellationException();
|
||||
CancellationException& operator=(CancellationException const&) = default;
|
||||
};
|
||||
|
||||
class ANTLR4CPP_PUBLIC ParseCancellationException : public CancellationException {
|
||||
public:
|
||||
ParseCancellationException(const std::string &msg = "") : CancellationException(msg) {};
|
||||
ParseCancellationException(const std::string &msg = "") : CancellationException(msg) {}
|
||||
ParseCancellationException(ParseCancellationException const&) = default;
|
||||
~ParseCancellationException();
|
||||
ParseCancellationException& operator=(ParseCancellationException const&) = default;
|
||||
};
|
||||
|
||||
} // namespace antlr4
|
||||
|
|
|
@ -28,8 +28,8 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
|
|||
atn::ATNState *s = recognizer->getInterpreter<atn::ATNSimulator>()->atn.states[recognizer->getState()];
|
||||
atn::Transition *transition = s->transitions[0];
|
||||
if (is<atn::PredicateTransition*>(transition)) {
|
||||
_ruleIndex = ((atn::PredicateTransition *)transition)->ruleIndex;
|
||||
_predicateIndex = ((atn::PredicateTransition *)transition)->predIndex;
|
||||
_ruleIndex = static_cast<atn::PredicateTransition *>(transition)->ruleIndex;
|
||||
_predicateIndex = static_cast<atn::PredicateTransition *>(transition)->predIndex;
|
||||
} else {
|
||||
_ruleIndex = 0;
|
||||
_predicateIndex = 0;
|
||||
|
|
|
@ -13,3 +13,6 @@ InputMismatchException::InputMismatchException(Parser *recognizer)
|
|||
: RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(),
|
||||
recognizer->getCurrentToken()) {
|
||||
}
|
||||
|
||||
InputMismatchException::~InputMismatchException() {
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ namespace antlr4 {
|
|||
class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException {
|
||||
public:
|
||||
InputMismatchException(Parser *recognizer);
|
||||
InputMismatchException(InputMismatchException const&) = default;
|
||||
~InputMismatchException();
|
||||
InputMismatchException& operator=(InputMismatchException const&) = default;
|
||||
};
|
||||
|
||||
} // namespace antlr4
|
||||
|
|
|
@ -8,3 +8,5 @@
|
|||
using namespace antlr4;
|
||||
|
||||
const std::string IntStream::UNKNOWN_SOURCE_NAME = "<unknown>";
|
||||
|
||||
IntStream::~IntStream() = default;
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace antlr4 {
|
|||
/// </summary>
|
||||
class ANTLR4CPP_PUBLIC IntStream {
|
||||
public:
|
||||
static const size_t EOF = (size_t)-1;
|
||||
static const size_t EOF = std::numeric_limits<size_t>::max();
|
||||
|
||||
/// The value returned by <seealso cref="#LA LA()"/> when the end of the stream is
|
||||
/// reached.
|
||||
|
@ -40,7 +40,7 @@ namespace antlr4 {
|
|||
/// </summary>
|
||||
static const std::string UNKNOWN_SOURCE_NAME;
|
||||
|
||||
virtual ~IntStream() {};
|
||||
virtual ~IntStream();
|
||||
|
||||
/// <summary>
|
||||
/// Consumes the current symbol in the stream. This method has the following
|
||||
|
|
|
@ -19,8 +19,8 @@ namespace antlr4 {
|
|||
class ANTLR4CPP_PUBLIC Lexer : public Recognizer, public TokenSource {
|
||||
public:
|
||||
static const size_t DEFAULT_MODE = 0;
|
||||
static const size_t MORE = (size_t)-2;
|
||||
static const size_t SKIP = (size_t)-3;
|
||||
static const size_t MORE = static_cast<size_t>(-2);
|
||||
static const size_t SKIP = static_cast<size_t>(-3);
|
||||
|
||||
static const size_t DEFAULT_TOKEN_CHANNEL = Token::DEFAULT_CHANNEL;
|
||||
static const size_t HIDDEN = Token::HIDDEN_CHANNEL;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue