From b957903c305f275948322ab5f6041e5d08c6ff29 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kukrash Date: Tue, 20 Feb 2024 03:03:41 +0400 Subject: [PATCH 1/3] Only log exceptions (for example LexerNoViableAltException) if debug is enabled for _interp. There is no other way to control this console output right now, seems like missed if check. [in progress]: unintentional exception is fired by Lexer along with passing it through error listener at the same time. This behavior changed. Signed-off-by: Aliaksandr Kukrash --- runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js | 4 ++-- runtime/JavaScript/src/antlr4/Lexer.js | 4 +++- runtime/JavaScript/src/antlr4/index.node.js | 2 +- runtime/JavaScript/src/antlr4/index.web.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js b/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js index a58bc26ef0..022ac0db5f 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 = new antlr4.CharStream(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 = new antlr4.CharStream("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..a686976b11 100644 --- a/runtime/JavaScript/src/antlr4/Lexer.js +++ b/runtime/JavaScript/src/antlr4/Lexer.js @@ -121,7 +121,9 @@ export default class Lexer extends Recognizer { this.notifyListeners(e); // report error this.recover(e); } else { - console.log(e.stack); + if (this._interp.debug) { + 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 78b55bdb89..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'; diff --git a/runtime/JavaScript/src/antlr4/index.web.js b/runtime/JavaScript/src/antlr4/index.web.js index dec5c91c70..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'; From bfb9ab60e88279c67b77ad83428fc5919b58139e Mon Sep 17 00:00:00 2001 From: Aliaksandr Kukrash Date: Mon, 26 Feb 2024 00:09:24 +0400 Subject: [PATCH 2/3] update CharStreams usage and revert change for exception logging Signed-off-by: Aliaksandr Kukrash --- runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js | 4 ++-- runtime/JavaScript/src/antlr4/Lexer.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js b/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js index 022ac0db5f..f9a66136c9 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.CharStream(input); + const chars = new 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.CharStream("abcccba"); + const chars = new 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 a686976b11..8ff0a89a53 100644 --- a/runtime/JavaScript/src/antlr4/Lexer.js +++ b/runtime/JavaScript/src/antlr4/Lexer.js @@ -121,9 +121,7 @@ export default class Lexer extends Recognizer { this.notifyListeners(e); // report error this.recover(e); } else { - if (this._interp.debug) { - console.log(e.stack); - } + console.log(e.stack); throw e; } } From a0a689189563473136f52bf50d7214e7281a2326 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kukrash Date: Mon, 26 Feb 2024 16:58:29 +0400 Subject: [PATCH 3/3] Fix static method usage Signed-off-by: Aliaksandr Kukrash --- runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js b/runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js index f9a66136c9..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.CharStreams.fromString(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.CharStreams.fromString("abcccba"); + const chars = antlr4.CharStreams.fromString("abcccba"); const lexer = new abc(chars); const tokens = new antlr4.CommonTokenStream(lexer); tokens.fill();