Skip to content

Commit

Permalink
Only log exceptions (for example LexerNoViableAltException) if debug …
Browse files Browse the repository at this point in the history
…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 <multiarc@gmail.com>
  • Loading branch information
multiarc authored and ericvergnaud committed Feb 27, 2024
1 parent f08a19b commit bb48237
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions runtime/JavaScript/spec/rewriter/TokenStreamRewriterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion runtime/JavaScript/src/antlr4/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit bb48237

Please sign in to comment.