Skip to content

Commit 14880cb

Browse files
authored
Merge branch 'master' into support_intel_compiler
2 parents 154585c + 9a701ef commit 14880cb

33 files changed

+998
-772
lines changed

.travis/before-install-osx-dotnet.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
set -euo pipefail
44

55
cache_dir="$HOME/Library/Caches/Antlr4"
6-
dotnet_url='https://download.microsoft.com/download/B/9/F/B9F1AF57-C14A-4670-9973-CDF47209B5BF/dotnet-dev-osx-x64.1.0.4.pkg'
6+
dotnet_url='https://download.microsoft.com/download/F/4/F/F4FCB6EC-5F05-4DF8-822C-FF013DF1B17F/dotnet-dev-osx-x64.1.1.4.pkg'
77
dotnet_file=$(basename "$dotnet_url")
8-
dotnet_shasum='63b5d99028cd8b2454736076106c96ba7d05f0fc'
8+
dotnet_shasum='dc46d93716db8bea8cc3c668088cc9e39384b5a4'
99

1010
thisdir=$(dirname "$0")
1111

appveyor.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ version: '4.7.1-SNAPSHOT+AppVeyor.{build}'
22
cache:
33
- '%USERPROFILE%\.m2'
44
- '%USERPROFILE%\.nuget\packages -> **\project.json'
5+
image: Visual Studio 2017
56
build: off
67
build_script:
78
- mvn -DskipTests install --batch-mode
8-
- msbuild runtime/CSharp/runtime/CSharp/Antlr4.vs2013.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /verbosity:detailed
9+
- msbuild /target:restore /target:rebuild /property:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /verbosity:detailed runtime/CSharp/runtime/CSharp/Antlr4.dotnet.sln
910
- msbuild ./runtime-testsuite/target/classes/CSharp/runtime/CSharp/Antlr4.vs2013.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /verbosity:detailed
11+
after_build:
12+
- msbuild /target:pack /property:Configuration=Release /verbosity:detailed runtime/CSharp/runtime/CSharp/Antlr4.dotnet.sln
1013
test_script:
1114
- mvn install -Dantlr-python2-python="C:\Python27\python.exe" -Dantlr-python3-python="C:\Python35\python.exe" -Dantlr-javascript-nodejs="C:\Program Files (x86)\nodejs\node.exe" --batch-mode
15+
artifacts:
16+
- path: 'runtime\**\*.nupkg'
17+
name: NuGet

contributors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ YYYY/MM/DD, github id, Full name, email
165165
2017/08/29, Eddy Reyes, [email protected]
166166
2017/09/09, brauliobz, Bráulio Bezerra, [email protected]
167167
2017/09/11, sachinjain024, Sachin Jain, [email protected]
168+
2017/09/25, kaedvann, Rostislav Listerenko, [email protected]
168169
2017/10/06, bramp, Andrew Brampton, [email protected]
169170
2017/10/15, simkimsia, Sim Kim Sia, [email protected]
170171
2017/10/27, Griffon26, Maurice van der Pot, [email protected]
171172
2017/05/29, rlfnb, Ralf Neeb, [email protected]
172173
2017/10/29, gendalph, Максим Прохоренко, Maxim\dotProhorenko@[email protected]
173174
2017/11/02, jasonmoo, Jason Mooberry, [email protected]
174175
2017/11/05, ajaypanyala, Ajay Panyala, [email protected]
176+
2017/11/24, zqlu.cn, Zhiqiang Lu, [email protected]

doc/interpreters.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Parser and lexer interpreters
1+
# Parser and Lexer Interpreters
22

33
*Since ANTLR 4.2*
44

5-
For small parsing tasks it is sometimes convenient to use ANTLR in interpreted mode, rather than generating a parser in a particular target, compiling it and running it as part of your application. Here's some sample code that creates lexer and parser Grammar objects and then creates interpreters. Once we have a ParserInterpreter, we can use it to parse starting in any rule we like, given a rule index (which the Grammar can provide).
5+
For small parsing tasks it is sometimes convenient to use ANTLR in interpreted mode, rather than generating a parser in a particular target, compiling it and running it as part of your application. Here's some sample code that creates lexer and parser Grammar objects and then creates interpreters. Once we have a ParserInterpreter, we can use it to parse starting in any rule we like, given a rule index (which the grammar + the parser can provide).
6+
7+
## Action Code
8+
9+
Since interpreters don't use generated parsers + lexers they cannot execute any action code (including predicates). That means the interpreter runs as if there were no predicates at all. If your grammar requires action code in order to parse correctly you will not be able to test it using this approach.
10+
11+
## Java Target Interpreter Setup
612

