From 8629d46bbe004f039133655f075d39e8b19d06c2 Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Mon, 1 Jan 2018 14:13:11 +0800 Subject: [PATCH 01/33] fixes #2188 --- .../v4/codegen/target/Python2Target.java | 31 ++++++++--------- .../v4/codegen/target/Python3Target.java | 33 ++++++++++--------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/tool/src/org/antlr/v4/codegen/target/Python2Target.java b/tool/src/org/antlr/v4/codegen/target/Python2Target.java index 3fc6a3541..28dfaae60 100644 --- a/tool/src/org/antlr/v4/codegen/target/Python2Target.java +++ b/tool/src/org/antlr/v4/codegen/target/Python2Target.java @@ -24,27 +24,28 @@ import java.util.Set; */ public class Python2Target extends Target { protected static final String[] python2Keywords = { - "abs", "all", "any", "apply", "as", - "bin", "bool", "buffer", "bytearray", - "callable", "chr", "classmethod", "coerce", "compile", "complex", - "del", "delattr", "dict", "dir", "divmod", - "enumerate", "eval", "execfile", - "file", "filter", "float", "format", "frozenset", - "getattr", "globals", + "abs", "all", "and", "any", "apply", "as", "assert", + "bin", "bool", "break", "buffer", "bytearray", + "callable", "chr", "class", "classmethod", "coerce", "compile", "complex", "continue", + "def", "del", "delattr", "dict", "dir", "divmod", + "elif", "else", "enumerate", "eval", "except", "exec", "execfile", + "file", "filter", "finally", "float", "for", "format", "from", "frozenset", + "getattr", "global", "globals", "hasattr", "hash", "help", "hex", - "id", "input", "int", "intern", "isinstance", "issubclass", "iter", - "len", "list", "locals", - "map", "max", "min", "next", + "id", "if", "import", "in", "input", "int", "intern", "is", "isinstance", "issubclass", "iter", + "lambda", "len", "list", "locals", + "map", "max", "min", "next", "not", "memoryview", - "object", "oct", "open", "ord", - "pow", "print", "property", - "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", + "object", "oct", "open", "or", "ord", + "pass", "pow", "print", "property", + "raise", "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", - "tuple", "type", + "try", "tuple", "type", "unichr", "unicode", "vars", - "with", + "while", "with", "xrange", + "yield", "zip", "__import__", "True", "False", "None" diff --git a/tool/src/org/antlr/v4/codegen/target/Python3Target.java b/tool/src/org/antlr/v4/codegen/target/Python3Target.java index 388269a73..1dffc4e42 100644 --- a/tool/src/org/antlr/v4/codegen/target/Python3Target.java +++ b/tool/src/org/antlr/v4/codegen/target/Python3Target.java @@ -24,26 +24,27 @@ import java.util.Set; */ public class Python3Target extends Target { protected static final String[] python3Keywords = { - "abs", "all", "any", "apply", "as", - "bin", "bool", "buffer", "bytearray", - "callable", "chr", "classmethod", "coerce", "compile", "complex", - "del", "delattr", "dict", "dir", "divmod", - "enumerate", "eval", "execfile", - "file", "filter", "float", "format", "frozenset", - "getattr", "globals", + "abs", "all", "and", "any", "apply", "as", "assert", + "bin", "bool", "break", "buffer", "bytearray", + "callable", "chr", "class", "classmethod", "coerce", "compile", "complex", "continue", + "def", "del", "delattr", "dict", "dir", "divmod", + "elif", "else", "enumerate", "eval", "execfile", "except", + "file", "filter", "finally", "float", "for", "format", "from", "frozenset", + "getattr", "global", "globals", "hasattr", "hash", "help", "hex", - "id", "input", "int", "intern", "isinstance", "issubclass", "iter", - "len", "list", "locals", - "map", "max", "min", "next", - "memoryview", - "object", "oct", "open", "ord", - "pow", "print", "property", - "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", + "id", "if", "import", "in", "input", "int", "intern", "is", "isinstance", "issubclass", "iter", + "lambda", "len", "list", "locals", + "map", "max", "min", "memoryview", + "next", "nonlocal", "not", + "object", "oct", "open", "or", "ord", + "pass", "pow", "print", "property", + "raise", "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", - "tuple", "type", + "try", "tuple", "type", "unichr", "unicode", "vars", - "with", + "with", "while", + "yield", "zip", "__import__", "True", "False", "None" From bfd5e5d8188740175b21c893372d9f3cb860edba Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Mon, 1 Jan 2018 14:33:38 +0800 Subject: [PATCH 02/33] =?UTF-8?q?more=20python=202=20to=20main=20test=20st?= =?UTF-8?q?age=20since=20it=E2=80=99s=20a=20standalone=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2897de583..1b00e7eb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -176,7 +176,7 @@ matrix: - os: linux jdk: openjdk7 env: TARGET=python2 - stage: extended-test + stage: main-test - os: linux jdk: openjdk7 env: TARGET=python3 From b594b24b15b87c6da6fafe42a49f708dd6b74a9e Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Mon, 1 Jan 2018 14:43:29 +0800 Subject: [PATCH 03/33] csharp target builds faster so use it for main test --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1b00e7eb3..5cd9f7eb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -151,28 +151,28 @@ matrix: - os: linux jdk: openjdk7 env: TARGET=csharp - stage: extended-test + stage: main-test - os: linux jdk: oraclejdk8 dist: trusty env: - TARGET=dotnet - GROUP=LEXER - stage: main-test + stage: extended-test - os: linux jdk: openjdk8 dist: trusty env: - TARGET=dotnet - GROUP=PARSER - stage: main-test + stage: extended-test - os: linux jdk: oraclejdk8 dist: trusty env: - TARGET=dotnet - GROUP=RECURSION - stage: main-test + stage: extended-test - os: linux jdk: openjdk7 env: TARGET=python2 From dd3af945fda571db6025a0b1ad334c24eb1c4a1b Mon Sep 17 00:00:00 2001 From: Robert Brignull Date: Wed, 3 Jan 2018 12:49:52 +0000 Subject: [PATCH 04/33] Only visit is ctx.children is non-null --- runtime/JavaScript/src/antlr4/tree/Tree.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/JavaScript/src/antlr4/tree/Tree.js b/runtime/JavaScript/src/antlr4/tree/Tree.js index 468d7a8a7..1cfda9a92 100644 --- a/runtime/JavaScript/src/antlr4/tree/Tree.js +++ b/runtime/JavaScript/src/antlr4/tree/Tree.js @@ -73,7 +73,9 @@ ParseTreeVisitor.prototype.visit = function(ctx) { }; ParseTreeVisitor.prototype.visitChildren = function(ctx) { - return this.visit(ctx.children); + if (ctx.children) { + return this.visit(ctx.children); + } } ParseTreeVisitor.prototype.visitTerminal = function(node) { From 87725e65c951099249c42e512061fc9bca465167 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 Jan 2018 11:26:31 +0000 Subject: [PATCH 05/33] Add an explicit return statement --- runtime/JavaScript/src/antlr4/tree/Tree.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/JavaScript/src/antlr4/tree/Tree.js b/runtime/JavaScript/src/antlr4/tree/Tree.js index 1cfda9a92..515b122b5 100644 --- a/runtime/JavaScript/src/antlr4/tree/Tree.js +++ b/runtime/JavaScript/src/antlr4/tree/Tree.js @@ -75,6 +75,8 @@ ParseTreeVisitor.prototype.visit = function(ctx) { ParseTreeVisitor.prototype.visitChildren = function(ctx) { if (ctx.children) { return this.visit(ctx.children); + } else { + return null; } } From dadd466cbd8840356994976a4364b5e0733cb04f Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Sat, 6 Jan 2018 12:42:05 +0100 Subject: [PATCH 06/33] fix indentation in javascript target examples --- doc/javascript-target.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/javascript-target.md b/doc/javascript-target.md index 3473e95b5..5aa01f83b 100644 --- a/doc/javascript-target.md +++ b/doc/javascript-target.md @@ -128,30 +128,30 @@ Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value". The a ``` In order to provide custom behavior, you might want to create the following class: - + ```javascript - KeyPrinter = function() { - MyGrammarListener.call(this); // inherit default listener - return this; - }; - -// inherit default listener +var KeyPrinter = function() { + MyGrammarListener.call(this); // inherit default listener + return this; +}; + +// continue inheriting default listener KeyPrinter.prototype = Object.create(MyGrammarListener.prototype); KeyPrinter.prototype.constructor = KeyPrinter; - + // override default listener behavior - KeyPrinter.prototype.exitKey = function(ctx) { - console.log("Oh, a key!"); - }; +KeyPrinter.prototype.exitKey = function(ctx) { + console.log("Oh, a key!"); +}; ``` In order to execute this listener, you would simply add the following lines to the above code: - + ```javascript - ... - tree = parser.StartRule() - only repeated here for reference - var printer = new KeyPrinter(); - antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree); + ... + tree = parser.StartRule() // only repeated here for reference +var printer = new KeyPrinter(); +antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree); ``` ## What about TypeScript? From cbf65226c72a898bb41d905110b4dd3c1364ae77 Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Sat, 6 Jan 2018 12:45:49 +0100 Subject: [PATCH 07/33] sign contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index ffd3b9b2e..fb57de7cf 100644 --- a/contributors.txt +++ b/contributors.txt @@ -179,3 +179,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/01, SebastianLng, Sebastian Lang, sebastian.lang@outlook.com 2017/12/03, oranoran, Oran Epelbaum, oran / epelbaum me 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com +2018/01/06, kasbah, Kaspar Emanuel, kaspar@monostable.co.uk From 040ca0cee315e275178c1968c54546ef60da0223 Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Sat, 6 Jan 2018 13:54:26 +0100 Subject: [PATCH 08/33] add require statements to javascript target example --- doc/javascript-target.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/javascript-target.md b/doc/javascript-target.md index 5aa01f83b..450f244aa 100644 --- a/doc/javascript-target.md +++ b/doc/javascript-target.md @@ -95,11 +95,16 @@ Let's suppose that your grammar is named, as above, "MyGrammar". Let's suppose t Now a fully functioning script might look like the following: ```javascript + var antlr4 = require('antlr4'); + var MyGrammarLexer = require('./MyGrammarLexer').MyGrammarLexer; + var MyGrammarParser = require('./MyGrammarParser').MyGrammarParser; + var MyGrammarListener = require('./MyGrammarListener').MyGrammarListener; + var input = "your text to parse here" var chars = new antlr4.InputStream(input); - var lexer = new MyGrammarLexer.MyGrammarLexer(chars); + var lexer = new MyGrammarLexer(chars); var tokens = new antlr4.CommonTokenStream(lexer); - var parser = new MyGrammarParser.MyGrammarParser(tokens); + var parser = new MyGrammarParser(tokens); parser.buildParseTrees = true; var tree = parser.MyStartRule(); ``` From 2c8542b5149cbd0264fe1e4829097921b4b7d12b Mon Sep 17 00:00:00 2001 From: EternalPhane Date: Mon, 29 Jan 2018 20:48:07 +0800 Subject: [PATCH 09/33] let Any::Derived::clone depend on whether T is copy-constructible --- runtime/Cpp/runtime/src/support/Any.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index 3d8845c70..a14fd379a 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -41,14 +41,14 @@ struct ANTLR4CPP_PUBLIC Any } template - Any(U&& value) : _ptr(new Derived>(std::forward(value))) { + Any(U&& value) : _ptr(new Derived, std::is_copy_constructible>::value>(std::forward(value))) { } template bool is() const { typedef StorageType T; - auto derived = dynamic_cast *>(_ptr); + auto derived = dynamic_cast> *>(_ptr); return derived != nullptr; } @@ -57,7 +57,7 @@ struct ANTLR4CPP_PUBLIC Any StorageType& as() { typedef StorageType T; - auto derived = dynamic_cast*>(_ptr); + auto derived = dynamic_cast>*>(_ptr); if (!derived) throw std::bad_cast(); @@ -104,8 +104,11 @@ private: virtual Base* clone() const = 0; }; + template + struct Derived; + template - struct Derived : Base + struct Derived : Base { template Derived(U&& value_) : value(std::forward(value_)) { } @@ -113,7 +116,21 @@ private: T value; Base* clone() const { - return new Derived(value); + return new Derived>(value); + } + + }; + + template + struct Derived : Base + { + template Derived(U&& value_) : value(std::forward(value_)) { + } + + T value; + + Base* clone() const { + return nullptr; } }; From 940e174b5e0825b39bcda4a370f2b658278a0306 Mon Sep 17 00:00:00 2001 From: EternalPhane Date: Mon, 29 Jan 2018 21:38:15 +0800 Subject: [PATCH 10/33] fix typos --- runtime/Cpp/runtime/src/support/Any.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index a14fd379a..d6b4990b8 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -48,7 +48,7 @@ struct ANTLR4CPP_PUBLIC Any bool is() const { typedef StorageType T; - auto derived = dynamic_cast> *>(_ptr); + auto derived = dynamic_cast::value> *>(_ptr); return derived != nullptr; } @@ -57,7 +57,7 @@ struct ANTLR4CPP_PUBLIC Any StorageType& as() { typedef StorageType T; - auto derived = dynamic_cast>*>(_ptr); + auto derived = dynamic_cast::value>*>(_ptr); if (!derived) throw std::bad_cast(); @@ -116,7 +116,7 @@ private: T value; Base* clone() const { - return new Derived>(value); + return new Derived::value>(value); } }; From d027f00aca19962b2de98a428a9a1b8b98707721 Mon Sep 17 00:00:00 2001 From: EternalPhane Date: Tue, 30 Jan 2018 00:17:41 +0800 Subject: [PATCH 11/33] add patch to std::vector --- runtime/Cpp/runtime/src/support/Any.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index d6b4990b8..0e72b5718 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -41,14 +41,14 @@ struct ANTLR4CPP_PUBLIC Any } template - Any(U&& value) : _ptr(new Derived, std::is_copy_constructible>::value>(std::forward(value))) { + Any(U&& value) : _ptr(new Derived, Cloneable>::value>(std::forward(value))) { } template bool is() const { typedef StorageType T; - auto derived = dynamic_cast::value> *>(_ptr); + auto derived = dynamic_cast::value> *>(_ptr); return derived != nullptr; } @@ -57,7 +57,7 @@ struct ANTLR4CPP_PUBLIC Any StorageType& as() { typedef StorageType T; - auto derived = dynamic_cast::value>*>(_ptr); + auto derived = dynamic_cast::value>*>(_ptr); if (!derived) throw std::bad_cast(); @@ -99,6 +99,11 @@ struct ANTLR4CPP_PUBLIC Any } private: + template + struct Cloneable : std::is_copy_constructible {}; + template + struct Cloneable> : std::is_copy_constructible {}; + struct Base { virtual ~Base(); virtual Base* clone() const = 0; @@ -116,7 +121,7 @@ private: T value; Base* clone() const { - return new Derived::value>(value); + return new Derived::value>(value); } }; From 6b8e9824a670fe81601805e6ebce24446ca3aacf Mon Sep 17 00:00:00 2001 From: EternalPhane Date: Sat, 3 Feb 2018 17:12:09 +0800 Subject: [PATCH 12/33] fix #2211 --- contributors.txt | 1 + runtime/Cpp/runtime/src/support/Any.cpp | 3 --- runtime/Cpp/runtime/src/support/Any.h | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/contributors.txt b/contributors.txt index ffd3b9b2e..e2124b25d 100644 --- a/contributors.txt +++ b/contributors.txt @@ -179,3 +179,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/01, SebastianLng, Sebastian Lang, sebastian.lang@outlook.com 2017/12/03, oranoran, Oran Epelbaum, oran / epelbaum me 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com +2018/01/29, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com diff --git a/runtime/Cpp/runtime/src/support/Any.cpp b/runtime/Cpp/runtime/src/support/Any.cpp index 3dd1a94bf..b324cc15d 100644 --- a/runtime/Cpp/runtime/src/support/Any.cpp +++ b/runtime/Cpp/runtime/src/support/Any.cpp @@ -11,6 +11,3 @@ Any::~Any() { delete _ptr; } - -Any::Base::~Base() { -} diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index 0e72b5718..aa08ac0cc 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -105,7 +105,7 @@ private: struct Cloneable> : std::is_copy_constructible {}; struct Base { - virtual ~Base(); + virtual ~Base() {}; virtual Base* clone() const = 0; }; From c0cfcdf23c44d8a0d6a0a2ef6839082eee2ba048 Mon Sep 17 00:00:00 2001 From: Raz Friman Date: Thu, 8 Feb 2018 14:02:59 +1100 Subject: [PATCH 13/33] Update README.md Make the NuGet package name more visible and add a link to the official package --- runtime/CSharp/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/CSharp/README.md b/runtime/CSharp/README.md index 265f2b4ee..3985a298b 100644 --- a/runtime/CSharp/README.md +++ b/runtime/CSharp/README.md @@ -51,7 +51,13 @@ This is just a quick start. The tool has many useful options to control generati The Antlr 4 standard runtime for C# is now available from NuGet. We trust that you know how to do add NuGet references to your project :-). -The package id is Antlr4.Runtime.Standard. We do not support other packages. +The package id is [Antlr4.Runtime.Standard](https://www.nuget.org/packages/Antlr4.Runtime.Standard/). We do not support other packages. + +Use the GUI or the following command in the Package Manager Console: + +``` +Install-Package Antlr4.Runtime.Standard +``` ### Step 6: You're done! From acc2d037351cc7fa5aaf9f3bdf8a5dc0a101c21d Mon Sep 17 00:00:00 2001 From: Raz Friman Date: Thu, 8 Feb 2018 14:03:57 +1100 Subject: [PATCH 14/33] Update contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index d18168b04..298d9583c 100644 --- a/contributors.txt +++ b/contributors.txt @@ -180,3 +180,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/03, oranoran, Oran Epelbaum, oran / epelbaum me 2017/12/20, kbsletten, Kyle Sletten, kbsletten@gmail.com 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com +2018/02/08, razfriman, Raz Friman, raz@razfriman.com From 54297cd329c4e784ae4ce28e0d5598926693571c Mon Sep 17 00:00:00 2001 From: Zongyuan Zuo Date: Mon, 26 Feb 2018 19:51:21 +0800 Subject: [PATCH 15/33] rewrite + add patch to all stl containers --- runtime/Cpp/runtime/src/support/Any.h | 34 +++++++++++---------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index aa08ac0cc..ebd359d1d 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -41,14 +41,14 @@ struct ANTLR4CPP_PUBLIC Any } template - Any(U&& value) : _ptr(new Derived, Cloneable>::value>(std::forward(value))) { + Any(U&& value) : _ptr(new Derived>(std::forward(value))) { } template bool is() const { typedef StorageType T; - auto derived = dynamic_cast::value> *>(_ptr); + auto derived = dynamic_cast *>(_ptr); return derived != nullptr; } @@ -57,7 +57,7 @@ struct ANTLR4CPP_PUBLIC Any StorageType& as() { typedef StorageType T; - auto derived = dynamic_cast::value>*>(_ptr); + auto derived = dynamic_cast*>(_ptr); if (!derived) throw std::bad_cast(); @@ -99,21 +99,18 @@ struct ANTLR4CPP_PUBLIC Any } private: - template + template struct Cloneable : std::is_copy_constructible {}; - template - struct Cloneable> : std::is_copy_constructible {}; + template class C> + struct Cloneable, typename std::enable_if>::value && !std::is_nothrow_copy_constructible>::value>::type> : std::is_copy_constructible {}; struct Base { virtual ~Base() {}; virtual Base* clone() const = 0; }; - template - struct Derived; - template - struct Derived : Base + struct Derived : Base { template Derived(U&& value_) : value(std::forward(value_)) { } @@ -121,20 +118,17 @@ private: T value; Base* clone() const { - return new Derived::value>(value); + return clone<>(); } - }; - - template - struct Derived : Base - { - template Derived(U&& value_) : value(std::forward(value_)) { + private: + template + auto clone() const -> typename std::enable_if::value, Base*>::type { + return new Derived(value); } - T value; - - Base* clone() const { + template + auto clone() const -> typename std::enable_if::value, Base*>::type { return nullptr; } From b4a43a886d17a01acee9e6e8c496bbe7bf2a2a1e Mon Sep 17 00:00:00 2001 From: Zongyuan Zuo Date: Mon, 26 Feb 2018 19:55:51 +0800 Subject: [PATCH 16/33] fix typos --- runtime/Cpp/runtime/src/support/Any.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index ebd359d1d..510f827dc 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -110,7 +110,7 @@ private: }; template - struct Derived : Base + struct Derived : Base { template Derived(U&& value_) : value(std::forward(value_)) { } From 8fb3b42ded91adebd8cf4ce0339b122f1d297c37 Mon Sep 17 00:00:00 2001 From: EternalPhane Date: Mon, 26 Mar 2018 20:31:51 +0800 Subject: [PATCH 17/33] rewrite with std::is_nothrow_copy_constructible --- runtime/Cpp/runtime/src/support/Any.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index 510f827dc..817490a3a 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -99,11 +99,6 @@ struct ANTLR4CPP_PUBLIC Any } private: - template - struct Cloneable : std::is_copy_constructible {}; - template class C> - struct Cloneable, typename std::enable_if>::value && !std::is_nothrow_copy_constructible>::value>::type> : std::is_copy_constructible {}; - struct Base { virtual ~Base() {}; virtual Base* clone() const = 0; @@ -122,13 +117,13 @@ private: } private: - template - auto clone() const -> typename std::enable_if::value, Base*>::type { + template::value, int>::type = 0> + Base* clone() const { return new Derived(value); } - template - auto clone() const -> typename std::enable_if::value, Base*>::type { + template::value, int>::type = 0> + Base* clone() const { return nullptr; } From d076768dfff14d2c24686c6c192b82b76e92677e Mon Sep 17 00:00:00 2001 From: john Date: Tue, 15 May 2018 13:17:23 +0200 Subject: [PATCH 18/33] fixed spelling mistake in js docs --- doc/javascript-target.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/javascript-target.md b/doc/javascript-target.md index 3473e95b5..bfc985c06 100644 --- a/doc/javascript-target.md +++ b/doc/javascript-target.md @@ -62,7 +62,7 @@ The steps to create your parsing code are the following: You are now ready to bundle your parsing code as follows: - following webpack specs, create a webpack.config file - in the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" } - - from the cmd line, nag-vigate to the directory containing webpack.config and type: webpack + - from the cmd line, navigate to the directory containing webpack.config and type: webpack This will produce a single js file containing all your parsing code. Easy to include in your web pages! From cb70d10a78289cccb516117d475bc4738c0c6076 Mon Sep 17 00:00:00 2001 From: john Date: Tue, 15 May 2018 13:21:07 +0200 Subject: [PATCH 19/33] added name to contibuters.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index 6e1d2ffdd..a55a31707 100644 --- a/contributors.txt +++ b/contributors.txt @@ -181,3 +181,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/20, kbsletten, Kyle Sletten, kbsletten@gmail.com 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com +2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com From 58ef6bbc96e6ba67c7692e2a2a9139c895d3c858 Mon Sep 17 00:00:00 2001 From: sinopsysHK Date: Wed, 16 May 2018 23:37:21 +0800 Subject: [PATCH 20/33] Enable running debug mode of ParserATNSimulator This is to have appropriate logs during debug and avoid crashing in some occasions when startIndex=stopIndex range(startIndex, stopIndex) is equivalent to an array of values from startIndex to stopIndex-1 thus when startIndex=stopIndex range(startIndex, stopIndex+1) = [startIndex] which is not exactly an interval and would break getText that is expecting an interval as a Tuple. --- runtime/Python3/src/antlr4/atn/ParserATNSimulator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py b/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py index d15629252..a3b2c7c14 100644 --- a/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py +++ b/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py @@ -1608,7 +1608,7 @@ class ParserATNSimulator(ATNSimulator): def reportAttemptingFullContext(self, dfa:DFA, conflictingAlts:set, configs:ATNConfigSet, startIndex:int, stopIndex:int): if ParserATNSimulator.debug or ParserATNSimulator.retry_debug: - interval = range(startIndex, stopIndex + 1) + interval = (startIndex, stopIndex + 1) print("reportAttemptingFullContext decision=" + str(dfa.decision) + ":" + str(configs) + ", input=" + self.parser.getTokenStream().getText(interval)) if self.parser is not None: @@ -1616,7 +1616,7 @@ class ParserATNSimulator(ATNSimulator): def reportContextSensitivity(self, dfa:DFA, prediction:int, configs:ATNConfigSet, startIndex:int, stopIndex:int): if ParserATNSimulator.debug or ParserATNSimulator.retry_debug: - interval = range(startIndex, stopIndex + 1) + interval = (startIndex, stopIndex + 1) print("reportContextSensitivity decision=" + str(dfa.decision) + ":" + str(configs) + ", input=" + self.parser.getTokenStream().getText(interval)) if self.parser is not None: @@ -1642,7 +1642,7 @@ class ParserATNSimulator(ATNSimulator): # } # i++; # } - interval = range(startIndex, stopIndex + 1) + interval = (startIndex, stopIndex + 1) print("reportAmbiguity " + str(ambigAlts) + ":" + str(configs) + ", input=" + self.parser.getTokenStream().getText(interval)) if self.parser is not None: From 83273c5e7ce92def5594e651e309ad904e5d667b Mon Sep 17 00:00:00 2001 From: sinopsysHK Date: Thu, 17 May 2018 00:07:15 +0800 Subject: [PATCH 21/33] Signed contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index a55a31707..8c0175f81 100644 --- a/contributors.txt +++ b/contributors.txt @@ -182,3 +182,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com +2018/17/05, sinopsysHK, Eric Bardes, sinofwd@gmail.com From 2971f3732335a37af3c12e9842156515a2857c31 Mon Sep 17 00:00:00 2001 From: Stephen Vance Date: Wed, 23 May 2018 09:01:07 -0400 Subject: [PATCH 22/33] Update icu4j version to address CVEs --- tool/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/pom.xml b/tool/pom.xml index 78da0b47c..338cdd856 100644 --- a/tool/pom.xml +++ b/tool/pom.xml @@ -44,7 +44,7 @@ com.ibm.icu icu4j - 58.2 + 61.1 From e05a6a6f53c8339581523850c089f2030da68179 Mon Sep 17 00:00:00 2001 From: Stephen Vance Date: Wed, 23 May 2018 09:13:37 -0400 Subject: [PATCH 23/33] Sign contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index a55a31707..d74e3284f 100644 --- a/contributors.txt +++ b/contributors.txt @@ -182,3 +182,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com +2018/23/05, srvance, Stephen Vance, steve@vance.com From 2a6a107b499617426b056afbe5ebe7325f6408f5 Mon Sep 17 00:00:00 2001 From: Daniel Halperin Date: Wed, 30 May 2018 20:56:17 -0700 Subject: [PATCH 24/33] Java.stg: use static functions instead of inline arrays --- .../v4/tool/templates/codegen/Java/Java.stg | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) 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 492c56644..1683a18f8 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 @@ -236,9 +236,12 @@ public class extends { public static final int = }; separator=", ", wrap, anchor>; - public static final String[] ruleNames = { - "}; separator=", ", wrap, anchor> - }; + private static String[] makeRuleNames() { + return new String[] { + "}; separator=", ", wrap, anchor> + }; + } + public static final String[] ruleNames = makeRuleNames(); @@ -275,12 +278,18 @@ case : >> vocabulary(literalNames, symbolicNames) ::= << -private static final String[] _LITERAL_NAMES = { - }; null="null", separator=", ", wrap, anchor> -}; -private static final String[] _SYMBOLIC_NAMES = { - }; null="null", separator=", ", wrap, anchor> -}; +private static String[] makeLiteralNames() { + return new String[] { + }; null="null", separator=", ", wrap, anchor> + }; +} +private static final String[] _LITERAL_NAMES = makeLiteralNames(); +private static String[] makeSymbolicNames() { + return new String[] { + }; null="null", separator=", ", wrap, anchor> + }; +} +private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); /** @@ -914,9 +923,12 @@ public class extends { "}; separator=", ", wrap, anchor> }; - public static final String[] ruleNames = { - "}; separator=", ", wrap, anchor> - }; + private static String[] makeRuleNames() { + return new String[] { + "}; separator=", ", wrap, anchor> + }; + } + public static final String[] ruleNames = makeRuleNames(); From d134b6a12d7b2141350fdfac75bd4fafd06c47dc Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Sun, 3 Jun 2018 11:21:37 +0800 Subject: [PATCH 25/33] Fixes #2301 --- .../descriptors/ParserExecDescriptors.java | 35 +++++++++++++++++++ .../Python3/src/antlr4/atn/SemanticContext.py | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java index 297d2989e..ca6e393dd 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java @@ -854,4 +854,39 @@ public class ParserExecDescriptors { @CommentHasStringValue public String grammar; } + + /** + * This is a regression test for antlr/antlr4#2301. + */ + public static class OrderingPredicates extends BaseParserTestDescriptor { + public String input = "POINT AT X"; + public String output = null; + public String errors = null; + public String startRule = "expr"; + public String grammarName = "Issue2301"; + + /** + grammar Issue2301; + + SPACES: [ \t\r\n]+ -> skip; + + AT: 'AT'; + X : 'X'; + Y : 'Y'; + + ID: [A-Z]+; + + constant + : 'DUMMY' + ; + + expr + : ID constant? + | expr AT X + | expr AT Y + ; + */ + @CommentHasStringValue + public String grammar; + } } diff --git a/runtime/Python3/src/antlr4/atn/SemanticContext.py b/runtime/Python3/src/antlr4/atn/SemanticContext.py index 548d7eaba..d4593195e 100644 --- a/runtime/Python3/src/antlr4/atn/SemanticContext.py +++ b/runtime/Python3/src/antlr4/atn/SemanticContext.py @@ -135,8 +135,8 @@ class PrecedencePredicate(SemanticContext): else: return None - def __cmp__(self, other): - return self.precedence - other.precedence + def __lt__(self, other): + return self.precedence < other.precedence def __hash__(self): return 31 From 7ca6d525e6beec44c8751cd1b325a0027b6b0c5f Mon Sep 17 00:00:00 2001 From: Ale Contenti Date: Fri, 15 Jun 2018 00:02:07 -0700 Subject: [PATCH 26/33] Updated csharp-target doc Added a 'using' statement for namespace using Antlr4.Runtime.Tree, so that IParseTree can be found without fully qualified name. Fixed typo in property Parser.BuildParseTree --- contributors.txt | 1 + doc/csharp-target.md | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/contributors.txt b/contributors.txt index a55a31707..14f74cc6a 100644 --- a/contributors.txt +++ b/contributors.txt @@ -182,3 +182,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com +2018/06/14, alecont, Alessandro Contenti, alecontenti@hotmail.com \ No newline at end of file diff --git a/doc/csharp-target.md b/doc/csharp-target.md index 9158b0211..40be51840 100644 --- a/doc/csharp-target.md +++ b/doc/csharp-target.md @@ -21,7 +21,7 @@ You will find full instructions on the [Git repo page for ANTLR C# runtime](http Let's suppose that your grammar is named `MyGrammar`. The tool will generate for you the following files: -* MyGrammarLexer.cs +* MyGrammarLexer.cs * MyGrammarParser.cs * MyGrammarListener.cs (if you have not activated the -no-listener option) * MyGrammarBaseListener.cs (if you have not activated the -no-listener option) @@ -32,6 +32,7 @@ Now a fully functioning code might look like the following for start rule `Start ``` using Antlr4.Runtime; +using Antlr4.Runtime.Tree; public void MyParseMethod() { String input = "your text to parse here"; @@ -39,7 +40,7 @@ public void MyParseMethod() { ITokenSource lexer = new MyGrammarLexer(stream); ITokenStream tokens = new CommonTokenStream(lexer); MyGrammarParser parser = new MyGrammarParser(tokens); - parser.buildParseTrees = true; + parser.BuildParseTree = true; IParseTree tree = parser.StartRule(); } ``` From ee92d8caf122a1c7438784750666b2426efd5ab9 Mon Sep 17 00:00:00 2001 From: James Goppert Date: Tue, 3 Jul 2018 20:21:55 -0400 Subject: [PATCH 27/33] Add support for cpack. --- runtime/Cpp/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/Cpp/CMakeLists.txt b/runtime/Cpp/CMakeLists.txt index f4940c0c5..963250601 100644 --- a/runtime/Cpp/CMakeLists.txt +++ b/runtime/Cpp/CMakeLists.txt @@ -136,3 +136,7 @@ endif() install(FILES README.md VERSION DESTINATION "share/doc/libantlr4") + +set(CPACK_PACKAGE_CONTACT "antlr-discussion@googlegroups.com") +set(CPACK_PACKAGE_VERSION ${ANTLR_VERSION}) +include(CPack) From f09f0ffbc2c70fc6e3ff0a12a13977b7110d5a6a Mon Sep 17 00:00:00 2001 From: James Goppert Date: Tue, 3 Jul 2018 20:24:13 -0400 Subject: [PATCH 28/33] Sign contributors. --- contributors.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contributors.txt b/contributors.txt index 81aec6bde..06f6044b9 100644 --- a/contributors.txt +++ b/contributors.txt @@ -182,4 +182,5 @@ YYYY/MM/DD, github id, Full name, email 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com -2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com \ No newline at end of file +2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com +2018/07/03, jgoppert, James Goppert, james.goppert@gmail.com From 7c4806bb0bf417dbadc16c2fbb26b156356a08c8 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Thu, 12 Jul 2018 09:46:38 -0700 Subject: [PATCH 29/33] Update releasing-antlr.md --- doc/releasing-antlr.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/releasing-antlr.md b/doc/releasing-antlr.md index e3ed7915b..239a57476 100644 --- a/doc/releasing-antlr.md +++ b/doc/releasing-antlr.md @@ -172,6 +172,7 @@ alias java='/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/ alias javac='/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/javac' alias javadoc='/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/javadoc' alias jar='/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin/jar' +export JAVA_HOME=`/usr/libexec/java_home -v 1.7` ``` You should see 0x33 in generated .class files after 0xCAFEBABE; see [Java SE 7 = 51 (0x33 hex)](https://en.wikipedia.org/wiki/Java_class_file): From ad603efe9147652b5aa41c92f6b5fd12a94954f8 Mon Sep 17 00:00:00 2001 From: Maksim Novikov Date: Fri, 27 Jul 2018 20:31:21 +0200 Subject: [PATCH 30/33] Add StdninStream for python3 runtime. Closes: #2271 --- contributors.txt | 3 ++- runtime/Python3/src/antlr4/StdinStream.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 runtime/Python3/src/antlr4/StdinStream.py diff --git a/contributors.txt b/contributors.txt index 93ef0005a..5aa803e4e 100644 --- a/contributors.txt +++ b/contributors.txt @@ -187,4 +187,5 @@ YYYY/MM/DD, github id, Full name, email 2018/05/17, sinopsysHK, Eric Bardes, sinofwd@gmail.com 2018/05/23, srvance, Stephen Vance, steve@vance.com 2018/06/14, alecont, Alessandro Contenti, alecontenti@hotmail.com -2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com \ No newline at end of file +2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com +2018/07/27, Maksim Novikov, mnovikov.work@gmail.com diff --git a/runtime/Python3/src/antlr4/StdinStream.py b/runtime/Python3/src/antlr4/StdinStream.py new file mode 100644 index 000000000..f044fc4d7 --- /dev/null +++ b/runtime/Python3/src/antlr4/StdinStream.py @@ -0,0 +1,11 @@ +import codecs +import sys + +from antlr4.InputStream import InputStream + + +class StdinStream(InputStream): + def __init__(self, encoding:str='ascii', errors:str='strict') -> None: + bytes = sys.stdin.buffer.read() + data = codecs.decode(bytes, encoding, errors) + super().__init__(data) From 411960b1878f12912f5c330086a79eb07345a3d8 Mon Sep 17 00:00:00 2001 From: ENDOH takanao Date: Fri, 3 Aug 2018 16:11:37 +0700 Subject: [PATCH 31/33] remove double dots in the filename some tools are can not handling files that have double dots in the filename --- contributors.txt | 1 + ...5.vcxproj..filters => antlr4-cpp-demo-vs2015.vcxproj.filters} | 0 2 files changed, 1 insertion(+) rename runtime/Cpp/demo/Windows/antlr4-cpp-demo/{antlr4-cpp-demo-vs2015.vcxproj..filters => antlr4-cpp-demo-vs2015.vcxproj.filters} (100%) diff --git a/contributors.txt b/contributors.txt index 5aa803e4e..b9b18604d 100644 --- a/contributors.txt +++ b/contributors.txt @@ -189,3 +189,4 @@ YYYY/MM/DD, github id, Full name, email 2018/06/14, alecont, Alessandro Contenti, alecontenti@hotmail.com 2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com 2018/07/27, Maksim Novikov, mnovikov.work@gmail.com +2018/08/03, ENDOH takanao, djmchl@gmail.com diff --git a/runtime/Cpp/demo/Windows/antlr4-cpp-demo/antlr4-cpp-demo-vs2015.vcxproj..filters b/runtime/Cpp/demo/Windows/antlr4-cpp-demo/antlr4-cpp-demo-vs2015.vcxproj.filters similarity index 100% rename from runtime/Cpp/demo/Windows/antlr4-cpp-demo/antlr4-cpp-demo-vs2015.vcxproj..filters rename to runtime/Cpp/demo/Windows/antlr4-cpp-demo/antlr4-cpp-demo-vs2015.vcxproj.filters From b748545707d580cac345e728a05f7b54450862ca Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Mon, 8 Oct 2018 13:59:57 +0200 Subject: [PATCH 32/33] [Python3] Fix the import of parser superclasses. Until now, the generated Python3 code imported the custom parser superclasses relatively. However, this only worked in Python3 if the module was inside a package, since relative imports rely on __name__ to determine the current module's position in the package hierarchy. In case of a standalone script, this was always __main__ and hence these relative imports failed. The patch handles this issue them same way as it is handled by listener imports. --- .../org/antlr/v4/tool/templates/codegen/Python3/Python3.stg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 34e525b85..3f2acec78 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 @@ -119,7 +119,10 @@ Parser(parser, funcs, atn, sempredFuncs, superClass) ::= << Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= << -from . import +if __name__ is not None and "." in __name__: + from . import +else: + from import From 301ac82631e4c78bad34c2ea45a1a2b7632cff7e Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Mon, 8 Oct 2018 14:18:56 +0200 Subject: [PATCH 33/33] [Python] Add missing lexer super class imports. Although, both lexer and parser grammars can have a custom super class set, but only the generated parser sources were prepared to import these classes. The patch makes custom lexer ancestor classes imported, too. --- .../org/antlr/v4/tool/templates/codegen/Python2/Python2.stg | 4 ++++ .../org/antlr/v4/tool/templates/codegen/Python3/Python3.stg | 6 ++++++ 2 files changed, 10 insertions(+) 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 570f1659f..dcaa4463d 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 @@ -749,6 +749,10 @@ import sys >> Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= << + +from . import + + 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 34e525b85..adf396648 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 @@ -756,7 +756,13 @@ import sys >> Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= << + +if __name__ is not None and "." in __name__: + from . import +else: + from import + class (Lexer):