From 7dc17ace6e1624ba08e3e2e322b60aa6617f5666 Mon Sep 17 00:00:00 2001
From: Ivan Kochurkin
Date: Sun, 14 May 2017 13:23:53 +0300
Subject: [PATCH 01/50] Distinct error codes, added unit-test. fixes #1865.
---
.../org/antlr/v4/test/tool/TestToolSyntaxErrors.java | 11 +++++++++++
tool/src/org/antlr/v4/tool/ErrorType.java | 8 ++++----
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
index 3219c0bad..b19d6c865 100644
--- a/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
+++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestToolSyntaxErrors.java
@@ -8,6 +8,7 @@ package org.antlr.v4.test.tool;
import org.antlr.v4.Tool;
import org.antlr.v4.tool.ErrorType;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -60,6 +61,16 @@ public class TestToolSyntaxErrors extends BaseJavaToolTest {
super.testSetUp();
}
+ @Test
+ public void AllErrorCodesDistinct() {
+ ErrorType[] errorTypes = ErrorType.class.getEnumConstants();
+ for (int i = 0; i < errorTypes.length; i++) {
+ for (int j = i + 1; j < errorTypes.length; j++) {
+ Assert.assertNotEquals(errorTypes[i].code, errorTypes[j].code);
+ }
+ }
+ }
+
@Test public void testA() { super.testErrors(A, true); }
@Test public void testExtraColon() {
diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java
index 700269fb9..d7ad7ab40 100644
--- a/tool/src/org/antlr/v4/tool/ErrorType.java
+++ b/tool/src/org/antlr/v4/tool/ErrorType.java
@@ -394,11 +394,11 @@ public enum ErrorType {
*/
IMPORT_NAME_CLASH(113, " grammar and imported grammar both generate ", ErrorSeverity.ERROR),
/**
- * Compiler Error 160.
+ * Compiler Error 114.
*
* cannot find tokens file filename
*/
- CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(160, "cannot find tokens file ", ErrorSeverity.ERROR),
+ CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(114, "cannot find tokens file ", ErrorSeverity.ERROR),
/**
* Compiler Warning 118.
*
@@ -522,7 +522,7 @@ public enum ErrorType {
*/
USE_OF_BAD_WORD(134, "symbol conflicts with generated code in target language or runtime", ErrorSeverity.ERROR),
/**
- * Compiler Error 134.
+ * Compiler Error 183.
*
* rule reference rule is not currently supported in a set
*
@@ -530,7 +530,7 @@ public enum ErrorType {
* Note: This error has the same number as the unrelated error
* {@link #USE_OF_BAD_WORD}.
*/
- UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference is not currently supported in a set", ErrorSeverity.ERROR),
+ UNSUPPORTED_REFERENCE_IN_LEXER_SET(183, "rule reference is not currently supported in a set", ErrorSeverity.ERROR),
/**
* Compiler Error 135.
*
From 49b462f9607a08dd98e37e672990afacf04f9136 Mon Sep 17 00:00:00 2001
From: Sergey Parshukov
Date: Wed, 28 Jun 2017 11:43:50 +0300
Subject: [PATCH 02/50] Go file header complies with standardised Go 'generated
code' header
---
contributors.txt | 1 +
tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 71e97419e..4de6877cd 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -150,3 +150,4 @@ YYYY/MM/DD, github id, Full name, email
2017/05/29, kosak, Corey Kosak, kosak@kosak.com
2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, janm@transactionware.com
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
+2017/06/28, jBugman, Sergey Parshukov, codedby@bugman.me
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
index b1835e4e7..75112868a 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
@@ -1,5 +1,5 @@
fileHeader(grammarFileName, ANTLRVersion) ::= <<
-// Generated from by ANTLR .
+// Code generated from by ANTLR . DO NOT EDIT.
>>
ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
From 093009520751d5f4982bb050645703060a678f1e Mon Sep 17 00:00:00 2001
From: Eric Vergnaud
Date: Sat, 15 Jul 2017 12:19:54 +0800
Subject: [PATCH 03/50] fix inconsistent naming in target stg
---
.../v4/tool/templates/codegen/JavaScript/JavaScript.stg | 8 ++++----
.../antlr/v4/tool/templates/codegen/Python2/Python2.stg | 2 +-
.../antlr/v4/tool/templates/codegen/Python3/Python3.stg | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
index fb5883c02..4d04b9f76 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
@@ -36,12 +36,12 @@
* REQUIRED.
*/
-pythonTypeInitMap ::= [
- "bool":"False",
+javascriptTypeInitMap ::= [
+ "bool":"false",
"int":"0",
"float":"0.0",
"str":"",
- default:"None" // anything other than a primitive type is an object
+ default:"{}" // anything other than a primitive type is an object
]
// args must be ,
@@ -860,7 +860,7 @@ var serializedATN = [" "}>"].join("");
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".js"
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
index b01a76fc4..570f1659f 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Python2/Python2.stg
@@ -809,7 +809,7 @@ def serializedATN():
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".py"
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
index 081e3f3f1..34e525b85 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg
@@ -816,7 +816,7 @@ def serializedATN():
* must be an object, default value is "null".
*/
initValue(typeName) ::= <<
-
+
>>
codeFileExtension() ::= ".py"
From 8b3da13259024bf4fd9913ebcc7c950339687779 Mon Sep 17 00:00:00 2001
From: vaibhavaingankar09
Date: Mon, 17 Jul 2017 06:45:29 +0000
Subject: [PATCH 04/50] fix to the ATN deserialiser issue on big endian
architecture
---
contributors.txt | 3 ++-
.../runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs | 5 ++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/contributors.txt b/contributors.txt
index 63d6d57f5..ba29c99e4 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -150,4 +150,5 @@ YYYY/MM/DD, github id, Full name, email
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
\ No newline at end of file
+2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
+2017/07/17, vaibhavaingankar09, Vaibhav Vaingankar, vbhvvaingankar9@gmail.com
diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
index 9009b9f43..3ce2e87d2 100644
--- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
+++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Atn/ATNDeserializer.cs
@@ -1092,7 +1092,10 @@ nextTransition_continue: ;
protected internal Guid ReadUUID()
{
byte[] d = BitConverter.GetBytes (ReadLong ());
- Array.Reverse(d);
+ if(BitConverter.IsLittleEndian)
+ {
+ Array.Reverse(d);
+ }
short c = (short)ReadInt();
short b = (short)ReadInt();
int a = ReadInt32();
From 2bce3a74d4c4c1fcc33611c63dd6afe195dc4f25 Mon Sep 17 00:00:00 2001
From: Corey Kosak
Date: Mon, 17 Jul 2017 17:54:17 -0400
Subject: [PATCH 05/50] Remove the useless visibility attribute from this "enum
class" declaration.
When compiling under gcc, ANTLR4CPP_PUBLIC macro expands to the following
gcc visibility attribute:
__attribute__((visibility ("default")))
(when compiling under Windows it expands to the corresponding __declspec
attribute)
This change was introduced in commit 8ff852640a7ec62d46330f71e274c591ada1fc70
Although the attribute makes perfect sense when applied to a "class"
declaration, it makes no sense (has no effect) when applied to an
"enum class" declaration. I assume that doing so was unintentional; that
when the change was introduced it was it was added mechanically to all
"class XXX" instances in the source code, a process which accidentally
picked up one "enum class XXX" instance.
Although it has no effect on the object code, it leads to the following
warning when compiling under gcc:
/usr/local/include/antlr4-runtime/atn/PredictionMode.h:18:31: error: type attributes ignored after type is already defined [-Werror=attributes]
enum class ANTLR4CPP_PUBLIC PredictionMode {
This is a problem for people who would like their builds to be warning-free.
Happily, this declaration can be safely removed. The "enum class" construct
(just like with regular enum) does not cause any linker symbols to be
emitted. So having a linker attribute on the type does not actually have any
effect. It can therefore be safely removed.
---
runtime/Cpp/runtime/src/atn/PredictionMode.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/runtime/Cpp/runtime/src/atn/PredictionMode.h b/runtime/Cpp/runtime/src/atn/PredictionMode.h
index d3de2e952..726f4cf40 100755
--- a/runtime/Cpp/runtime/src/atn/PredictionMode.h
+++ b/runtime/Cpp/runtime/src/atn/PredictionMode.h
@@ -15,7 +15,7 @@ namespace atn {
* utility methods for analyzing configuration sets for conflicts and/or
* ambiguities.
*/
- enum class ANTLR4CPP_PUBLIC PredictionMode {
+ enum class PredictionMode {
/**
* The SLL(*) prediction mode. This prediction mode ignores the current
* parser context when making predictions. This is the fastest prediction
From 6e02088e6abb687f4752b3d0bfcf9fe56e8b3992 Mon Sep 17 00:00:00 2001
From: Renata Hodovan
Date: Tue, 18 Jul 2017 18:29:36 +0200
Subject: [PATCH 06/50] Python: add public getter to parsers to access syntax
error count.
ANTLR parsers in Java are allowed to access the number of encountered
syntax errors via the getNumberOfSyntaxErrors method. However, the
Python variants must use the protected _syntaxErrors member to get this
value. The patch defines the same getter for Python targets too.
---
runtime/Python2/src/antlr4/Parser.py | 7 +++++++
runtime/Python3/src/antlr4/Parser.py | 8 ++++++++
2 files changed, 15 insertions(+)
diff --git a/runtime/Python2/src/antlr4/Parser.py b/runtime/Python2/src/antlr4/Parser.py
index d88f77918..69abe739b 100644
--- a/runtime/Python2/src/antlr4/Parser.py
+++ b/runtime/Python2/src/antlr4/Parser.py
@@ -218,6 +218,13 @@ class Parser (Recognizer):
self._ctx.exitRule(listener)
listener.exitEveryRule(self._ctx)
+ # Gets the number of syntax errors reported during parsing. This value is
+ # incremented each time {@link #notifyErrorListeners} is called.
+ #
+ # @see #notifyErrorListeners
+ #
+ def getNumberOfSyntaxErrors(self):
+ return self._syntaxErrors
def getTokenFactory(self):
return self._input.tokenSource._factory
diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py
index 03f10a438..c461bbdc0 100644
--- a/runtime/Python3/src/antlr4/Parser.py
+++ b/runtime/Python3/src/antlr4/Parser.py
@@ -227,6 +227,14 @@ class Parser (Recognizer):
listener.exitEveryRule(self._ctx)
+ # Gets the number of syntax errors reported during parsing. This value is
+ # incremented each time {@link #notifyErrorListeners} is called.
+ #
+ # @see #notifyErrorListeners
+ #
+ def getNumberOfSyntaxErrors(self):
+ return self._syntaxErrors
+
def getTokenFactory(self):
return self._input.tokenSource._factory
From e01af374d2d725e236be8ea5c0e12d7d0b1dab10 Mon Sep 17 00:00:00 2001
From: Venkat Peri
Date: Sat, 22 Jul 2017 18:11:37 -0400
Subject: [PATCH 07/50] 'requires' SUPERclass for Lexers in split mode,
symbols/modes/channels available on Lexer prototype for use in lexer actions
(this.SOME_MODE) like in Java actions, Utils.escapeWhiteSpace uses regex for
global replace (was replacing only first occurnce of \n etc).
---
runtime/JavaScript/src/antlr4/Utils.js | 10 +++++-----
.../tool/templates/codegen/JavaScript/JavaScript.stg | 8 ++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/runtime/JavaScript/src/antlr4/Utils.js b/runtime/JavaScript/src/antlr4/Utils.js
index d7627be60..2cb939a66 100644
--- a/runtime/JavaScript/src/antlr4/Utils.js
+++ b/runtime/JavaScript/src/antlr4/Utils.js
@@ -401,11 +401,11 @@ DoubleDict.prototype.set = function (a, b, o) {
function escapeWhitespace(s, escapeSpaces) {
- s = s.replace("\t", "\\t");
- s = s.replace("\n", "\\n");
- s = s.replace("\r", "\\r");
+ s = s.replace(/\t/g, "\\t")
+ .replace(/\n/g, "\\n")
+ .replace(/\r/g, "\\r");
if (escapeSpaces) {
- s = s.replace(" ", "\u00B7");
+ s = s.replace(/ /g, "\u00B7");
}
return s;
}
@@ -443,4 +443,4 @@ exports.hashStuff = hashStuff;
exports.escapeWhitespace = escapeWhitespace;
exports.arrayToString = arrayToString;
exports.titleCase = titleCase;
-exports.equalArrays = equalArrays;
\ No newline at end of file
+exports.equalArrays = equalArrays;
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
index fb5883c02..6981ec03f 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
@@ -160,6 +160,7 @@ Object.defineProperty(.prototype, "atn", {
});
.EOF = antlr4.Token.EOF;
+.prototype.EOF = antlr4.Token.EOF;
. = ;}; separator="\n", wrap, anchor>
@@ -802,6 +803,9 @@ var antlr4 = require('antlr4/index');
>>
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
+
+var = require('./').;
+
@@ -819,14 +823,18 @@ function (input) {
.prototype.constructor = ;
.EOF = antlr4.Token.EOF;
+.prototype.EOF = antlr4.Token.EOF;
. = ;}; separator="\n", wrap, anchor>
+.prototype. = ;}; separator="\n", wrap, anchor>
. = ;}; separator="\n">
+.prototype. = ;}; separator="\n">
. = ;}; separator="\n">
+.prototype. = ;}; separator="\n">
.prototype.channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", "}; separator=", ", wrap, anchor> ];
From 61edb0204dff4e35840d8a35e82e937268d02bb5 Mon Sep 17 00:00:00 2001
From: Venkat Peri
Date: Sun, 23 Jul 2017 10:14:34 -0400
Subject: [PATCH 08/50] signed contributors.txt
---
contributors.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 63d6d57f5..4187ee0cc 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -150,4 +150,5 @@ YYYY/MM/DD, github id, Full name, email
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
\ No newline at end of file
+2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
+2017/07/23, venkatperi, Venkat Peri, venkatperi@gmail.com
From caa5e46def0cdd0a48fd0e2bee64bf2bc90b84ec Mon Sep 17 00:00:00 2001
From: Venkat Peri
Date: Mon, 24 Jul 2017 15:09:43 -0400
Subject: [PATCH 09/50] removed proto level stuff
---
.../antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg | 4 ----
1 file changed, 4 deletions(-)
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
index 6981ec03f..3095dcc29 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
@@ -160,7 +160,6 @@ Object.defineProperty(.prototype, "atn", {
});
.EOF = antlr4.Token.EOF;
-.prototype.EOF = antlr4.Token.EOF;
. = ;}; separator="\n", wrap, anchor>
@@ -825,16 +824,13 @@ function (input) {
.EOF = antlr4.Token.EOF;
.prototype.EOF = antlr4.Token.EOF;
. = ;}; separator="\n", wrap, anchor>
-.prototype. = ;}; separator="\n", wrap, anchor>
. = ;}; separator="\n">
-.prototype. = ;}; separator="\n">
. = ;}; separator="\n">
-.prototype. = ;}; separator="\n">
.prototype.channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN", "}; separator=", ", wrap, anchor> ];
From e123bb8cea642577b4291285aca7c1cf44f2f192 Mon Sep 17 00:00:00 2001
From: Venkat Peri
Date: Mon, 24 Jul 2017 15:11:00 -0400
Subject: [PATCH 10/50] removed proto level stuff (one more)
---
.../antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg | 1 -
1 file changed, 1 deletion(-)
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
index 3095dcc29..f143bbd38 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg
@@ -822,7 +822,6 @@ function (input) {
.prototype.constructor = ;
.EOF = antlr4.Token.EOF;
-.prototype.EOF = antlr4.Token.EOF;
. = ;}; separator="\n", wrap, anchor>
From 95338f710ecd201f2a5fe5f451c610aba7c64ae7 Mon Sep 17 00:00:00 2001
From: Matt Hauck
Date: Thu, 27 Jul 2017 20:54:59 -0700
Subject: [PATCH 11/50] Ignore Cmake policy CMP0054
---
runtime/Cpp/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/runtime/Cpp/CMakeLists.txt b/runtime/Cpp/CMakeLists.txt
index 65e704516..07ef35e69 100644
--- a/runtime/Cpp/CMakeLists.txt
+++ b/runtime/Cpp/CMakeLists.txt
@@ -33,6 +33,7 @@ endif()
if(CMAKE_VERSION VERSION_EQUAL "3.3.0" OR
CMAKE_VERSION VERSION_GREATER "3.3.0")
CMAKE_POLICY(SET CMP0059 OLD)
+ CMAKE_POLICY(SET CMP0054 OLD)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
From f12a71306200160bc5b7af99ade1ae11f0f50510 Mon Sep 17 00:00:00 2001
From: Matt Hauck
Date: Thu, 27 Jul 2017 20:56:54 -0700
Subject: [PATCH 12/50] sign contributors.txt
---
contributors.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/contributors.txt b/contributors.txt
index 4b923fd79..97a19126e 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -153,3 +153,4 @@ YYYY/MM/DD, github id, Full name, email
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
+2017/07/27, matthauck, Matt Hauck, matthauck@gmail.com
From ac9f75303e215dbc12937eba68089151aef6f874 Mon Sep 17 00:00:00 2001
From: Niels Basjes
Date: Wed, 2 Aug 2017 14:29:36 +0200
Subject: [PATCH 13/50] Fixed empty CodePointCharStream throwing exception on
getText. Fixes #1949
---
.../test/org/antlr/v4/runtime/TestCodePointCharStream.java | 1 +
.../Java/src/org/antlr/v4/runtime/CodePointCharStream.java | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java b/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
index 25c4c0919..c40c4048c 100644
--- a/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
+++ b/runtime-testsuite/test/org/antlr/v4/runtime/TestCodePointCharStream.java
@@ -23,6 +23,7 @@ public class TestCodePointCharStream {
CodePointCharStream s = CharStreams.fromString("");
assertEquals(0, s.size());
assertEquals(0, s.index());
+ assertEquals("", s.toString());
}
@Test
diff --git a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
index 491ef6918..107faa7b1 100644
--- a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
+++ b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java
@@ -151,8 +151,8 @@ public abstract class CodePointCharStream implements CharStream {
/** Return the UTF-16 encoded string for the given interval */
@Override
public String getText(Interval interval) {
- int startIdx = Math.min(interval.a, size - 1);
- int len = Math.min(interval.b - interval.a + 1, size);
+ int startIdx = Math.min(interval.a, size);
+ int len = Math.min(interval.b - interval.a + 1, size - startIdx);
// We know the maximum code point in byteArray is U+00FF,
// so we can treat this as if it were ISO-8859-1, aka Latin-1,
From ba75dc95501c75414f787e60cb03acfdd99b28c2 Mon Sep 17 00:00:00 2001
From: Arshinskiy Mike
Date: Thu, 3 Aug 2017 01:03:28 +0200
Subject: [PATCH 14/50] Added additional interval math functionality
---
runtime/Go/antlr/interval_set.go | 62 ++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/runtime/Go/antlr/interval_set.go b/runtime/Go/antlr/interval_set.go
index 510d90911..630b88032 100644
--- a/runtime/Go/antlr/interval_set.go
+++ b/runtime/Go/antlr/interval_set.go
@@ -27,6 +27,68 @@ func (i *Interval) Contains(item int) bool {
return item >= i.Start && item < i.Stop
}
+// Does this start completely before other? Disjoint
+func (i *Interval) StartsBeforeDisjoint(other *Interval) bool{
+ return i.Start= other.Start
+}
+
+// Does this.a start after other.b? May or may not be disjoint
+func (i *Interval) StartsAfter(other *Interval) bool{
+ return i.Start > other.Start
+}
+
+// Does this start completely after other? Disjoint
+func (i *Interval) StartsAfterDisjoint(other *Interval) bool{
+ return i.Start > other.Stop
+}
+
+// Does this start after other? NonDisjoint
+func (i *Interval) StartsAfterNonDisjoint(other *Interval) bool{
+ return i.Start>other.Start && i.Start <= other.Stop // i.Stop>=other.Stop implied
+}
+
+// Are both ranges disjoint? I.e., no overlap?
+func (i *Interval) Disjoint(other *Interval) bool{
+ return i.StartsBeforeDisjoint(other) || i.StartsAfterDisjoint(other)
+}
+
+// Are two intervals adjacent such as 0..41 and 42..42?
+func (i *Interval) Adjacent(other *Interval) bool{
+ return i.Start == other.Stop+1 || i.Stop == other.Start-1;
+}
+
+func (i *Interval) ProperlyContains(other *Interval) bool{
+ return other.Start >= i.Start && other.Stop <= i.Stop
+}
+
+// Return the interval computed from combining this and other
+func (i *Interval) Union(other *Interval) *Interval{
+ return NewInterval(intMin(i.Start, other.Start), intMax(i.Stop, other.Stop))
+}
+
+// Return the interval in common between this and other
+func (i *Interval) Intersection(other *Interval) *Interval{
+ return NewInterval(intMax(i.Start, other.Start), intMin(i.Stop, other.Stop))
+}
+// Return the interval with elements from this not in other;
+// other must not be totally enclosed (properly contained)
+// within this, which would result in two disjoint intervals
+// instead of the single one returned by this method.
+func (i *Interval) DifferenceNotProperlyContained(other *Interval) *Interval{
+ var diff *Interval = nil
+ if other.StartsBeforeDisjoint(i){
+ diff = NewInterval(intMax(i.Start, other.Stop +1), i.Stop)
+ }else if other.StartsAfterNonDisjoint(i){
+ diff = NewInterval(i.Start, other.Start -1)
+ }
+ return diff
+}
+
func (i *Interval) String() string {
if i.Start == i.Stop-1 {
return strconv.Itoa(i.Start)
From 5f2f7981b75f6223f5cf59e7a93f13c36539e692 Mon Sep 17 00:00:00 2001
From: Sam Harwell
Date: Mon, 7 Aug 2017 18:04:32 -0500
Subject: [PATCH 15/50] Set the tab width in .editorconfig so GitHub shows
source properly
---
.editorconfig | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.editorconfig b/.editorconfig
index 53b65e9f3..daa6da0fb 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,5 +1,8 @@
root = true
+[*]
+tab_width = 4
+
[*.{java,stg}]
charset = utf-8
insert_final_newline = true
From 715bfccb8033106663adb73ce319bf9a6bef868e Mon Sep 17 00:00:00 2001
From: Tiago Mazzutti
Date: Sun, 20 Aug 2017 14:18:41 -0300
Subject: [PATCH 16/50] Update contributors.txt
---
contributors.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 2fda68671..c5d18265b 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -153,4 +153,5 @@ YYYY/MM/DD, github id, Full name, email
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
-2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
\ No newline at end of file
+2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
+2017/08/20, tiagomazzutti, Tiago Mazzutti, tiagomzt@gmail.com
From dc77aacfcd2fc0a068185e06d2356502d97e1a5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Br=C3=A1ulio=20Bezerra?=
Date: Sat, 9 Sep 2017 12:02:42 -0300
Subject: [PATCH 17/50] Fix codegen error (Java) when a lexer has only fragment
tokens
Solves issue #1999.
---
contributors.txt | 3 ++-
.../org/antlr/v4/tool/templates/codegen/Java/Java.stg | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 2fda68671..66996fe3a 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -153,4 +153,5 @@ YYYY/MM/DD, github id, Full name, email
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
-2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
\ No newline at end of file
+2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
+2017/09/09, brauliobz, Bráulio Bezerra, brauliobezerra@gmail.com
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
index 0ebd212ec..492c56644 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
@@ -894,8 +894,10 @@ public class extends {
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
+
public static final int
=}; separator=", ", wrap, anchor>;
+
public static final int
=}; separator=", ", wrap, anchor>;
From 7ed8fe6d295c818c3b62fa6ea457d7a0327e77d3 Mon Sep 17 00:00:00 2001
From: Sachin Jain
Date: Mon, 11 Sep 2017 16:23:45 +0530
Subject: [PATCH 18/50] Minor formatting
Introduced newlines to have better view of steps.
---
doc/getting-started.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/doc/getting-started.md b/doc/getting-started.md
index eaf2141fb..88aa7c990 100644
--- a/doc/getting-started.md
+++ b/doc/getting-started.md
@@ -21,11 +21,13 @@ $ curl -O http://www.antlr.org/download/antlr-4.5.3-complete.jar
Or just download in browser from website:
[http://www.antlr.org/download.html](http://www.antlr.org/download.html)
and put it somewhere rational like `/usr/local/lib`.
+
2. Add `antlr-4.5.3-complete.jar` to your `CLASSPATH`:
```
$ export CLASSPATH=".:/usr/local/lib/antlr-4.5.3-complete.jar:$CLASSPATH"
```
It's also a good idea to put this in your `.bash_profile` or whatever your startup script is.
+
3. Create aliases for the ANTLR Tool, and `TestRig`.
```
$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.5.3-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
From efd985f4c32dd1144e8d465f9152c431159b02a3 Mon Sep 17 00:00:00 2001
From: Sachin Jain
Date: Mon, 11 Sep 2017 16:26:06 +0530
Subject: [PATCH 19/50] Adding mention to contributor.txt
---
contributors.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 2fda68671..26ea8aded 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -153,4 +153,5 @@ YYYY/MM/DD, github id, Full name, email
2017/06/25, alimg, Alim Gökkaya, alim.gokkaya@gmail.com
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
-2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
\ No newline at end of file
+2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com
+2017/09/11, sachinjain024, Sachin Jain, sachinjain024@gmail.com
From 50d2d3ef5541bf3c3a143e58fc0207de8d290d92 Mon Sep 17 00:00:00 2001
From: gendalph
Date: Tue, 12 Sep 2017 22:10:59 +0300
Subject: [PATCH 20/50] CMake build fixes for Visual Studio
Remove unsupported cmd line options (gcc).
Disable warning for DLL.
---
runtime/Cpp/CMakeLists.txt | 10 ++++++++--
runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake | 2 ++
runtime/Cpp/demo/CMakeLists.txt | 8 +++++++-
runtime/Cpp/runtime/CMakeLists.txt | 10 +++++++++-
4 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/runtime/Cpp/CMakeLists.txt b/runtime/Cpp/CMakeLists.txt
index 65e704516..cfc8a7693 100644
--- a/runtime/Cpp/CMakeLists.txt
+++ b/runtime/Cpp/CMakeLists.txt
@@ -25,7 +25,8 @@ project(LIBANTLR4)
if(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
CMAKE_VERSION VERSION_GREATER "3.0.0")
- CMAKE_POLICY(SET CMP0026 OLD)
+ CMAKE_POLICY(SET CMP0026 NEW)
+ CMAKE_POLICY(SET CMP0054 OLD)
CMAKE_POLICY(SET CMP0045 OLD)
CMAKE_POLICY(SET CMP0042 OLD)
endif()
@@ -61,7 +62,9 @@ if (WITH_DEMO)
endif()
endif(WITH_DEMO)
-set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
+if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
+endif ()
# Initialize CXXFLAGS.
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
@@ -75,11 +78,13 @@ else()
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=c++11")
endif()
+if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${MY_CXX_WARNING_FLGAS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g ${MY_CXX_WARNING_FLAGS}")
+endif ()
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
@@ -101,6 +106,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_SYSTEM_NAME MATCHES
if (WITH_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
+elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()
diff --git a/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake b/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake
index e1c28821a..a77c09307 100644
--- a/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake
+++ b/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake
@@ -206,11 +206,13 @@ macro(antlr4cpp_process_grammar
# export generated cpp files into list
foreach(generated_file ${generated_files})
list(APPEND antlr4cpp_src_files_${antlr4cpp_project_namespace} ${generated_file})
+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set_source_files_properties(
${generated_file}
PROPERTIES
COMPILE_FLAGS -Wno-overloaded-virtual
)
+ endif ()
endforeach(generated_file)
message(STATUS "Antlr4Cpp ${antlr4cpp_project_namespace} Generated: ${generated_files}")
diff --git a/runtime/Cpp/demo/CMakeLists.txt b/runtime/Cpp/demo/CMakeLists.txt
index a91c40ddc..53e45fe40 100644
--- a/runtime/Cpp/demo/CMakeLists.txt
+++ b/runtime/Cpp/demo/CMakeLists.txt
@@ -45,11 +45,17 @@ set(antlr4-demo_SRC
${antlr4-demo-GENERATED_SRC}
)
+if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ set (flags_1 "-Wno-overloaded-virtual")
+else()
+ set (flags_1 "-MP /wd4251")
+endif()
+
foreach( src_file ${antlr4-demo_SRC} )
set_source_files_properties(
${src_file}
PROPERTIES
- COMPILE_FLAGS -Wno-overloaded-virtual
+ COMPILE_FLAGS "${COMPILE_FLAGS} ${flags_1}"
)
endforeach( src_file ${antlr4-demo_SRC} )
diff --git a/runtime/Cpp/runtime/CMakeLists.txt b/runtime/Cpp/runtime/CMakeLists.txt
index b2a4fbd02..c51d7f310 100644
--- a/runtime/Cpp/runtime/CMakeLists.txt
+++ b/runtime/Cpp/runtime/CMakeLists.txt
@@ -44,7 +44,10 @@ elseif(APPLE)
target_link_libraries(antlr4_static ${COREFOUNDATION_LIBRARY})
endif()
-set(disabled_compile_warnings "-Wno-overloaded-virtual")
+if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ set(disabled_compile_warnings "-Wno-overloaded-virtual")
+endif ()
+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(disabled_compile_warnings "${disabled_compile_warnings} -Wno-dollar-in-identifier-extension -Wno-four-char-constants")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
@@ -58,6 +61,11 @@ if (WIN32)
set(extra_static_compile_flags "-DANTLR4CPP_STATIC")
endif(WIN32)
+if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ set(extra_share_compile_flags "-DANTLR4CPP_EXPORTS -MP /wd4251")
+ set(extra_static_compile_flags "-DANTLR4CPP_STATIC -MP")
+endif()
+
set_target_properties(antlr4_shared
PROPERTIES VERSION ${ANTLR_VERSION}
SOVERSION ${ANTLR_VERSION}
From 8f30ae661050b4dbf9cdcc1e9473087547a2655c Mon Sep 17 00:00:00 2001
From: Robert Jacobson
Date: Sat, 16 Sep 2017 16:16:01 -0400
Subject: [PATCH 21/50] Import RuleContext into the antlr4 module namespace.
See Issue #2012.
---
runtime/Python3/src/antlr4/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/runtime/Python3/src/antlr4/__init__.py b/runtime/Python3/src/antlr4/__init__.py
index 4eac6c579..37c834202 100644
--- a/runtime/Python3/src/antlr4/__init__.py
+++ b/runtime/Python3/src/antlr4/__init__.py
@@ -12,7 +12,7 @@ from antlr4.atn.LexerATNSimulator import LexerATNSimulator
from antlr4.atn.ParserATNSimulator import ParserATNSimulator
from antlr4.atn.PredictionMode import PredictionMode
from antlr4.PredictionContext import PredictionContextCache
-from antlr4.ParserRuleContext import ParserRuleContext
+from antlr4.ParserRuleContext import RuleContext, ParserRuleContext
from antlr4.tree.Tree import ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, TerminalNode, ErrorNode, RuleNode
from antlr4.error.Errors import RecognitionException, IllegalStateException, NoViableAltException
from antlr4.error.ErrorStrategy import BailErrorStrategy
From 41cd0309a7920477ec2357f852fd8e31bcc249c4 Mon Sep 17 00:00:00 2001
From: fallnirvana <903689031@qq.com>
Date: Tue, 19 Sep 2017 23:19:39 +0800
Subject: [PATCH 22/50] correct the version of the antlr jar package
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
version of the antlr jar package is different from other place of this doc,and it make mistake.
---
doc/getting-started.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/getting-started.md b/doc/getting-started.md
index eaf2141fb..97863fb0c 100644
--- a/doc/getting-started.md
+++ b/doc/getting-started.md
@@ -39,7 +39,7 @@ $ alias grun='java org.antlr.v4.gui.TestRig'
0. Install Java (version 1.6 or higher)
1. Download antlr-4.5.3-complete.jar (or whatever version) from [http://www.antlr.org/download/](http://www.antlr.org/download/)
Save to your directory for 3rd party Java libraries, say `C:\Javalib`
-2. Add `antlr-4.5-complete.jar` to CLASSPATH, either:
+2. Add `antlr-4.5.3-complete.jar` to CLASSPATH, either:
* Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable
* Temporarily, at command line:
```
From d95fb2ec46f41abf30d413cde95271f3e674baa0 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 28 Sep 2017 15:48:25 -0700
Subject: [PATCH 23/50] Replace oraclejdk7 with openjdk7 in .travis.yml.
Oracle JDK 7 support has been withdrawn.
https://github.com/travis-ci/travis-ci/issues/7964
http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
---
.travis.yml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index d27ee56b3..17d1527c1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ matrix:
include:
- os: linux
compiler: clang
- jdk: oraclejdk7
+ jdk: openjdk7
env:
- TARGET=cpp
- CXX=g++-5
@@ -104,13 +104,13 @@ matrix:
- TARGET=dotnet
- GROUP=RECURSION
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=java
- os: linux
jdk: oraclejdk8
env: TARGET=java
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=csharp
- os: linux
jdk: oraclejdk8
@@ -131,10 +131,10 @@ matrix:
- TARGET=dotnet
- GROUP=RECURSION
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=python2
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=python3
addons:
apt:
@@ -143,10 +143,10 @@ matrix:
packages:
- python3.5
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=javascript
- os: linux
- jdk: oraclejdk7
+ jdk: openjdk7
env: TARGET=go
before_install:
From 99d32dc86189a1e25eaded875504167f0309f0bd Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 28 Sep 2017 16:10:26 -0700
Subject: [PATCH 24/50] Add some version numbers to pom.xml.
This silences warnings from Maven.
---
runtime/Java/pom.xml | 1 +
tool/pom.xml | 2 ++
2 files changed, 3 insertions(+)
diff --git a/runtime/Java/pom.xml b/runtime/Java/pom.xml
index c42015629..3eb60b2df 100644
--- a/runtime/Java/pom.xml
+++ b/runtime/Java/pom.xml
@@ -27,6 +27,7 @@
org.apache.maven.plugins
maven-source-plugin
+ 3.0.1
diff --git a/tool/pom.xml b/tool/pom.xml
index 1952a25ec..cb172c534 100644
--- a/tool/pom.xml
+++ b/tool/pom.xml
@@ -58,6 +58,7 @@
org.apache.maven.plugins
maven-source-plugin
+ 3.0.1
@@ -86,6 +87,7 @@
org.codehaus.mojo
build-helper-maven-plugin
+ 3.0.0
generate-sources
From 44031b544dccb9b07dda44b821a14cfdc8337439 Mon Sep 17 00:00:00 2001
From: Eric Vergnaud
Date: Sat, 30 Sep 2017 17:07:40 +0800
Subject: [PATCH 25/50] fix #2031
---
runtime/Python2/src/antlr4/tree/RuleTagToken.py | 9 ++++-----
runtime/Python2/src/antlr4/tree/TokenTagToken.py | 8 ++++----
runtime/Python2/src/antlr4/tree/Tree.py | 6 +++---
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/runtime/Python2/src/antlr4/tree/RuleTagToken.py b/runtime/Python2/src/antlr4/tree/RuleTagToken.py
index 2043c1625..d63a3a53b 100644
--- a/runtime/Python2/src/antlr4/tree/RuleTagToken.py
+++ b/runtime/Python2/src/antlr4/tree/RuleTagToken.py
@@ -36,14 +36,13 @@ class RuleTagToken(Token):
self.tokenIndex = -1 # from 0..n-1 of the token object in the input stream
self.line = 0 # line=1..n of the 1st character
self.column = -1 # beginning of the line at which it occurs, 0..n-1
- self.label = label
+ self.label = unicode(label)
self._text = self.getText() # text of the token.
-
- self.ruleName = ruleName
+ self.ruleName = unicode(ruleName)
def getText(self):
if self.label is None:
- return "<" + self.ruleName + ">"
+ return u"<" + self.ruleName + u">"
else:
- return "<" + self.label + ":" + self.ruleName + ">"
+ return u"<" + self.label + ":" + self.ruleName + u">"
diff --git a/runtime/Python2/src/antlr4/tree/TokenTagToken.py b/runtime/Python2/src/antlr4/tree/TokenTagToken.py
index 2ffc79f6f..dba41f785 100644
--- a/runtime/Python2/src/antlr4/tree/TokenTagToken.py
+++ b/runtime/Python2/src/antlr4/tree/TokenTagToken.py
@@ -24,8 +24,8 @@ class TokenTagToken(CommonToken):
#
def __init__(self, tokenName, type, label=None):
super(TokenTagToken, self).__init__(type=type)
- self.tokenName = tokenName
- self.label = label
+ self.tokenName = unicode(tokenName)
+ self.label = unicode(label)
self._text = self.getText()
#
@@ -36,9 +36,9 @@ class TokenTagToken(CommonToken):
#
def getText(self):
if self.label is None:
- return "<" + self.tokenName + ">"
+ return u"<" + self.tokenName + u">"
else:
- return "<" + self.label + ":" + self.tokenName + ">"
+ return u"<" + self.label + u":" + self.tokenName + u">"
# The implementation for {@link TokenTagToken} returns a string of the form
# {@code tokenName:type}.
diff --git a/runtime/Python2/src/antlr4/tree/Tree.py b/runtime/Python2/src/antlr4/tree/Tree.py
index 26e959612..14b5f29ec 100644
--- a/runtime/Python2/src/antlr4/tree/Tree.py
+++ b/runtime/Python2/src/antlr4/tree/Tree.py
@@ -108,13 +108,13 @@ class TerminalNodeImpl(TerminalNode):
return visitor.visitTerminal(self)
def getText(self):
- return self.symbol.text
+ return unicode(self.symbol.text)
def __unicode__(self):
if self.symbol.type == Token.EOF:
- return ""
+ return u""
else:
- return self.symbol.text
+ return unicode(self.symbol.text)
# Represents a token that was consumed during resynchronization
# rather than during a valid match operation. For example,
From 6d337f9cce64ba9987751dbc62eba74634d17b95 Mon Sep 17 00:00:00 2001
From: Eric Vergnaud
Date: Sat, 30 Sep 2017 17:20:35 +0800
Subject: [PATCH 26/50] seems jdk7 is no longer supported
---
.travis.yml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index d27ee56b3..d7781b286 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -110,7 +110,7 @@ matrix:
jdk: oraclejdk8
env: TARGET=java
- os: linux
- jdk: oraclejdk7
+ jdk: oraclejdk8
env: TARGET=csharp
- os: linux
jdk: oraclejdk8
@@ -131,10 +131,10 @@ matrix:
- TARGET=dotnet
- GROUP=RECURSION
- os: linux
- jdk: oraclejdk7
+ jdk: oraclejdk8
env: TARGET=python2
- os: linux
- jdk: oraclejdk7
+ jdk: oraclejdk8
env: TARGET=python3
addons:
apt:
@@ -143,7 +143,7 @@ matrix:
packages:
- python3.5
- os: linux
- jdk: oraclejdk7
+ jdk: oraclejdk8
env: TARGET=javascript
- os: linux
jdk: oraclejdk7
From 7d6189beea7c9029e15ff88884005d92042adb9c Mon Sep 17 00:00:00 2001
From: Andrew Brampton
Date: Fri, 6 Oct 2017 07:40:35 -0700
Subject: [PATCH 27/50] bramp signed the contributors.txt
---
contributors.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index e73adaadc..2338243da 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -155,4 +155,5 @@ YYYY/MM/DD, github id, Full name, email
2017/07/11, dhalperi, Daniel Halperin, daniel@halper.in
2017/07/17, vaibhavaingankar09, Vaibhav Vaingankar, vbhvvaingankar9@gmail.com
2017/07/23, venkatperi, Venkat Peri, venkatperi@gmail.com
-2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
\ No newline at end of file
+2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com
+2017/10/06, bramp, Andrew Brampton, brampton@gmail.com
From 9f90d5144292a040412e1fcf5cc328848e6f6ac8 Mon Sep 17 00:00:00 2001
From: Andrew Brampton
Date: Fri, 6 Oct 2017 08:01:17 -0700
Subject: [PATCH 28/50] Placed the CommonSetStuff code inside a scope, this is
to avoid two _lt variables in the same scope. This happens with the mysql
grammar: `build: previous declaration at mysql/mysql_parser.go:12215:6`
---
.../antlr/v4/tool/templates/codegen/Go/Go.stg | 42 ++++++++++---------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
index b1835e4e7..626f28070 100644
--- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
+++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
@@ -777,29 +777,31 @@ MatchSet(m, expr, capture) ::= ""
MatchNotSet(m, expr, capture) ::= ""
CommonSetStuff(m, expr, capture, invert) ::= <<
-p.SetState()
-
-
-var _lt = p.GetTokenStream().LT(1)
-
- = _lt}; separator="\n">
-
-
-
-
-
-
-if \<= 0 || if !() {
+{
+ p.SetState()
- var _ri = p.GetErrorHandler().RecoverInline(p)
- = _ri}; separator="\n">
-
- p.GetErrorHandler().RecoverInline(p)
+ var _lt = p.GetTokenStream().LT(1)
+
+ = _lt}; separator="\n">
+
-} else {
- p.GetErrorHandler().ReportMatch(p)
- p.Consume()
+
+
+
+
+ if \<= 0 || if !() {
+
+ var _ri = p.GetErrorHandler().RecoverInline(p)
+
+ = _ri}; separator="\n">
+
+ p.GetErrorHandler().RecoverInline(p)
+
+ } else {
+ p.GetErrorHandler().ReportMatch(p)
+ p.Consume()
+ }
}
>>
From 5df3b2bbdfc02ca460340ab18d1935a4bd3c3c39 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 12 Oct 2017 00:52:44 -0700
Subject: [PATCH 29/50] Remove ANTLRError.nullPointer from the Swift runtime.
This was copied from the API of the equivalent code in Java when
the runtime was ported to Swift. It is meaningless in Swift, and
was unused.
---
runtime/Swift/Sources/Antlr4/CharStream.swift | 1 -
runtime/Swift/Sources/Antlr4/Parser.swift | 2 --
runtime/Swift/Sources/Antlr4/Recognizer.swift | 3 ---
runtime/Swift/Sources/Antlr4/TokenStream.swift | 1 -
runtime/Swift/Sources/Antlr4/misc/BitSet.swift | 4 ----
runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift | 1 -
6 files changed, 12 deletions(-)
diff --git a/runtime/Swift/Sources/Antlr4/CharStream.swift b/runtime/Swift/Sources/Antlr4/CharStream.swift
index 81fbf84d6..38e87e109 100644
--- a/runtime/Swift/Sources/Antlr4/CharStream.swift
+++ b/runtime/Swift/Sources/Antlr4/CharStream.swift
@@ -19,7 +19,6 @@ public protocol CharStream: IntStream {
/// - parameter interval: an interval within the stream
/// - returns: the text of the specified interval
///
- /// - throws: _ANTLRError.nullPointer_ if `interval` is `null`
/// - throws: _ANTLRError.illegalArgument_ if `interval.a < 0`, or if
/// `interval.b < interval.a - 1`, or if `interval.b` lies at or
/// past the end of the stream
diff --git a/runtime/Swift/Sources/Antlr4/Parser.swift b/runtime/Swift/Sources/Antlr4/Parser.swift
index 6f7f30742..5a4c9257e 100644
--- a/runtime/Swift/Sources/Antlr4/Parser.swift
+++ b/runtime/Swift/Sources/Antlr4/Parser.swift
@@ -336,8 +336,6 @@ open class Parser: Recognizer {
///
/// - Parameter listener: the listener to add
///
- /// - Throws: _ANTLRError.nullPointer_ if listener is `null`
- ///
public func addParseListener(_ listener: ParseTreeListener) {
if _parseListeners == nil {
_parseListeners = Array()
diff --git a/runtime/Swift/Sources/Antlr4/Recognizer.swift b/runtime/Swift/Sources/Antlr4/Recognizer.swift
index 9a3acad79..6133bbeea 100644
--- a/runtime/Swift/Sources/Antlr4/Recognizer.swift
+++ b/runtime/Swift/Sources/Antlr4/Recognizer.swift
@@ -228,9 +228,6 @@ open class Recognizer {
return "\(s)"
}
- ///
- /// - Throws: ANTLRError.nullPointer if `listener` is `null`.
- ///
open func addErrorListener(_ listener: ANTLRErrorListener) {
_listeners.append(listener)
diff --git a/runtime/Swift/Sources/Antlr4/TokenStream.swift b/runtime/Swift/Sources/Antlr4/TokenStream.swift
index ef5834862..536f33b90 100644
--- a/runtime/Swift/Sources/Antlr4/TokenStream.swift
+++ b/runtime/Swift/Sources/Antlr4/TokenStream.swift
@@ -63,7 +63,6 @@ public protocol TokenStream: IntStream {
///
/// - Parameter interval: The interval of tokens within this stream to get text
/// for.
- /// - Throws: ANTLRError.nullPointer if `interval` is `null`
/// - Returns: The text of all tokens within the specified interval in this
/// stream.
///
diff --git a/runtime/Swift/Sources/Antlr4/misc/BitSet.swift b/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
index d2c9b510f..d0056ad0c 100644
--- a/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/BitSet.swift
@@ -32,10 +32,6 @@ import Foundation
/// implementation. The length of a bit set relates to logical length
/// of a bit set and is defined independently of implementation.
///
-/// Unless otherwise noted, passing a null parameter to any of the
-/// methods in a `BitSet` will result in a
-/// `ANTLRError.nullPointer`.
-///
/// A `BitSet` is not safe for multithreaded use without
/// external synchronization.
///
diff --git a/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift b/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
index 2bc300c56..c9df3022e 100644
--- a/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/exception/ANTLRError.swift
@@ -14,7 +14,6 @@
import Foundation
public enum ANTLRError: Error {
- case nullPointer(msg:String)
case unsupportedOperation(msg:String)
case indexOutOfBounds(msg:String)
case illegalState(msg:String)
From 0097838b8a170ad0875b7a7124713584fdbf9418 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 12 Oct 2017 16:49:03 -0700
Subject: [PATCH 30/50] Update AppVeyor version number to 4.7.1-SNAPSHOT.
---
appveyor.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/appveyor.yml b/appveyor.yml
index 57184557b..61ef31a41 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,4 +1,4 @@
-version: '4.6-SNAPSHOT+AppVeyor.{build}'
+version: '4.7.1-SNAPSHOT+AppVeyor.{build}'
os: Windows Server 2012
build_script:
- mvn -DskipTests install -q --batch-mode
From 242dbe095d7dea9d6688f0ac0c8f64af61483a60 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 12 Oct 2017 09:46:38 -0700
Subject: [PATCH 31/50] Add cache entries to .travis.yml.
This is recommended by the Travis docs to speed up the parts of the
tests where unpack / install has a significant cost, as opposed to the
download.
This changeset adds entries for ~/.m2 (for Maven) and
~/Library/Caches/Homebrew for (brew on macOS).
---
.travis.yml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 6fe2a4b88..1d27cd0c9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,11 @@ sudo: true
language: java
+cache:
+ directories:
+ - $HOME/.m2
+ - $HOME/Library/Caches/Homebrew
+
matrix:
include:
- os: linux
From 7bd52e5518fb2d61c897d633bdef250d5d090ad1 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 12 Oct 2017 21:41:56 -0700
Subject: [PATCH 32/50] Wrap the run-tests-$TARGET.sh with a travis_wait call.
This means that it will write a line to the log each minute while the
tests are running, up to the specified timeout. This works around the
fact that one of Maven / Surefire / JUnit are buffering our test output
until a whole test class has run.
This is a problem in particular with the TestLeftRecursion tests because
they are taking over 9 minutes on their own. After 10 minutes of silence
Travis assumes that a job is broken and kills it. We've been hitting
that timeout regularly.
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 1d27cd0c9..3a4b97563 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -158,4 +158,4 @@ before_install:
- ./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh
script:
- - cd runtime-testsuite; ../.travis/run-tests-$TARGET.sh
+ - cd runtime-testsuite; travis_wait 40 ../.travis/run-tests-$TARGET.sh
From 5f28a5b3131985a452bdc55114303eaa038d09b9 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Thu, 12 Oct 2017 21:46:20 -0700
Subject: [PATCH 33/50] Split Travis tests into three phases.
This gives a "smoke-test" phase which just runs the Java tests, to get a
quick check that compilation is working. It is followed by the
"main-test" phase that tests each target on their preferred platform
(e.g. Swift on macOS, Python on Linux) followed by "test-extended"
which runs all the remaining tests (all the other Java variants, and
any other platforms supported by each target).
This means that those tests in the later phases won't run unless the
earlier phases have passed. This should vastly improve our Travis
turnaround.
This changeset also changes the matrix so that we get some coverage across
all of openjdk7,8 and oraclejdk7,8 and moves the Go and Javascript tests
to Trusty just so that they are more up-to-date. This adds one additional
Java test run, so now we compare oraclejdk8 and openjdk8 in case of
problems in that regard.
Note that the test matrix has not been extended to cover oraclejdk9. This
currently fails for us with a build issue, so it is not included in this
changeset.
This changeset also removes the meaningless custom apt configuration in the
section for macOS .NET tests.
---
.travis.yml | 65 ++++++++++++++++++++++++++++-------------------------
1 file changed, 35 insertions(+), 30 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 3a4b97563..6cedda6f5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,11 @@ cache:
- $HOME/.m2
- $HOME/Library/Caches/Homebrew
+stages:
+ - smoke-test
+ - main-test
+ - extended-test
+
matrix:
include:
- os: linux
@@ -16,6 +21,7 @@ matrix:
- TARGET=cpp
- CXX=g++-5
- GROUP=ALL
+ stage: main-test
addons:
apt:
sources:
@@ -31,113 +37,107 @@ matrix:
env:
- TARGET=cpp
- GROUP=LEXER
- addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- - llvm-toolchain-precise-3.7
- packages:
- - g++-5
- - uuid-dev
- - clang-3.7
+ stage: extended-test
- os: osx
compiler: clang
osx_image: xcode8.1
env:
- TARGET=cpp
- GROUP=PARSER
- addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- - llvm-toolchain-precise-3.7
- packages:
- - g++-5
- - uuid-dev
- - clang-3.7
+ stage: extended-test
- 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
+ stage: extended-test
- os: osx
compiler: clang
osx_image: xcode8.1
env:
- TARGET=swift
- GROUP=LEXER
+ stage: main-test
- os: osx
compiler: clang
osx_image: xcode8.1
env:
- TARGET=swift
- GROUP=PARSER
+ stage: main-test
- os: osx
compiler: clang
osx_image: xcode8.1
env:
- TARGET=swift
- GROUP=RECURSION
+ stage: main-test
- os: linux
compiler: clang
env:
- TARGET=swift
- GROUP=ALL
+ stage: extended-test
- os: osx
osx_image: xcode8.2
env:
- TARGET=dotnet
- GROUP=LEXER
+ stage: extended-test
- os: osx
osx_image: xcode8.2
env:
- TARGET=dotnet
- GROUP=PARSER
+ stage: extended-test
- os: osx
osx_image: xcode8.2
env:
- TARGET=dotnet
- GROUP=RECURSION
+ stage: extended-test
- os: linux
jdk: openjdk7
env: TARGET=java
+ stage: extended-test
+ - os: linux
+ jdk: openjdk8
+ env: TARGET=java
+ stage: extended-test
- os: linux
jdk: oraclejdk8
env: TARGET=java
+ stage: smoke-test
- os: linux
jdk: openjdk7
env: TARGET=csharp
+ stage: extended-test
- os: linux
jdk: oraclejdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=LEXER
+ stage: main-test
- os: linux
- jdk: oraclejdk8
+ jdk: openjdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=PARSER
+ stage: main-test
- os: linux
jdk: oraclejdk8
dist: trusty
env:
- TARGET=dotnet
- GROUP=RECURSION
+ stage: main-test
- os: linux
jdk: openjdk7
env: TARGET=python2
+ stage: extended-test
- os: linux
jdk: openjdk7
env: TARGET=python3
@@ -147,12 +147,17 @@ matrix:
- deadsnakes # source required so it finds the package definition below
packages:
- python3.5
+ stage: main-test
- os: linux
- jdk: openjdk7
+ dist: trusty
+ jdk: openjdk8
env: TARGET=javascript
+ stage: main-test
- os: linux
- jdk: openjdk7
+ dist: trusty
+ jdk: openjdk8
env: TARGET=go
+ stage: main-test
before_install:
- ./.travis/before-install-$TRAVIS_OS_NAME-$TARGET.sh
From d297c9dddac4d4df3824003d540d54d3d4fa48f7 Mon Sep 17 00:00:00 2001
From: Arshinskiy Mike
Date: Sat, 14 Oct 2017 15:15:41 +0200
Subject: [PATCH 34/50] added initial tests for interval set
---
runtime/Go/antlr/interval_set_test.go | 51 +++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 runtime/Go/antlr/interval_set_test.go
diff --git a/runtime/Go/antlr/interval_set_test.go b/runtime/Go/antlr/interval_set_test.go
new file mode 100644
index 000000000..832559df3
--- /dev/null
+++ b/runtime/Go/antlr/interval_set_test.go
@@ -0,0 +1,51 @@
+package antlr
+
+import (
+ "testing"
+)
+
+func assertInterval(t *testing.T, i *Interval, l int){
+ if i.length() != l{
+ t.Errorf("For interval [%s] [%d] length is expected, [%d] is actual", i.String(), l, i.length())
+ }
+}
+
+func assertString(t *testing.T, result string, expected string){
+ if result != expected{
+ t.Errorf("expected: %s, result:%s", result, expected)
+ }
+}
+
+func TestDefaultIntervalLength(t *testing.T){
+ assertInterval(t, NewInterval(0,0), 1)
+ assertInterval(t, NewInterval(100, 100), 1)
+
+}
+
+func TestIntervalSetAbsorb(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,20)
+ s.addRange(11,19)
+ assertString(t, "10..20", s.toIndexString())
+}
+
+func TestIntervalSetOverlap(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10, 20)
+ s.addRange(15, 25)
+ assertString(t, "10..25", s.toIndexString())
+}
+
+func TestIntervalSetIndependent(t *testing.T) {
+ s := NewIntervalSet()
+ s.addRange(10, 20)
+ s.addRange(30, 40)
+ assertString(t, "{10..20, 30..40}", s.toIndexString())
+}
+
+func TestIntervalSetAdjoint(t *testing.T) {
+ s := NewIntervalSet()
+ s.addRange(10,20)
+ s.addRange(20, 30)
+ assertString(t, "10..30", s.toIndexString())
+}
\ No newline at end of file
From 5297bf2697687dc1fc3f7732d0597d8963f12b13 Mon Sep 17 00:00:00 2001
From: Arshinskiy Mike
Date: Sat, 14 Oct 2017 20:31:38 +0200
Subject: [PATCH 35/50] Modified open interval logic Added tests
---
runtime/Go/antlr/interval_set.go | 56 +++++++++++++++------------
runtime/Go/antlr/interval_set_test.go | 56 ++++++++++++++++++++++++++-
2 files changed, 86 insertions(+), 26 deletions(-)
diff --git a/runtime/Go/antlr/interval_set.go b/runtime/Go/antlr/interval_set.go
index 630b88032..9a2fedf82 100644
--- a/runtime/Go/antlr/interval_set.go
+++ b/runtime/Go/antlr/interval_set.go
@@ -14,10 +14,9 @@ type Interval struct {
Stop int
}
-/* stop is not included! */
+/* Inclusive interval*/
func NewInterval(start, stop int) *Interval {
i := new(Interval)
-
i.Start = start
i.Stop = stop
return i
@@ -29,7 +28,7 @@ func (i *Interval) Contains(item int) bool {
// Does this start completely before other? Disjoint
func (i *Interval) StartsBeforeDisjoint(other *Interval) bool{
- return i.Start ni.Start && v.Stop < ni.Stop {
- i.intervals[k] = NewInterval(ni.Start, v.Start)
- x := NewInterval(v.Stop, ni.Stop)
+ i.intervals[k] = NewInterval(ni.Start, v.Start-1)
+ x := NewInterval(v.Stop+1, ni.Stop)
// i.intervals.splice(k, 0, x)
- i.intervals = append(i.intervals[0:k], append([]*Interval{x}, i.intervals[k:]...)...)
+ i.intervals = append(i.intervals[0:k+1], append([]*Interval{x}, i.intervals[k+1:]...)...)
return
} else if v.Start <= ni.Start && v.Stop >= ni.Stop {
// i.intervals.splice(k, 1)
i.intervals = append(i.intervals[0:k], i.intervals[k+1:]...)
- k = k - 1 // need another pass
+ k = k - 1
+ continue
} else if v.Start < ni.Stop {
- i.intervals[k] = NewInterval(ni.Start, v.Start)
+ i.intervals[k] = NewInterval(ni.Start, v.Start-1)
} else if v.Stop < ni.Stop {
- i.intervals[k] = NewInterval(v.Stop, ni.Stop)
+ i.intervals[k] = NewInterval(v.Stop+1, ni.Stop)
}
- k++
}
}
}
@@ -247,18 +245,18 @@ func (i *IntervalSet) removeOne(v int) {
// intervals i ordered
if v < ki.Start {
return
- } else if v == ki.Start && v == ki.Stop-1 {
+ } else if v == ki.Start && v == ki.Stop {
// i.intervals.splice(k, 1)
i.intervals = append(i.intervals[0:k], i.intervals[k+1:]...)
return
} else if v == ki.Start {
i.intervals[k] = NewInterval(ki.Start+1, ki.Stop)
return
- } else if v == ki.Stop-1 {
+ } else if v == ki.Stop {
i.intervals[k] = NewInterval(ki.Start, ki.Stop-1)
return
- } else if v < ki.Stop-1 {
- x := NewInterval(ki.Start, v)
+ } else if v < ki.Stop {
+ x := NewInterval(ki.Start, v-1)
ki.Start = v + 1
// i.intervals.splice(k, 0, x)
i.intervals = append(i.intervals[0:k], append([]*Interval{x}, i.intervals[k:]...)...)
@@ -297,9 +295,14 @@ func (i *IntervalSet) toCharString() string {
names = append(names, ("'" + string(v.Start) + "'"))
}
} else {
- names = append(names, "'"+string(v.Start)+"'..'"+string(v.Stop-1)+"'")
+ names = append(names, "'"+string(v.Start)+"'..'"+string(v.Stop)+"'")
}
}
+
+ if len(names) == 0{
+ return "{}"
+ }
+
if len(names) > 1 {
return "{" + strings.Join(names, ", ") + "}"
}
@@ -319,9 +322,14 @@ func (i *IntervalSet) toIndexString() string {
names = append(names, strconv.Itoa(v.Start))
}
} else {
- names = append(names, strconv.Itoa(v.Start)+".."+strconv.Itoa(v.Stop-1))
+ names = append(names, strconv.Itoa(v.Start)+".."+strconv.Itoa(v.Stop))
}
}
+
+ if len(names) == 0{
+ return "{}"
+ }
+
if len(names) > 1 {
return "{" + strings.Join(names, ", ") + "}"
}
diff --git a/runtime/Go/antlr/interval_set_test.go b/runtime/Go/antlr/interval_set_test.go
index 832559df3..1b15b7842 100644
--- a/runtime/Go/antlr/interval_set_test.go
+++ b/runtime/Go/antlr/interval_set_test.go
@@ -10,7 +10,7 @@ func assertInterval(t *testing.T, i *Interval, l int){
}
}
-func assertString(t *testing.T, result string, expected string){
+func assertString(t *testing.T, expected string, result string){
if result != expected{
t.Errorf("expected: %s, result:%s", result, expected)
}
@@ -19,7 +19,7 @@ func assertString(t *testing.T, result string, expected string){
func TestDefaultIntervalLength(t *testing.T){
assertInterval(t, NewInterval(0,0), 1)
assertInterval(t, NewInterval(100, 100), 1)
-
+ assertInterval(t, NewInterval(200,100),0)
}
func TestIntervalSetAbsorb(t *testing.T){
@@ -48,4 +48,56 @@ func TestIntervalSetAdjoint(t *testing.T) {
s.addRange(10,20)
s.addRange(20, 30)
assertString(t, "10..30", s.toIndexString())
+}
+
+func TestIntervalSetBridge(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,20)
+ s.addRange(30,40)
+ s.addRange(20,30)
+ assertString(t, "10..40", s.toIndexString())
+}
+
+func TestIntervalSetBreak(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,40)
+ s.removeOne(25)
+ assertString(t, "{10..24, 26..40}", s.toIndexString())
+}
+
+func TestIntervalSetRemoveStart(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,40)
+ s.removeOne(10)
+ assertString(t, "11..40", s.toIndexString())
+}
+
+func TestIntervalSetRemoveEnd(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,40)
+ s.removeOne(40)
+ assertString(t, "10..39", s.toIndexString())
+}
+
+func TestIntervalSetRemoveSinglePoint(t *testing.T){
+ s := NewIntervalSet()
+ s.addOne(10)
+ s.addRange(100,200)
+ s.removeOne(10)
+ assertString(t, "100..200", s.toIndexString())
+}
+
+func TestIntervalSetRemoveRangeMid(t *testing.T) {
+ s := NewIntervalSet()
+ s.addRange(10,30)
+ s.removeRange(NewInterval(15,20))
+ assertString(t, "{10..14, 21..30}", s.toIndexString())
+}
+
+func TestIntervalSetRemoveEverything(t *testing.T){
+ s := NewIntervalSet()
+ s.addRange(10,20)
+ s.addRange(30,40)
+ s.removeRange(NewInterval(5, 50))
+ assertString(t, "{}", s.toIndexString())
}
\ No newline at end of file
From 51fc50dbcbdd43ab002694c9fed13d7b3f2e7139 Mon Sep 17 00:00:00 2001
From: simkimsia
Date: Sun, 15 Oct 2017 16:14:50 +0800
Subject: [PATCH 36/50] Update getting-started.md
change all mentions of 4.5.3 to 4.7 since that's what the quickstart on http://www.antlr.org/ homepage is already showing
---
doc/getting-started.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/doc/getting-started.md b/doc/getting-started.md
index 62bc69711..30acdb65a 100644
--- a/doc/getting-started.md
+++ b/doc/getting-started.md
@@ -6,7 +6,7 @@ Hi and welcome to the version 4 release of ANTLR! It's named after the fearless
ANTLR is really two things: a tool that translates your grammar to a parser/lexer in Java (or other target language) and the runtime needed by the generated parsers/lexers. Even if you are using the ANTLR Intellij plug-in or ANTLRWorks to run the ANTLR tool, the generated code will still need the runtime library.
-The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.5.3-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
+The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.7-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).
If you are going to integrate ANTLR into your existing build system using mvn, ant, or want to get ANTLR into your IDE such as eclipse or intellij, see Integrating ANTLR into Development Systems.
@@ -16,7 +16,7 @@ If you are going to integrate ANTLR into your existing build system using mvn, a
1. Download
```
$ cd /usr/local/lib
-$ curl -O http://www.antlr.org/download/antlr-4.5.3-complete.jar
+$ curl -O http://www.antlr.org/download/antlr-4.7-complete.jar
```
Or just download in browser from website:
[http://www.antlr.org/download.html](http://www.antlr.org/download.html)
@@ -45,7 +45,7 @@ Save to your directory for 3rd party Java libraries, say `C:\Javalib`
* Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable
* Temporarily, at command line:
```
-SET CLASSPATH=.;C:\Javalib\antlr-4.5.3-complete.jar;%CLASSPATH%
+SET CLASSPATH=.;C:\Javalib\antlr-4.7-complete.jar;%CLASSPATH%
```
3. Create short convenient commands for the ANTLR Tool, and TestRig, using batch files or doskey commands:
* Batch files (in directory in system PATH) antlr4.bat and grun.bat
@@ -67,7 +67,7 @@ Either launch org.antlr.v4.Tool directly:
```
$ java org.antlr.v4.Tool
-ANTLR Parser Generator Version 4.5.3
+ANTLR Parser Generator Version 4.7
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
@@ -76,8 +76,8 @@ ANTLR Parser Generator Version 4.5.3
or use -jar option on java:
```
-$ java -jar /usr/local/lib/antlr-4.5.3-complete.jar
-ANTLR Parser Generator Version 4.5.3
+$ java -jar /usr/local/lib/antlr-4.7-complete.jar
+ANTLR Parser Generator Version 4.7
-o ___ specify output directory where all output is generated
-lib ___ specify location of .tokens files
...
From 3def33fdd59b2a5e5bc6d52bc25472910d835146 Mon Sep 17 00:00:00 2001
From: simkimsia
Date: Sun, 15 Oct 2017 16:17:23 +0800
Subject: [PATCH 37/50] Update contributors.txt
---
contributors.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contributors.txt b/contributors.txt
index 8e79d3b68..2311a15bd 100644
--- a/contributors.txt
+++ b/contributors.txt
@@ -163,4 +163,5 @@ YYYY/MM/DD, github id, Full name, email
2017/08/20, tiagomazzutti, Tiago Mazzutti, tiagomzt@gmail.com
2017/09/09, brauliobz, Bráulio Bezerra, brauliobezerra@gmail.com
2017/09/11, sachinjain024, Sachin Jain, sachinjain024@gmail.com
-2017/10/06, bramp, Andrew Brampton, brampton@gmail.com
\ No newline at end of file
+2017/10/06, bramp, Andrew Brampton, brampton@gmail.com
+2017/10/15, simkimsia, Sim Kim Sia, kimcity@gmail.com
From 7df0c2f47886c78de66bf7931e5ba87888a4d6c4 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Fri, 20 Oct 2017 00:26:35 -0700
Subject: [PATCH 38/50] Split the C++ tests into three groups.
Running these as a single test still intermittently times out after 40
minutes, even with the other recent csets.
---
.travis.yml | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 6cedda6f5..131a71a7b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,7 +20,41 @@ matrix:
env:
- TARGET=cpp
- CXX=g++-5
- - GROUP=ALL
+ - GROUP=LEXER
+ stage: main-test
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-precise-3.7
+ packages:
+ - g++-5
+ - uuid-dev
+ - clang-3.7
+ - os: linux
+ compiler: clang
+ jdk: openjdk7
+ env:
+ - TARGET=cpp
+ - CXX=g++-5
+ - GROUP=PARSER
+ stage: main-test
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ - llvm-toolchain-precise-3.7
+ packages:
+ - g++-5
+ - uuid-dev
+ - clang-3.7
+ - os: linux
+ compiler: clang
+ jdk: openjdk7
+ env:
+ - TARGET=cpp
+ - CXX=g++-5
+ - GROUP=RECURSION
stage: main-test
addons:
apt:
From 4d628174df4e8c287961e87eb0e9fbaa56dfd507 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Wed, 27 Sep 2017 11:17:39 -0700
Subject: [PATCH 39/50] Update Swift runtime documentation.
We now use boot.py and Swift Package Manager to generate the .xcodeproj
rather than having those committed in the source repo.
---
doc/swift-target.md | 107 +++++++++++++++++++++++++++-----------------
1 file changed, 65 insertions(+), 42 deletions(-)
diff --git a/doc/swift-target.md b/doc/swift-target.md
index 09dd17de3..57a8f8022 100644
--- a/doc/swift-target.md
+++ b/doc/swift-target.md
@@ -23,60 +23,83 @@ $ antlr4 -Dlanguage=Swift MyGrammar.g4
For a full list of antlr4 tool options, please visit the
[tool documentation page](tool-options.md).
+
## Build your Swift project with ANTLR runtime
-The following instructions are assuming Xcode as the IDE:
+The following instructions assume Xcode as the IDE.
-* __Add parser/lexer to project__. Make sure the parsers/lexers
+Note that even if you are otherwise using ANTLR from a binary distribution,
+you should compile the ANTLR Swift runtime from source, because the Swift
+language does not yet have a stable ABI.
+
+ANTLR uses Swift Package Manager to generate Xcode project files. Note that
+Swift Package Manager does not currently support iOS, watchOS, or tvOS, so
+if you wish to use those platforms, you will need to alter the project build
+settings manually as appropriate.
+
+### Download source code for ANTLR
+
+```
+git clone https://github.com/antlr/antlr4
+```
+
+### Generate Xcode project for ANTLR runtime
+
+The `boot.py` script includes a wrapper around `swift package
+generate-xcodeproj`. Use this to generate `Antlr4.xcodeproj` for the ANTLR
+Swift runtime.
+
+```
+cd antlr4/runtime/Swift
+python boot.py --gen-xcodeproj
+```
+
+### Import ANTLR Swift runtime into your project
+
+Open your own project in Xcode.
+
+Open Finder in the `runtime/Swift` directory:
+
+```
+# From antlr4/runtime/Swift
+open .
+```
+
+Drag `Antlr4.xcodeproj` into your project.
+
+After this is done, your Xcode project navigator will be something like the
+screenshot below. In this example, your own project is "Smalltalk", and you
+will be able to see `Antlr4.xcodeproj` shown as a contained project.
+
+
+
+### Edit the build settings if necessary
+
+Swift Package Manager currently does not support iOS, watchOS, or tvOS. If
+you wish to build for those platforms, you will need to alter the project
+build settings manually.
+
+### Add generated parser and lexer to project
+
+Make sure the parsers/lexers
generated in __step 2__ are added to the project. To do this, you can
drag the generated files from Finder to the Xcode IDE. Remember to
check __Copy items if needed__ to make sure the files are actually
moved into the project folder instead of symbolic links (see the
screenshot below). After moving you will be able to see your files in
-the project navigator. But when you open one of the files, you will
-see Xcode complaining the module "Antlr4" could not be found at the
-import statement. This is expected, since we still need the ANTLR
-Swift runtime for those missing symbols.
+the project navigator. Make sure that the Target Membership settings
+are correct for your project.
-* __Download ANTLR runtime__. Due to unstable ABI of Swift language,
-there will not be a single "library" for the Swift ANTLR runtime for
-now. To get Swift ANTLR runtime, clone the ANTLR repository. Open it
-in finder. From the root directory of the repo, go to runtime/Swift
-folder. You will see the Xcode project manifest file:
-__Antlr4.xcodeproj__.
+### Add the ANTLR Swift runtime as a dependency
-* __Import ANTLR Swift runtime into project__. Drag Antlr4.xcodeproj
-into your project, after this is done, your Xcode project navigator
-will be something like the screenshot below. In this case, your own
-project is "Smalltalk", and you will be able to see the
-Antlr4.xcodeproj shown as a contained project. The error message will
-still be there, that's because we still need to tell Xcode how to find
-the runtime.
+Select your own project in Xcode and go to the Build Phases settings panel.
+Add the ANTLR runtime under __Target Dependencies__ and __Link Binary With
+Libraries__.
-
+
-* __Build ANTLR runtime__. By expanding the "Products" folder in the
-inner project (Antlr4.xcodeproj), you will see two Antlr4.framework
-files. ".framework" file is the swift version of ".jar", ".a" as in
-JAVA, C/C++ Initially those two files should be red, that's because
-they are not built. To build, click the "target selection" button
-right next to your Xcode run button. And in the drop down select the
-target you want to build. And you will see the two Antlr4.framework
-files are for iOS and OSX, as shown below. After target selection,
-press "CMD+B", and Xcode will build the framework for you. Then you
-will see one of the frameworks become black.
+### Build your project
-
-
-* __Add dependencies__. Simply adding ANTLR Swift runtime and build
-the artifact is not enough. You still need to specify
-dependencies. Click your own project (Smalltalk), and you will see
-project setting page. Go to "Build Phase", and inside it make sure
-your ANTLR Swift runtime framework is added to both "__Target
-Dependencies__" and "__Link Binary With Libraries__" sections, as
-shown below. After correctly added dependencies, the error message for
-importing library will be gone.
-
-
\ No newline at end of file
+The runtime and generated grammar should now build correctly.
From 8ba2c0ba4f70eeb98f995716e569696231699e68 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Wed, 27 Sep 2017 11:33:13 -0700
Subject: [PATCH 40/50] Add entries to .gitignore for the files that are
generated by Swift Package Manager.
---
runtime/Swift/.gitignore | 3 +++
1 file changed, 3 insertions(+)
diff --git a/runtime/Swift/.gitignore b/runtime/Swift/.gitignore
index c54511205..e4a84b226 100644
--- a/runtime/Swift/.gitignore
+++ b/runtime/Swift/.gitignore
@@ -1 +1,4 @@
+.build/
+Antlr4.xcodeproj/
+Tests/Antlr4Tests/gen/
xcuserdata/
From 4bafc74e6c99316c381eb5fb13e9cfbc9907c78e Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Wed, 27 Sep 2017 12:07:49 -0700
Subject: [PATCH 41/50] Remove unused functions from StringExtension.
Some of these are subject to change for Swift 4, but since they are unused
we should remove them anyway.
---
.../misc/extension/StringExtension.swift | 145 ------------------
.../pattern/ParseTreePatternMatcher.swift | 2 -
2 files changed, 147 deletions(-)
diff --git a/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift b/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
index 49a39592c..c50ba7a1e 100644
--- a/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
+++ b/runtime/Swift/Sources/Antlr4/misc/extension/StringExtension.swift
@@ -11,14 +11,6 @@ import Foundation
extension String {
- func split(_ separator: String) -> [String] {
- return self.components(separatedBy: separator)
- }
-
- func containsIgnoreCase(_ find: String) -> Bool {
- return self.lowercased().range(of: find.lowercased()) != nil
- }
-
var length: Int {
return self.characters.count
}
@@ -60,32 +52,6 @@ extension String {
return index
}
- func substringAfter(_ string: String) -> String {
- if let range = self.range(of: string) {
- let intIndex: Int = self.characters.distance(from: self.startIndex, to: range.upperBound)
- return self.substring(from: self.characters.index(self.startIndex, offsetBy: intIndex))
- }
- return self
-
- }
-
- var lowercaseFirstChar: String {
- var result = self
- if self.length > 0 {
- let startIndex = self.startIndex
- result.replaceSubrange(startIndex ... startIndex, with: String(self[startIndex]).lowercased())
- }
- return result
- }
- func substringWithRange(_ range: Range) -> String {
-
-
- let start = self.characters.index(self.startIndex, offsetBy: range.lowerBound)
-
- let end = self.characters.index(self.startIndex, offsetBy: range.upperBound)
- return self.substring(with: start ..< end)
- }
-
subscript(integerIndex: Int) -> Character {
let index = characters.index(startIndex, offsetBy: integerIndex)
return self[index]
@@ -97,116 +63,5 @@ extension String {
let range = start ..< end
return self[range]
}
-
- func charAt(_ index: Int) -> Character {
- return self[self.characters.index(self.startIndex, offsetBy: index)]
- }
-
}
-// Mapping from XML/HTML character entity reference to character
-// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
-private let characterEntities: [String:Character] = [
- // XML predefined entities:
- """: "\"",
- "&": "&",
- "'": "'",
- "<": "<",
- ">": ">",
-
- // HTML character entity references:
- " ": "\u{00a0}",
- // ...
- "♦": "♦",
-]
-
-extension String {
-
- ///
- /// Returns a new string made by replacing in the `String`
- /// all HTML character entity references with the corresponding
- /// character.
- ///
- var stringByDecodingHTMLEntities: String {
-
-
- // Convert the number in the string to the corresponding
- // Unicode character, e.g.
- // decodeNumeric("64", 10) --> "@"
- // decodeNumeric("20ac", 16) --> "€"
- func decodeNumeric(_ string: String, base: Int32) -> Character? {
- let code = UInt32(strtoul(string, nil, base))
- return Character(UnicodeScalar(code)!)
- }
-
- // Decode the HTML character entity to the corresponding
- // Unicode character, return `nil` for invalid input.
- // decode("@") --> "@"
- // decode("€") --> "€"
- // decode("<") --> "<"
- // decode("&foo;") --> nil
- func decode(_ entity: String) -> Character? {
-
- if entity.hasPrefix("") || entity.hasPrefix("") {
- return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 3)), base: 16)
- } else if entity.hasPrefix("") {
- return decodeNumeric(entity.substring(from: entity.characters.index(entity.startIndex, offsetBy: 2)), base: 10)
- } else {
- return characterEntities[entity]
- }
- }
-
- var result = ""
- var position = startIndex
-
- // Find the next '&' and copy the characters preceding it to `result`:
- while let ampRange = self.range(of: "&", range: position ..< endIndex) {
- result.append(self[position ..< ampRange.lowerBound])
- position = ampRange.lowerBound
-
- // Find the next ';' and copy everything from '&' to ';' into `entity`
- if let semiRange = self.range(of: ";", range: position ..< endIndex) {
- let entity = self[position ..< semiRange.upperBound]
- position = semiRange.upperBound
-
- if let decoded = decode(entity) {
- // Replace by decoded character:
- result.append(decoded)
- } else {
- // Invalid entity, copy verbatim:
- result.append(entity)
- }
- } else {
- // No matching ';'.
- break
- }
- }
- // Copy remaining characters to `result`:
- result.append(self[position ..< endIndex])
- return result
- }
-}
-
-extension String {
-
- static let htmlEscapedDictionary = [
- "&": "&",
- """: "\"",
- "'": "'",
- "9": "'",
- "": "'",
- "": "'",
- ">": ">",
- "<": "<"
- ]
-
- public var escapedHtmlString: String {
- var newString = "\(self)"
-
- for (key, value) in String.htmlEscapedDictionary {
- newString = newString.replacingOccurrences(of: value, with: key)
- }
- return newString
- }
-
-}
diff --git a/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift b/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
index c5f731a13..ecc9ae1d0 100644
--- a/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
+++ b/runtime/Swift/Sources/Antlr4/tree/pattern/ParseTreePatternMatcher.swift
@@ -320,7 +320,6 @@ public class ParseTreePatternMatcher {
// add special rule token or conjure up new token from name
let firstStr = String(tagChunk.getTag()[0])
if firstStr.lowercased() != firstStr {
- //if ( Character.isUpperCase(tagChunk.getTag().charAt(0)) ) {
let ttype: Int = parser.getTokenType(tagChunk.getTag())
if ttype == CommonToken.INVALID_TYPE {
throw ANTLRError.illegalArgument(msg: "Unknown token " + tagChunk.getTag() + " in pattern: " + pattern)
@@ -329,7 +328,6 @@ public class ParseTreePatternMatcher {
tokens.append(t)
} else {
if firstStr.uppercased() != firstStr {
- // if ( Character.isLowerCase(tagChunk.getTag().charAt(0)) ) {
let ruleIndex: Int = parser.getRuleIndex(tagChunk.getTag())
if ruleIndex == -1 {
throw ANTLRError.illegalArgument(msg: "Unknown rule " + tagChunk.getTag() + " in pattern: " + pattern)
From 365d4f40bbf7c57dbe31de8b806f52dddfdb635c Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Wed, 27 Sep 2017 12:26:53 -0700
Subject: [PATCH 42/50] Refactor to avoid forced casts.
---
.../Sources/Antlr4/atn/SemanticContext.swift | 20 ++++++++-----------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift b/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
index 9e0c777b0..413d517be 100644
--- a/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/SemanticContext.swift
@@ -187,15 +187,13 @@ public class SemanticContext: Hashable, CustomStringConvertible {
public init(_ a: SemanticContext, _ b: SemanticContext) {
var operands: Set = Set()
- if a is AND {
- operands.formUnion((a as! AND).opnds)
- //operands.addAll(Arrays.asList((a as AND).opnds));
+ if let aAnd = a as? AND {
+ operands.formUnion(aAnd.opnds)
} else {
operands.insert(a)
}
- if b is AND {
- operands.formUnion((b as! AND).opnds)
- //operands.addAll(Arrays.asList((b as AND).opnds));
+ if let bAnd = b as? AND {
+ operands.formUnion(bAnd.opnds)
} else {
operands.insert(b)
}
@@ -305,15 +303,13 @@ public class SemanticContext: Hashable, CustomStringConvertible {
public init(_ a: SemanticContext, _ b: SemanticContext) {
var operands: Set = Set()
- if a is OR {
- operands.formUnion((a as! OR).opnds)
- // operands.addAll(Arrays.asList((a as OR).opnds));
+ if let aOr = a as? OR {
+ operands.formUnion(aOr.opnds)
} else {
operands.insert(a)
}
- if b is OR {
- operands.formUnion((b as! OR).opnds)
- //operands.addAll(Arrays.asList((b as OR).opnds));
+ if let bOr = b as? OR {
+ operands.formUnion(bOr.opnds)
} else {
operands.insert(b)
}
From 8a292c0f4f8f7a4705330d0015762383dab00744 Mon Sep 17 00:00:00 2001
From: Ewan Mellor
Date: Wed, 27 Sep 2017 11:54:15 -0700
Subject: [PATCH 43/50] Migrate the Swift runtime to Swift 4.
Remove a number of generic type constraints, since these can now
be inferred by the compiler.
Match the syntax change when passing a tuple into a function (adding
an extra set of parens).
Change filterPrecedencePredicates to avoid a now-illegal cast.
Match the renames truncatingBitPattern -> truncatingIfNeeded,
multiplyWithOverflow -> multipliedReportingOverflow, etc. In
some cases the multiplyWithOverflow calls are replaced by
overflowing operators (e.g. &*) instead.
---
.../Sources/Antlr4/ANTLRErrorListener.swift | 12 ++--
.../Sources/Antlr4/BaseErrorListener.swift | 12 ++--
.../Sources/Antlr4/ConsoleErrorListener.swift | 12 ++--
runtime/Swift/Sources/Antlr4/Lexer.swift | 2 +-
.../Sources/Antlr4/ProxyErrorListener.swift | 14 ++---
.../Swift/Sources/Antlr4/RuleContext.swift | 4 +-
.../Swift/Sources/Antlr4/atn/ATNConfig.swift | 2 +-
.../Sources/Antlr4/atn/ATNConfigSet.swift | 5 +-
.../Sources/Antlr4/atn/ATNDeserializer.swift | 2 +-
.../Antlr4/atn/PredictionContext.swift | 6 +-
.../Sources/Antlr4/atn/SemanticContext.swift | 56 ++++++++-----------
.../Sources/Antlr4/misc/ArrayWrapper.swift | 2 +-
.../Swift/Sources/Antlr4/misc/BitSet.swift | 4 +-
.../Swift/Sources/Antlr4/misc/HashMap.swift | 4 +-
.../Sources/Antlr4/misc/MurmurHash.swift | 16 +++---
.../misc/extension/StringExtension.swift | 2 +-
.../Tests/Antlr4Tests/VisitorTests.swift | 8 +--
17 files changed, 76 insertions(+), 87 deletions(-)
diff --git a/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift b/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
index c83ee58a3..56d1987f3 100644
--- a/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ANTLRErrorListener.swift
@@ -39,12 +39,12 @@ public protocol ANTLRErrorListener: class {
/// the parser was able to recover in line without exiting the
/// surrounding rule.
///
- func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
)
///
diff --git a/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift b/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
index 75d3cad8c..9a9805b96 100644
--- a/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/BaseErrorListener.swift
@@ -17,12 +17,12 @@ open class BaseErrorListener: ANTLRErrorListener {
public init() {
}
- open func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ open func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
) {
}
diff --git a/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift b/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
index 22a76c5f4..de6584c30 100644
--- a/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ConsoleErrorListener.swift
@@ -25,12 +25,12 @@ public class ConsoleErrorListener: BaseErrorListener {
/// line __line__:__charPositionInLine__ __msg__
///
///
- override public func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?
+ override public func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?
) {
if Parser.ConsoleError {
errPrint("line \(line):\(charPositionInLine) \(msg)")
diff --git a/runtime/Swift/Sources/Antlr4/Lexer.swift b/runtime/Swift/Sources/Antlr4/Lexer.swift
index a05150db4..a324d321b 100644
--- a/runtime/Swift/Sources/Antlr4/Lexer.swift
+++ b/runtime/Swift/Sources/Antlr4/Lexer.swift
@@ -405,7 +405,7 @@ open class Lexer: Recognizer
}
}
- open func notifyListeners(_ e: LexerNoViableAltException, recognizer: Recognizer) {
+ open func notifyListeners(_ e: LexerNoViableAltException, recognizer: Recognizer) {
let text: String = _input!.getText(Interval.of(_tokenStartCharIndex, _input!.index()))
let msg: String = "token recognition error at: '\(getErrorDisplay(text))'"
diff --git a/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift b/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
index 481064ff5..5d1d7646c 100644
--- a/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
+++ b/runtime/Swift/Sources/Antlr4/ProxyErrorListener.swift
@@ -20,13 +20,13 @@ public class ProxyErrorListener: ANTLRErrorListener {
self.delegates = delegates
}
- public func syntaxError(_ recognizer: Recognizer,
- _ offendingSymbol: AnyObject?,
- _ line: Int,
- _ charPositionInLine: Int,
- _ msg: String,
- _ e: AnyObject?)
- {
+ public func syntaxError(_ recognizer: Recognizer,
+ _ offendingSymbol: AnyObject?,
+ _ line: Int,
+ _ charPositionInLine: Int,
+ _ msg: String,
+ _ e: AnyObject?)
+ {
for listener: ANTLRErrorListener in delegates {
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e)
}
diff --git a/runtime/Swift/Sources/Antlr4/RuleContext.swift b/runtime/Swift/Sources/Antlr4/RuleContext.swift
index 18dafd571..a05b43257 100644
--- a/runtime/Swift/Sources/Antlr4/RuleContext.swift
+++ b/runtime/Swift/Sources/Antlr4/RuleContext.swift
@@ -233,7 +233,7 @@ open class RuleContext: RuleNode {
return description
}
- public final func toString(_ recog: Recognizer) -> String {
+ public final func toString(_ recog: Recognizer) -> String {
return toString(recog, ParserRuleContext.EMPTY)
}
@@ -242,7 +242,7 @@ open class RuleContext: RuleNode {
}
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
- open func toString(_ recog: Recognizer?, _ stop: RuleContext) -> String {
+ open func toString(_ recog: Recognizer?, _ stop: RuleContext) -> String {
let ruleNames: [String]? = recog != nil ? recog!.getRuleNames() : nil
let ruleNamesList: Array? = ruleNames ?? nil
return toString(ruleNamesList, stop)
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
index 1054ef342..75bff30e4 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
@@ -167,7 +167,7 @@ public class ATNConfig: Hashable, CustomStringConvertible {
//return "MyClass \(string)"
return toString(nil, true)
}
- public func toString(_ recog: Recognizer?, _ showAlt: Bool) -> String {
+ public func toString(_ recog: Recognizer?, _ showAlt: Bool) -> String {
let buf: StringBuilder = StringBuilder()
buf.append("(")
buf.append(state)
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
index 5cac3bffb..803d9c369 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
@@ -238,12 +238,9 @@ public class ATNConfigSet: Hashable, CustomStringConvertible {
private var configsHashValue: Int {
var hashCode = 1
for item in configs {
- hashCode = Int.multiplyWithOverflow(3, hashCode).0
- hashCode = Int.addWithOverflow(hashCode, item.hashValue).0
-
+ hashCode = hashCode &* 3 &+ item.hashValue
}
return hashCode
-
}
public final var count: Int {
diff --git a/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift b/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
index 5d3d25015..7bc3f63fc 100644
--- a/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
@@ -175,7 +175,7 @@ public class ATNDeserializer {
if let s = s as? BlockStartState {
let endStateNumber: Int = toInt(data[p])
p += 1
- endStateNumbers.append(s, endStateNumber)
+ endStateNumbers.append((s, endStateNumber))
}
}
atn.addState(s)
diff --git a/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift b/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
index c603b06c6..783a1ab5b 100644
--- a/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
+++ b/runtime/Swift/Sources/Antlr4/atn/PredictionContext.swift
@@ -712,17 +712,17 @@ public class PredictionContext: Hashable, CustomStringConvertible {
}
}
- public func toString(_ recog: Recognizer) -> String {
+ public func toString(_ recog: Recognizer) -> String {
return NSStringFromClass(PredictionContext.self)
// return toString(recog, ParserRuleContext.EMPTY);
}
- public func toStrings(_ recognizer: Recognizer, _ currentState: Int) -> [String] {
+ public func toStrings