713
```java
814
LexerGrammar lg = new LexerGrammar(
@@ -76,4 +82,49 @@ ParseTree t = parse(fileName, XMLLexerGrammar, XMLParserGrammar, "document");
7682

7783
This is also how we will integrate instantaneous parsing into ANTLRWorks2 and development environment plug-ins.
7884

79-
See [TestParserInterpreter.java](https://github.com/antlr/antlr4/blob/master/tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java).
85+
See [TestParserInterpreter.java](../tool-testsuite/test/org/antlr/v4/test/tool/TestParserInterpreter.java).
86+
87+
## Non-Java Target Interpreter Setup
88+
The ANTLR4 runtimes do not contain any grammar parsing classes (they are in the ANTLR4 tool jar). Hence we cannot use `LexerGrammar` and `Grammar` to parse grammars for the interpreter. Instead we directly instantiate `LexerInterpreter` and `ParserInterpreter` objects. They require some data (namely symbol information and the ATNs) which only the ANTLR4 tool can give us. However, on each generation run ANTLR not only produces your parser + lexer files but also interpreter data files (*.interp) which contain all you need to feed the interpreters.
89+
90+
A support class (`InterpreterDataReader`) is used to load the data for your convenience, which makes this very easy to use. Btw. even the Java target go this route instead of using the non-runtime classes `Grammar` and `LexerGrammar`. Sometimes it might not be feasible to use the tool jar for whatever reason.
91+
92+
Here's how the setup looks like (C++ example):
93+
94+
```cpp
95+
/**
96+
* sourceFileName - name of the file with content to parse
97+
* lexerName - the name of your lexer (arbitrary, that's what is used in error messages)
98+
* parserName - ditto for the parser
99+
* lexerDataFileName - the lexer interpeter data file name (e.g. `<path>/ExprLexer.interp`)
100+
* parserDataFileName - ditto for the parser (e.g. `<path>/Expr.interp`)
101+
* startRule - the name of the rule to start parsing at
102+
*/
103+
void parse(std::string const& sourceFileName,
104+
std::string const& lexerName, std::string const& parserName,
105+
std::string const& lexerDataFileName, std::string const& parserDataFileName,
106+
std::string const& startRule) {
107+
108+
InterpreterData lexerData = InterpreterDataReader::parseFile(lexerDataFileName);
109+
InterpreterData parserData = InterpreterDataReader::parseFile(parserDataFileName);
110+
111+
ANTLRFileStream input(sourceFileName);
112+
LexerInterpreter lexEngine(lexerName, lexerData.vocabulary, lexerData.ruleNames,
113+
lexerData.channels, lexerData.modes, lexerData.atn, &input);
114+
CommonTokenStream tokens(&lexEngine);
115+
116+
/* Remove comment to print the tokens.
117+
tokens.fill();
118+
std::cout << "INPUT:" << std::endl;
119+
for (auto token : tokens.getTokens()) {
120+
std::cout << token->toString() << std::endl;
121+
}
122+
*/
123+
124+
ParserInterpreter parser(parserName, parserData.vocabulary, parserData.ruleNames,
125+
parserData.atn, &tokens);
126+
tree::ParseTree *tree = parser.parse(parser.getRuleIndex(startRule));
127+
128+
std::cout << "parse tree: " << tree->toStringTree(&parser) << std::endl;
129+
}
130+
```

doc/releasing-antlr.md

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Edit the repository looking for 4.5 or whatever and update it. Bump version in t
3232
* runtime/Python3/setup.py
3333
* runtime/Python3/src/antlr4/Recognizer.py
3434
* runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Properties/AssemblyInfo.cs
35-
* runtime/CSharp/build/version.ps1
36-
* runtime/CSharp/runtime/CSharp/Package.nuspec
35+
* runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.dotnet.csproj
3736
* runtime/JavaScript/src/antlr4/package.json
3837
* runtime/JavaScript/src/antlr4/Recognizer.js
3938
* runtime/Cpp/VERSION
@@ -245,75 +244,55 @@ popd
245244

246245
### CSharp
247246

248-
*Publishing to Nuget from Linux/MacOSX*
247+
*Publishing to Nuget from Windows*
249248

250249
**Install the pre-requisites**
251250

252251
Of course you need Mono and `nuget` to be installed. On mac:
253252

254-
- mono - on mac, `brew install mono`
255-
- nuget - on mac, `brew install nuget` or you can [download nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe)
253+
- .NET build tools - can be loaded from [here](https://www.visualstudio.com/downloads/)
254+
- nuget - download [nuget.exe](https://www.nuget.org/downloads)
256255
- dotnet - follow [the instructions here](https://www.microsoft.com/net/core)
257256

258-
From the shell on mac, you can check all is ok by typing
257+
Alternatively, you can install Visual Studio 2017 and make sure to check boxes with .NET Core SDK.
259258

260-
```bash
261-
nuget
259+
You also need to enable .NET Framework 3.5 support in Windows "Programs and Features".
260+
261+
If everything is ok, the following command will restore nuget packages, build Antlr for .NET Standard and .NET 3.5 and create nuget package:
262+
263+
```PS
264+
msbuild /target:restore /target:rebuild /target:pack /property:Configuration=Release .\Antlr4.dotnet.sln /verbosity:minimal
262265
```
263266

