From 53f2a67b9d00cf3eaa7a55e23da5707011ec1f8c Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Sun, 10 Jul 2016 15:54:23 +0200 Subject: [PATCH 01/15] Add an iterative version of the ParseTreeWalker --- .../tree/IterativeParseTreeWalker.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java b/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java new file mode 100644 index 000000000..8a230511e --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java @@ -0,0 +1,151 @@ +/* + * [The "BSD license"] + * Copyright (c) 2012 Terence Parr + * Copyright (c) 2012 Sam Harwell + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.antlr.v4.runtime.tree; + +/** + * An iterative (read: non-recursive) pre-order and post-order tree walker that + * doesn't use the thread stack but it's own heap-based stack using linked data + * structures. Makes it possible to process deeply nested parse trees. + */ +public class IterativeParseTreeWalker extends ParseTreeWalker { + public static final ParseTreeWalker DEFAULT = new IterativeParseTreeWalker(); + + @Override + public void walk(final ParseTreeListener listener, final ParseTree t) { + for (WalkerNode currentNode = createNode(null, t, 0); currentNode != null;) { + currentNode.enter(listener); // Pre order visit + + // Move down to first child + WalkerNode nextNode = currentNode.getFirstChild(); + if (nextNode != null) { + currentNode = nextNode; + continue; + } + + // No child nodes, so walk tree + while (currentNode != null) { + currentNode.exit(listener); // Post order visit + + // Move to sibling if possible + nextNode = currentNode.getNextSibling(); + if (nextNode != null) { + currentNode = nextNode; + break; + } + + // Move up + currentNode = currentNode.getParentNode(); + } + } + } + + protected WalkerNode createNode(final WalkerNode parent, final ParseTree self, final int pos) { + if (self instanceof ErrorNode) { + return new ErrorWalkerNode(parent, (ErrorNode) self, pos); + } else if (self instanceof TerminalNode) { + return new TerminalWalkerNode(parent, (TerminalNode) self, pos); + } else { + return new RuleWalkerNode(parent, (RuleNode) self, pos); + } + } + + protected abstract class WalkerNode { + private final WalkerNode parent; + protected final N self; + private final int pos; + + protected WalkerNode(final WalkerNode parent, final N self, final int pos) { + this.parent = parent; + this.self = self; + this.pos = pos; + } + + public WalkerNode getFirstChild() { + return self.getChildCount() > 0 ? createChildNode(0) : null; + } + + public WalkerNode getNextSibling() { + return parent != null && parent.self.getChildCount() > pos + 1 ? parent.createChildNode(pos + 1) : null; + } + + public WalkerNode getParentNode() { + return parent; + } + + public abstract void enter(ParseTreeListener listener); + + public void exit(final ParseTreeListener listener) { + // defaults to do nothing + } + + protected WalkerNode createChildNode(final int pos) { + return createNode(this, self.getChild(pos), pos); + } + } + + protected class RuleWalkerNode extends WalkerNode { + public RuleWalkerNode(final WalkerNode parent, final RuleNode self, final int pos) { + super(parent, self, pos); + } + + @Override + public void enter(final ParseTreeListener listener) { + enterRule(listener, self); + } + + @Override + public void exit(final ParseTreeListener listener) { + exitRule(listener, self); + } + } + + protected class ErrorWalkerNode extends WalkerNode { + public ErrorWalkerNode(final WalkerNode parent, final ErrorNode self, final int pos) { + super(parent, self, pos); + } + + @Override + public void enter(final ParseTreeListener listener) { + listener.visitErrorNode(self); + } + } + + protected class TerminalWalkerNode extends WalkerNode { + public TerminalWalkerNode(final WalkerNode parent, final TerminalNode self, final int pos) { + super(parent, self, pos); + } + + @Override + public void enter(final ParseTreeListener listener) { + listener.visitTerminal(self); + } + } +} From 7ca7acd084cfd156316d1063920efededcf9cce5 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Wed, 20 Jul 2016 09:17:50 +0200 Subject: [PATCH 02/15] Use two queues instead of a custom linked memory structure --- .../tree/IterativeParseTreeWalker.java | 156 ++++++------------ 1 file changed, 54 insertions(+), 102 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java b/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java index 8a230511e..ebdf70998 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/IterativeParseTreeWalker.java @@ -30,122 +30,74 @@ package org.antlr.v4.runtime.tree; +import java.util.ArrayDeque; +import java.util.Deque; + +import org.antlr.v4.runtime.misc.IntegerStack; + /** * An iterative (read: non-recursive) pre-order and post-order tree walker that - * doesn't use the thread stack but it's own heap-based stack using linked data - * structures. Makes it possible to process deeply nested parse trees. + * doesn't use the thread stack but heap-based stacks. Makes it possible to + * process deeply nested parse trees. */ public class IterativeParseTreeWalker extends ParseTreeWalker { - public static final ParseTreeWalker DEFAULT = new IterativeParseTreeWalker(); - @Override - public void walk(final ParseTreeListener listener, final ParseTree t) { - for (WalkerNode currentNode = createNode(null, t, 0); currentNode != null;) { - currentNode.enter(listener); // Pre order visit + @Override + public void walk(ParseTreeListener listener, ParseTree t) { - // Move down to first child - WalkerNode nextNode = currentNode.getFirstChild(); - if (nextNode != null) { - currentNode = nextNode; - continue; - } + final Deque nodeStack = new ArrayDeque(); + final IntegerStack indexStack = new IntegerStack(); - // No child nodes, so walk tree - while (currentNode != null) { - currentNode.exit(listener); // Post order visit + ParseTree currentNode = t; + int currentIndex = 0; - // Move to sibling if possible - nextNode = currentNode.getNextSibling(); - if (nextNode != null) { - currentNode = nextNode; - break; - } + while (currentNode != null) { - // Move up - currentNode = currentNode.getParentNode(); - } - } - } + // pre-order visit + if (currentNode instanceof ErrorNode) { + listener.visitErrorNode((ErrorNode) currentNode); + } else if (currentNode instanceof TerminalNode) { + listener.visitTerminal((TerminalNode) currentNode); + } else { + final RuleNode r = (RuleNode) currentNode; + enterRule(listener, r); + } - protected WalkerNode createNode(final WalkerNode parent, final ParseTree self, final int pos) { - if (self instanceof ErrorNode) { - return new ErrorWalkerNode(parent, (ErrorNode) self, pos); - } else if (self instanceof TerminalNode) { - return new TerminalWalkerNode(parent, (TerminalNode) self, pos); - } else { - return new RuleWalkerNode(parent, (RuleNode) self, pos); - } - } + // Move down to first child, if exists + if (currentNode.getChildCount() > 0) { + nodeStack.push(currentNode); + indexStack.push(currentIndex); + currentIndex = 0; + currentNode = currentNode.getChild(0); + continue; + } - protected abstract class WalkerNode { - private final WalkerNode parent; - protected final N self; - private final int pos; + // No child nodes, so walk tree + do { - protected WalkerNode(final WalkerNode parent, final N self, final int pos) { - this.parent = parent; - this.self = self; - this.pos = pos; - } + // post-order visit + if (currentNode instanceof RuleNode) { + exitRule(listener, (RuleNode) currentNode); + } - public WalkerNode getFirstChild() { - return self.getChildCount() > 0 ? createChildNode(0) : null; - } + // No parent, so no siblings + if (nodeStack.isEmpty()) { + currentNode = null; + currentIndex = 0; + break; + } - public WalkerNode getNextSibling() { - return parent != null && parent.self.getChildCount() > pos + 1 ? parent.createChildNode(pos + 1) : null; - } + // Move to next sibling if possible + currentNode = nodeStack.peek().getChild(++currentIndex); + if (currentNode != null) { + break; + } - public WalkerNode getParentNode() { - return parent; - } + // No next, sibling, so move up + currentNode = nodeStack.pop(); + currentIndex = indexStack.pop(); - public abstract void enter(ParseTreeListener listener); - - public void exit(final ParseTreeListener listener) { - // defaults to do nothing - } - - protected WalkerNode createChildNode(final int pos) { - return createNode(this, self.getChild(pos), pos); - } - } - - protected class RuleWalkerNode extends WalkerNode { - public RuleWalkerNode(final WalkerNode parent, final RuleNode self, final int pos) { - super(parent, self, pos); - } - - @Override - public void enter(final ParseTreeListener listener) { - enterRule(listener, self); - } - - @Override - public void exit(final ParseTreeListener listener) { - exitRule(listener, self); - } - } - - protected class ErrorWalkerNode extends WalkerNode { - public ErrorWalkerNode(final WalkerNode parent, final ErrorNode self, final int pos) { - super(parent, self, pos); - } - - @Override - public void enter(final ParseTreeListener listener) { - listener.visitErrorNode(self); - } - } - - protected class TerminalWalkerNode extends WalkerNode { - public TerminalWalkerNode(final WalkerNode parent, final TerminalNode self, final int pos) { - super(parent, self, pos); - } - - @Override - public void enter(final ParseTreeListener listener) { - listener.visitTerminal(self); - } - } + } while (currentNode != null); + } + } } From ea316158047e08854f24ab4a87f04e1f8b5b9105 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Wed, 20 Jul 2016 09:18:08 +0200 Subject: [PATCH 03/15] Use the iterative version of the ParseTreeWalker as default implementation --- runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java index 1065204b4..e860327f8 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreeWalker.java @@ -34,7 +34,7 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.RuleContext; public class ParseTreeWalker { - public static final ParseTreeWalker DEFAULT = new ParseTreeWalker(); + public static final ParseTreeWalker DEFAULT = new IterativeParseTreeWalker(); public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { From 9766dff5d8ad8e157a6a1a170793b048629d286c Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 23 Sep 2016 16:57:40 +0300 Subject: [PATCH 04/15] Javascript performance. Was add new string.hash function - murmurhash3_gc.js (https://github.com/garycourt/murmurhash-js/blob/master/murmurhash3_gc.js). Performance of the function increased in two times --- runtime/JavaScript/src/antlr4/Utils.js | 69 +++++++++++++++++++++----- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/runtime/JavaScript/src/antlr4/Utils.js b/runtime/JavaScript/src/antlr4/Utils.js index b47e75872..6b54da305 100644 --- a/runtime/JavaScript/src/antlr4/Utils.js +++ b/runtime/JavaScript/src/antlr4/Utils.js @@ -2,18 +2,63 @@ function arrayToString(a) { return "[" + a.join(", ") + "]"; } -String.prototype.hashCode = function(s) { - var hash = 0; - if (this.length === 0) { - return hash; - } - for (var i = 0; i < this.length; i++) { - var character = this.charCodeAt(i); - hash = ((hash << 5) - hash) + character; - hash = hash & hash; // Convert to 32bit integer - } - return hash; -}; + String.prototype.seed = String.prototype.seed || Math.round(Math.random() * Math.pow(2, 32));; + + String.prototype.hashCode = function () { + var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i, + key = this.toString(); + + remainder = key.length & 3; // key.length % 4 + bytes = key.length - remainder; + h1 = String.prototype.seed; + c1 = 0xcc9e2d51; + c2 = 0x1b873593; + i = 0; + + while (i < bytes) { + k1 = + ((key.charCodeAt(i) & 0xff)) | + ((key.charCodeAt(++i) & 0xff) << 8) | + ((key.charCodeAt(++i) & 0xff) << 16) | + ((key.charCodeAt(++i) & 0xff) << 24); + ++i; + + k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); + h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff; + h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16)); + } + + k1 = 0; + + switch (remainder) { + case 3: + k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16; + case 2: + k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8; + case 1: + k1 ^= (key.charCodeAt(i) & 0xff); + + k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff; + h1 ^= k1; + } + + h1 ^= key.length; + + h1 ^= h1 >>> 16; + h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff; + h1 ^= h1 >>> 13; + h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff; + h1 ^= h1 >>> 16; + + return h1 >>> 0; + }; function standardEqualsFunction(a,b) { return a.equals(b); From 04e9078dd98a90e3d6b93d22936dd4c1ef46c0fd Mon Sep 17 00:00:00 2001 From: ghosthope Date: Wed, 23 Nov 2016 13:58:43 +0300 Subject: [PATCH 05/15] from master --- .../test/runtime/javascript/chrome/chromedriver.bin | Bin .../src/org/antlr/v4/runtime/atn/ATNConfigSet.java | 0 .../antlr/v4/runtime/atn/ParserATNSimulator.java | 0 runtime/Python2/src/antlr4/atn/ATNConfigSet.py | 0 .../Python2/src/antlr4/atn/ParserATNSimulator.py | 0 runtime/Python3/bin/pygrun | 0 runtime/Python3/bin/pygrun.bat | 0 runtime/Python3/src/antlr4/atn/ATNConfigSet.py | 0 .../Python3/src/antlr4/atn/ParserATNSimulator.py | 0 9 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin mode change 100755 => 100644 runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java mode change 100755 => 100644 runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java mode change 100755 => 100644 runtime/Python2/src/antlr4/atn/ATNConfigSet.py mode change 100755 => 100644 runtime/Python2/src/antlr4/atn/ParserATNSimulator.py mode change 100755 => 100644 runtime/Python3/bin/pygrun mode change 100755 => 100644 runtime/Python3/bin/pygrun.bat mode change 100755 => 100644 runtime/Python3/src/antlr4/atn/ATNConfigSet.py mode change 100755 => 100644 runtime/Python3/src/antlr4/atn/ParserATNSimulator.py diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin old mode 100755 new mode 100644 diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java old mode 100755 new mode 100644 diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java old mode 100755 new mode 100644 diff --git a/runtime/Python2/src/antlr4/atn/ATNConfigSet.py b/runtime/Python2/src/antlr4/atn/ATNConfigSet.py old mode 100755 new mode 100644 diff --git a/runtime/Python2/src/antlr4/atn/ParserATNSimulator.py b/runtime/Python2/src/antlr4/atn/ParserATNSimulator.py old mode 100755 new mode 100644 diff --git a/runtime/Python3/bin/pygrun b/runtime/Python3/bin/pygrun old mode 100755 new mode 100644 diff --git a/runtime/Python3/bin/pygrun.bat b/runtime/Python3/bin/pygrun.bat old mode 100755 new mode 100644 diff --git a/runtime/Python3/src/antlr4/atn/ATNConfigSet.py b/runtime/Python3/src/antlr4/atn/ATNConfigSet.py old mode 100755 new mode 100644 diff --git a/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py b/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py old mode 100755 new mode 100644 From cc59a699d4469d00be83370f3ee2b5b2700de60c Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 25 Nov 2016 12:16:48 +0100 Subject: [PATCH 06/15] Add myself to the list of contributors using the date of my first commit. --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index 687eeaf20..ab6403d32 100644 --- a/contributors.txt +++ b/contributors.txt @@ -92,3 +92,4 @@ YYYY/MM/DD, github id, Full name, email 2016/03/27, beardlybread, Bradley Steinbacher, bradley.j.steinbacher@gmail.com 2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de 2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de +2016/07/10, twz123, Tom Wieczorek, tom.wieczorek@zalando.de From 3ed4348ab6e475d3b29efe01f34877d0f0d4029f Mon Sep 17 00:00:00 2001 From: Oliver Sampson Date: Fri, 25 Nov 2016 13:01:24 +0100 Subject: [PATCH 07/15] Update getting-started.md --- doc/getting-started.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/getting-started.md b/doc/getting-started.md index a1332ff5e..60457610e 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -16,19 +16,19 @@ 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-complete.jar +$ 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-complete.jar` to your `CLASSPATH`: +2. Add `antlr-4.5.3-complete.jar` to your `CLASSPATH`: ``` $ export CLASSPATH=".:/usr/local/lib/antlr-4.5-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-complete.jar:$CLASSPATH" org.antlr.v4.Tool' +$ alias antlr4='java -Xmx500M -cp "/usr/local/lib/antlr-4.5.3-complete.jar:$CLASSPATH" org.antlr.v4.Tool' $ alias grun='java org.antlr.v4.gui.TestRig' ``` From 8b8afbf16cf1a7f4004eb6fcf760194ce467f7b9 Mon Sep 17 00:00:00 2001 From: Oliver Sampson Date: Fri, 25 Nov 2016 13:03:51 +0100 Subject: [PATCH 08/15] Update contributors.txt --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index 17a172a30..d7d0a7881 100644 --- a/contributors.txt +++ b/contributors.txt @@ -118,3 +118,4 @@ YYYY/MM/DD, github id, Full name, email 2016/11/06, janyou, Janyou, janyou.antlr@outlook.com 2016/11/20, marcohu, Marco Hunsicker, antlr@hunsicker.de 2016/09/02, lygav, Vladimir (Vladi) Lyga, lyvladi@gmail.com +2016/11/25, MrSampson, Oliver Sampson, olsam@quickaudio.com From cc59a359aedb3c99207b07346df85bda96b46244 Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 25 Nov 2016 15:36:24 +0300 Subject: [PATCH 09/15] contributor name was added --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index 687eeaf20..c2e9693df 100644 --- a/contributors.txt +++ b/contributors.txt @@ -92,3 +92,4 @@ YYYY/MM/DD, github id, Full name, email 2016/03/27, beardlybread, Bradley Steinbacher, bradley.j.steinbacher@gmail.com 2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de 2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de +2016/09/23, ghosthop, Dmitry Shakhtanov, sudstrike@gmail.com From b4bf40e47ed12cf62c34315ea058677d099fa74b Mon Sep 17 00:00:00 2001 From: Oliver Sampson Date: Fri, 25 Nov 2016 15:52:18 +0100 Subject: [PATCH 10/15] Update getting-started.md --- doc/getting-started.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/getting-started.md b/doc/getting-started.md index 60457610e..056f0fa9d 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-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.5.3-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. @@ -23,7 +23,7 @@ Or just download in browser from website: 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-complete.jar:$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`. @@ -37,13 +37,13 @@ $ alias grun='java org.antlr.v4.gui.TestRig' (*Thanks to Graham Wideman*) 0. Install Java (version 1.6 or higher) -1. Download antlr-4.5-complete.jar (or whatever version) from [http://www.antlr.org/download/](http://www.antlr.org/download/) +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: * Permanently: Using System Properties dialog > Environment variables > Create or append to `CLASSPATH` variable * Temporarily, at command line: ``` -SET CLASSPATH=.;C:\Javalib\antlr-4.5-complete.jar;%CLASSPATH% +SET CLASSPATH=.;C:\Javalib\antlr-4.5.3-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 @@ -65,7 +65,7 @@ Either launch org.antlr.v4.Tool directly: ``` $ java org.antlr.v4.Tool -ANTLR Parser Generator Version 4.5 +ANTLR Parser Generator Version 4.5.3 -o ___ specify output directory where all output is generated -lib ___ specify location of .tokens files ... @@ -74,8 +74,8 @@ ANTLR Parser Generator Version 4.5 or use -jar option on java: ``` -$ java -jar /usr/local/lib/antlr-4.5-complete.jar -ANTLR Parser Generator Version 4.5 +$ java -jar /usr/local/lib/antlr-4.5.3-complete.jar +ANTLR Parser Generator Version 4.5.3 -o ___ specify output directory where all output is generated -lib ___ specify location of .tokens files ... From a20a87fad6e570cb5e6993d12a48789f8ae5ce5c Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 25 Nov 2016 17:56:04 +0300 Subject: [PATCH 11/15] typo --- contributors.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributors.txt b/contributors.txt index c2e9693df..032495efa 100644 --- a/contributors.txt +++ b/contributors.txt @@ -92,4 +92,4 @@ YYYY/MM/DD, github id, Full name, email 2016/03/27, beardlybread, Bradley Steinbacher, bradley.j.steinbacher@gmail.com 2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de 2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de -2016/09/23, ghosthop, Dmitry Shakhtanov, sudstrike@gmail.com +2016/09/23, ghosthope, Dmitry Shakhtanov, sudstrike@gmail.com From d7996391f4da05eb072e776c94ff06d197d308c2 Mon Sep 17 00:00:00 2001 From: parrt Date: Fri, 25 Nov 2016 11:59:47 -0800 Subject: [PATCH 12/15] tweak issue template --- .github/ISSUE_TEMPLATE.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b22dc023c..52b36a92f 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -3,8 +3,4 @@ - [ ] I am not submitting a question on how to use ANTLR; instead, go to [antlr4-discussion google group](https://groups.google.com/forum/#!forum/antlr-discussion) or ask at [stackoverflow](http://stackoverflow.com/questions/tagged/antlr4) - [ ] I have done a search of the existing issues to make sure I'm not sending in a duplicate -### Expected behavior - -### Actual behavior - -### Steps to reproduce the behavior +Please include information about the expected behavior, actual behavior, and the smallest grammar or code that reproduces the behavior. If appropriate, please indicate the code generation targets such as Java, C#, ... Pointers into offending code regions are also very welcome. From 14bc6c4a6838010b0b0fad304f182ede7c5026e5 Mon Sep 17 00:00:00 2001 From: parrt Date: Fri, 25 Nov 2016 12:18:30 -0800 Subject: [PATCH 13/15] add appveyor badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e367a416..d2d29d3e0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ANTLR v4 -[![Build Status](https://travis-ci.org/antlr/antlr4.png?branch=master)](https://travis-ci.org/antlr/antlr4) [![Java 7+](https://img.shields.io/badge/java-7+-4c7e9f.svg)](http://java.oracle.com) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/antlr/antlr4/master/LICENSE.txt) +[![Build Status](https://travis-ci.org/antlr/antlr4.png?branch=master)](https://travis-ci.org/antlr/antlr4) [![Java 7+](https://img.shields.io/badge/java-7+-4c7e9f.svg)](http://java.oracle.com) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/antlr/antlr4/master/LICENSE.txt) **ANTLR** (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build parse trees and also generates a listener interface (or visitor) that makes it easy to respond to the recognition of phrases of interest. From 3506dcef1d7bfb5389ae8de2a29fd94bfad9a489 Mon Sep 17 00:00:00 2001 From: parrt Date: Fri, 25 Nov 2016 12:52:44 -0800 Subject: [PATCH 14/15] add @Override to hush warnings. Manually did some of https://github.com/antlr/antlr4/pull/1066 --- runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java | 1 + tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java | 3 +++ tool/src/org/antlr/v4/gui/TreeViewer.java | 1 + 3 files changed, 5 insertions(+) diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java b/runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java index 7bd249f6b..8d721d61d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java @@ -85,6 +85,7 @@ public class XPath { throw new IllegalArgumentException("Could not read path: "+path, ioe); } XPathLexer lexer = new XPathLexer(in) { + @Override public void recover(LexerNoViableAltException e) { throw e; } }; lexer.removeErrorListeners(); diff --git a/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java b/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java index a229942ff..1e4540bdc 100644 --- a/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java +++ b/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java @@ -220,14 +220,17 @@ public class JavaScriptTarget extends Target { } + @Override public boolean wantsBaseListener() { return false; } + @Override public boolean wantsBaseVisitor() { return false; } + @Override public boolean supportsOverloadedMethods() { return false; } diff --git a/tool/src/org/antlr/v4/gui/TreeViewer.java b/tool/src/org/antlr/v4/gui/TreeViewer.java index 96a0ca213..e9ec00134 100644 --- a/tool/src/org/antlr/v4/gui/TreeViewer.java +++ b/tool/src/org/antlr/v4/gui/TreeViewer.java @@ -393,6 +393,7 @@ public class TreeViewer extends JComponent { // make viz WindowListener exitListener = new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { prefs.putInt(DIALOG_WIDTH_PREFS_KEY, (int) dialog.getSize().getWidth()); prefs.putInt(DIALOG_HEIGHT_PREFS_KEY, (int) dialog.getSize().getHeight()); From c695ed25e9e716af0e33823a4e9d9b93a2b1bf02 Mon Sep 17 00:00:00 2001 From: parrt Date: Fri, 25 Nov 2016 13:01:07 -0800 Subject: [PATCH 15/15] Fixes #1238. @antlr/antlr-targets might want to tweak their targets. --- .../org/antlr/v4/runtime/BufferedTokenStream.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java b/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java index ba1417c68..068c86aa0 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java @@ -456,18 +456,17 @@ public class BufferedTokenStream implements TokenStream { @Override public String getText() { - lazyInit(); - fill(); return getText(Interval.of(0,size()-1)); } - - @Override - public String getText(Interval interval) { + @Override + public String getText(Interval interval) { + lazyInit(); + fill(); int start = interval.a; int stop = interval.b; - if ( start<0 || stop<0 ) return ""; - lazyInit(); + if ( start<0 || stop<0 ) return ""; + lazyInit(); if ( stop>=tokens.size() ) stop = tokens.size()-1; StringBuilder buf = new StringBuilder();