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 diff --git a/contributors.txt b/contributors.txt index c5d18265b..e424e930e 100644 --- a/contributors.txt +++ b/contributors.txt @@ -151,7 +151,13 @@ YYYY/MM/DD, github id, Full name, email 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 +2017/06/28, jBugman, Sergey Parshukov, codedby@bugman.me +2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com 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 2017/07/09, neatnerd, Mike Arshinskiy, neatnerd@users.noreply.github.com -2017/08/20, tiagomazzutti, Tiago Mazzutti, tiagomzt@gmail.com +2017/07/27, matthauck, Matt Hauck, matthauck@gmail.com +2017/07/27, shirou, WAKAYAMA Shirou, shirou.faw@gmail.com +2017/08/20, tiagomazzutti, Tiago Mazzutti, tiagomzt@gmail.com \ No newline at end of file diff --git a/doc/getting-started.md b/doc/getting-started.md index eaf2141fb..62bc69711 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' @@ -39,7 +41,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: ``` 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(); 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") 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 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/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/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 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 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/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 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) ::= << 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..728db6307 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 , @@ -802,6 +802,9 @@ var antlr4 = require('antlr4/index'); >> Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= << + +var = require('./').; + @@ -860,7 +863,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" 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. *