264-
This should display the nuget help.
267+
This should display something like this:
265268

266269
**Creating and packaging the assembly**
267270

268-
```bash
269-
$ cd runtime/CSharp/runtime/CSharp
270-
$ ./build-nuget-package.sh
271-
...
272-
Build succeeded.
273-
0 Warning(s)
274-
0 Error(s)
275-
Attempting to build package from 'Package.nuspec'.
276-
Successfully created package '/path/to/antlr/.../Antlr4.Runtime.Standard.4.7.0.nupkg'.
277271
```
272+
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Framework
273+
Copyright (C) Microsoft Corporation. All rights reserved.
278274
279-
This should display: Successfully created package *&lt;package-path>*
280-
281-
Alternately, you may want to build ANTLR using Xamarin Studio Community (free).
275+
Restoring packages for C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\Antlr4.Runtime.dotnet.csproj...
276+
Generating MSBuild file C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\obj\Antlr4.Runtime.dotnet.csproj.nuget.g.props.
277+
Generating MSBuild file C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\obj\Antlr4.Runtime.dotnet.csproj.nuget.g.targets.
278+
Restore completed in 427.62 ms for C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\Antlr4.Runtime.dotnet.csproj.
279+
Antlr4.Runtime.dotnet -> C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\netstandard1.3\Antlr4.Runtime.Standard.dll
280+
Antlr4.Runtime.dotnet -> C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\net35\Antlr4.Runtime.Standard.dll
281+
Successfully created package 'C:\Code\antlr4-fork\runtime\CSharp\runtime\CSharp\Antlr4.Runtime\lib\Release\Antlr4.Runtime.Standard.4.7.2.nupkg'.
282+
```
282283

283284
**Publishing to NuGet**
284285

285286
You need to be a NuGet owner for "ANTLR 4 Standard Runtime"
286-
As a registered NuGet user, you can then manually upload the package spec here (`runtime/CSharp/runtime/CSharp/Package.nuspec`): [https://www.nuget.org/packages/manage/upload](https://www.nuget.org/packages/manage/upload)
287+
As a registered NuGet user, you can then manually upload the package here: [https://www.nuget.org/packages/manage/upload](https://www.nuget.org/packages/manage/upload)
287288

288289
Alternately, you can publish from the cmd line. You need to get your NuGet key from [https://www.nuget.org/account#](https://www.nuget.org/account#) and then from the cmd line, you can then type:
289290

290-
```bash
291+
```cmd
291292
nuget push Antlr4.Runtime.Standard.<version>.nupkg <your-key> -Source https://www.nuget.org/api/v2/package
292293
```
293294

