diff --git a/doc/javascript-target.md b/doc/javascript-target.md index 76bb26cc3d..77f3ff2ccc 100644 --- a/doc/javascript-target.md +++ b/doc/javascript-target.md @@ -40,8 +40,6 @@ Once you've generated the lexer and/or parser code, you need to download the run The JavaScript runtime is [available from npm](https://www.npmjs.com/package/antlr4). -If you can't use npm, the JavaScript runtime is also available from the ANTLR web site [download section](http://www.antlr.org/download/index.html). The runtime is provided in the form of source code, so no additional installation is required. - We will not document here how to refer to the runtime from your project, since this would differ a lot depending on your project type and IDE. ## How do I get the runtime in my browser? diff --git a/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js b/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js index a58bc26ef0..b9ffa0eccc 100644 --- a/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js +++ b/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js @@ -8,7 +8,7 @@ import calc from "./generatedCode/calc.js"; * @param {string} input */ function getRewriter(lexerClass, input) { - const chars = new antlr4.InputStream(input); + const chars = antlr4.CharStreams.fromString(input); const lexer = new lexerClass(chars); const tokens = new antlr4.CommonTokenStream(lexer); tokens.fill(); @@ -385,7 +385,7 @@ describe("TokenStreamRewriter", () => { it("throws an error if second replace operation overlaps the first one on the left", () => { // Arrange - const chars = new antlr4.InputStream("abcccba"); + const chars = antlr4.CharStreams.fromString("abcccba"); const lexer = new abc(chars); const tokens = new antlr4.CommonTokenStream(lexer); tokens.fill(); diff --git a/runtime/JavaScript/src/antlr4/Lexer.js b/runtime/JavaScript/src/antlr4/Lexer.js index 0d1a494597..8ff0a89a53 100644 --- a/runtime/JavaScript/src/antlr4/Lexer.js +++ b/runtime/JavaScript/src/antlr4/Lexer.js @@ -121,7 +121,7 @@ export default class Lexer extends Recognizer { this.notifyListeners(e); // report error this.recover(e); } else { - console.log(e.stack); + console.log(e.stack); throw e; } } diff --git a/runtime/JavaScript/src/antlr4/index.node.js b/runtime/JavaScript/src/antlr4/index.node.js index b54aa2ccdf..4d06196e90 100644 --- a/runtime/JavaScript/src/antlr4/index.node.js +++ b/runtime/JavaScript/src/antlr4/index.node.js @@ -14,7 +14,7 @@ import { default as Utils } from './utils/index.js'; import Token from './Token.js'; import CommonToken from './CommonToken.js'; import InputStream from './InputStream.js'; -import CharStream from './InputStream.js'; +import CharStream from './CharStream.js'; import FileStream from './FileStream.js'; import CommonTokenStream from './CommonTokenStream.js'; import Lexer from './Lexer.js'; @@ -57,5 +57,5 @@ export { RuleNode, TerminalNode, ParseTreeWalker, RuleContext, ParserRuleContext, Interval, IntervalSet, PredictionMode, LL1Analyzer, ParseTreeListener, ParseTreeVisitor, ATN, ATNDeserializer, PredictionContextCache, LexerATNSimulator, ParserATNSimulator, DFA, RecognitionException, NoViableAltException, FailedPredicateException, ErrorListener, DiagnosticErrorListener, BailErrorStrategy, DefaultErrorStrategy, - arrayToString + arrayToString, TokenStreamRewriter } diff --git a/runtime/JavaScript/src/antlr4/index.web.js b/runtime/JavaScript/src/antlr4/index.web.js index 6361803b1e..3965b941d1 100644 --- a/runtime/JavaScript/src/antlr4/index.web.js +++ b/runtime/JavaScript/src/antlr4/index.web.js @@ -14,7 +14,7 @@ import { default as Utils } from './utils/index.js'; import Token from './Token.js'; import CommonToken from './CommonToken.js'; import InputStream from './InputStream.js'; -import CharStream from './InputStream.js'; +import CharStream from './CharStream.js'; import CommonTokenStream from './CommonTokenStream.js'; import Lexer from './Lexer.js'; import Parser from './Parser.js'; @@ -56,5 +56,5 @@ export { RuleNode, TerminalNode, ParseTreeWalker, RuleContext, ParserRuleContext, Interval, IntervalSet, PredictionMode, LL1Analyzer, ParseTreeListener, ParseTreeVisitor, ATN, ATNDeserializer, PredictionContextCache, LexerATNSimulator, ParserATNSimulator, DFA, RecognitionException, NoViableAltException, FailedPredicateException, ErrorListener, DiagnosticErrorListener, BailErrorStrategy, DefaultErrorStrategy, - arrayToString + arrayToString, TokenStreamRewriter } diff --git a/runtime/Python3/src/antlr4/atn/ATNDeserializer.py b/runtime/Python3/src/antlr4/atn/ATNDeserializer.py index d7b1768424..c491ac4c65 100644 --- a/runtime/Python3/src/antlr4/atn/ATNDeserializer.py +++ b/runtime/Python3/src/antlr4/atn/ATNDeserializer.py @@ -47,7 +47,7 @@ def deserialize(self, data : [int]): def checkVersion(self): version = self.readInt() if version != SERIALIZED_VERSION: - raise Exception("Could not deserialize ATN with version " + str(version) + " (expected " + str(SERIALIZED_VERSION) + ").") + raise Exception("Could not deserialize ATN with version {} (expected {}).".format(ord(version), SERIALIZED_VERSION)) def readATN(self): idx = self.readInt() 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 3a97a1fa27..8500371a20 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 @@ -225,7 +225,7 @@ Parser(parser, funcs, atn, sempredFuncs, superClass) ::= << >> Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= << -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"}) public class extends { static { RuntimeMetaData.checkVersion("", RuntimeMetaData.VERSION); }