294-
**Creating DLLs**
295-
296-
```bash
297-
cd ~/antlr/code/antlr4/runtime/CSharp/runtime/CSharp
298-
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it
299-
rm Antlr4.Runtime/bin/net20/Release/Antlr4.Runtime.dll
300-
rm Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.dll
301-
# build
302-
xbuild /p:Configuration=Release Antlr4.Runtime/Antlr4.Runtime.mono.csproj
303-
# zip it up to get a version number on zip filename
304-
zip --junk-paths /tmp/antlr-csharp-runtime-4.7.zip Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.Standard.dll
305-
cp /tmp/antlr-csharp-runtime-4.7.zip ~/antlr/sites/website-antlr4/download
306-
```
307-
308-
Move target to website
309-
310-
```bash
311-
pushd ~/antlr/sites/website-antlr4/download
312-
git add antlr-csharp-runtime-4.7.zip
313-
git commit -a -m 'update C# runtime'
314-
git push origin gh-pages
315-
popd
316-
```
295+
Nuget packages are also accessible as artifacts of [AppVeyor builds](https://ci.appveyor.com/project/parrt/antlr4/build/artifacts).
317296

318297
### Python
319298

runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.antlr.v4.runtime.Token;
1111
import org.antlr.v4.runtime.TokenSource;
1212
import org.antlr.v4.runtime.WritableToken;
13+
import org.antlr.v4.runtime.misc.Utils;
1314
import org.antlr.v4.test.runtime.ErrorQueue;
1415
import org.antlr.v4.test.runtime.RuntimeTestSupport;
1516
import org.antlr.v4.test.runtime.StreamVacuum;
@@ -337,7 +338,9 @@ protected String rawExecRecognizer(String parserName,
337338
}
338339

339340
public String execRecognizer() {
340-
compile();
341+
boolean success = compile();
342+
assertTrue(success);
343+
341344
String output = execTest();
342345
if ( output!=null && output.length()==0 ) {
343346
output = null;
@@ -354,6 +357,7 @@ public boolean compile() {
354357
return false;
355358
return true;
356359
} catch(Exception e) {
360+
e.printStackTrace(System.err);
357361
return false;
358362
}
359363
}
@@ -362,6 +366,7 @@ public boolean compile() {
362366
try {
363367
return buildDotnetProject();
364368
} catch(Exception e) {
369+
e.printStackTrace(System.err);
365370
return false;
366371
}
367372
}
@@ -390,10 +395,15 @@ private boolean buildProject() throws Exception {
390395
stdoutVacuum.join();
391396
stderrVacuum.join();
392397
// xbuild sends errors to output, so check exit code
393-
boolean success = process.exitValue()==0;
398+
int exitValue = process.exitValue();
399+
boolean success = (exitValue == 0);
394400
if ( !success ) {
395401
this.stderrDuringParse = stdoutVacuum.toString();
396-
System.err.println("buildProject stderrVacuum: "+ this.stderrDuringParse);
402+
String stderrString = stderrVacuum.toString();
403+
System.err.println("buildProject command: " + Utils.join(args, " "));
404+
System.err.println("buildProject exitValue: " + exitValue);
405+
System.err.println("buildProject stdout: " + stderrDuringParse);
406+
System.err.println("buildProject stderr: " + stderrString);
397407
}
398408
return success;
399409
}
@@ -505,6 +515,7 @@ public boolean buildDotnetProject() {
505515
runtimeProjPath
506516
};
507517
boolean success = runProcess(args, tmpdir);
518+
assertTrue(success);
508519

509520
// restore project
510521
args = new String[] {
@@ -514,6 +525,7 @@ public boolean buildDotnetProject() {
514525
"--no-dependencies"
515526
};
516527
success = runProcess(args, tmpdir);
528+
assertTrue(success);
517529

518530
// build test
519531
args = new String[] {
@@ -525,6 +537,7 @@ public boolean buildDotnetProject() {
525537
"--no-dependencies"
526538
};
527539
success = runProcess(args, tmpdir);
540+
assertTrue(success);
528541
}
529542
catch(Exception e) {
530543
e.printStackTrace(System.err);
@@ -535,6 +548,10 @@ public boolean buildDotnetProject() {
535548
}
536549

537550
private boolean runProcess(String[] args, String path) throws Exception {
551+
return runProcess(args, path, 0);
552+
}
553+
554+
private boolean runProcess(String[] args, String path, int retries) throws Exception {
538555
ProcessBuilder pb = new ProcessBuilder(args);
539556
pb.directory(new File(path));
540557
Process process = pb.start();
@@ -545,10 +562,28 @@ private boolean runProcess(String[] args, String path) throws Exception {
545562
process.waitFor();
546563
stdoutVacuum.join();
547564
stderrVacuum.join();
548-
boolean success = process.exitValue()==0;
565+
int exitValue = process.exitValue();
566+
boolean success = (exitValue == 0);
549567
if ( !success ) {
550568
this.stderrDuringParse = stderrVacuum.toString();
551-
System.err.println("runProcess stderrVacuum: "+ this.stderrDuringParse);
569+
System.err.println("runProcess command: " + Utils.join(args, " "));
570+
System.err.println("runProcess exitValue: " + exitValue);
571+
System.err.println("runProcess stdoutVacuum: " + stdoutVacuum.toString());
572+
System.err.println("runProcess stderrVacuum: " + stderrDuringParse);
573+
}
574+
if (exitValue == 132) {
575+
// Retry after SIGILL. We are seeing this intermittently on
576+
// macOS (issue #2078).
577+
if (retries < 3) {
578+
System.err.println("runProcess retrying; " + retries +
579+
" retries so far");
580+
return runProcess(args, path, retries + 1);
581+
}
582+
else {
583+
System.err.println("runProcess giving up after " + retries +
584+
" retries");
585+
return false;
586+
}
552587
}
553588
return success;
554589
}
@@ -577,9 +612,28 @@ public String execTest() {
577612
ProcessBuilder pb = new ProcessBuilder(args);
578613
pb.directory(tmpdirFile);
579614
Process process = pb.start();
615+
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
616+
StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream());
617+
stdoutVacuum.start();
618+
stderrVacuum.start();
580619
process.waitFor();
620+
stdoutVacuum.join();
621+
stderrVacuum.join();
581622
String writtenOutput = TestOutputReading.read(output);
582623
this.stderrDuringParse = TestOutputReading.read(errorOutput);
624+
int exitValue = process.exitValue();
625+
String stdoutString = stdoutVacuum.toString().trim();
626+
String stderrString = stderrVacuum.toString().trim();
627+
if (exitValue != 0) {
628+
System.err.println("execTest command: " + Utils.join(args, " "));
629+
System.err.println("execTest exitValue: " + exitValue);
630+
}
631+
if (!stdoutString.isEmpty()) {
632+
System.err.println("execTest stdoutVacuum: " + stdoutString);
633+
}
634+
if (!stderrString.isEmpty()) {
635+
System.err.println("execTest stderrVacuum: " + stderrString);
636+
}
583637
return writtenOutput;
584638
}
585639
catch (Exception e) {

runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private void writeParserTestFile(String parserName,
281281
"\n" +
282282
"do {\n" +
283283
"let args = CommandLine.arguments\n" +
284-
"let input = ANTLRFileStream(args[1])\n" +
284+
"let input = try ANTLRFileStream(args[1])\n" +
285285
"let lex = <lexerName>(input)\n" +
286286
"let tokens = CommonTokenStream(lex)\n" +
287287
"<createParser>\n" +
@@ -327,7 +327,7 @@ private void writeLexerTestFile(String lexerName, boolean showDFA) {
327327

328328
"setbuf(stdout, nil)\n" +
329329
"let args = CommandLine.arguments\n" +
330-
"let input = ANTLRFileStream(args[1])\n" +
330+
"let input = try ANTLRFileStream(args[1])\n" +
331331
"let lex = <lexerName>(input)\n" +
332332
"let tokens = CommonTokenStream(lex)\n" +
333333

0 commit comments

Comments
 (0)