From 6ba4f8cf5ddf7adadfd2b790adda9b444b68a9fe Mon Sep 17 00:00:00 2001 From: Robert Einhorn Date: Tue, 19 Mar 2024 00:30:57 +0100 Subject: [PATCH] depricate some methods Signed-off-by: Robert Einhorn --- runtime/JavaScript/src/antlr4/Lexer.d.ts | 4 +++- runtime/JavaScript/src/antlr4/Lexer.js | 22 ++++++++++++++++--- runtime/JavaScript/src/antlr4/Parser.js | 2 +- runtime/JavaScript/src/antlr4/Recognizer.d.ts | 3 +++ runtime/JavaScript/src/antlr4/Recognizer.js | 8 +++++++ runtime/JavaScript/src/antlr4/Token.d.ts | 6 +++-- .../src/antlr4/action/LexerModeAction.js | 2 +- .../src/antlr4/atn/ParserATNSimulator.js | 6 ++--- 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/runtime/JavaScript/src/antlr4/Lexer.d.ts b/runtime/JavaScript/src/antlr4/Lexer.d.ts index fe32aa7b4f..6429be3056 100644 --- a/runtime/JavaScript/src/antlr4/Lexer.d.ts +++ b/runtime/JavaScript/src/antlr4/Lexer.d.ts @@ -22,7 +22,9 @@ export declare class Lexer extends Recognizer { nextToken(): Token; skip(): void; more(): void; - more(m: number): void; + setMode(m: number): void; + getMode(): number; + getModeStack(): number[]; pushMode(m: number): void; popMode(): number; emitToken(token: Token): void; diff --git a/runtime/JavaScript/src/antlr4/Lexer.js b/runtime/JavaScript/src/antlr4/Lexer.js index 8ff0a89a53..3e1edb6ea6 100644 --- a/runtime/JavaScript/src/antlr4/Lexer.js +++ b/runtime/JavaScript/src/antlr4/Lexer.js @@ -169,16 +169,32 @@ export default class Lexer extends Recognizer { this._type = Lexer.MORE; } + /** + * @deprecated since ANTLR 4.13.2; use setMode instead + */ mode(m) { + console.warn("Calling deprecated method in Lexer class: mode(...)"); + setMode(m); + } + + setMode(m) { this._mode = m; } + getMode() { + return this._mode; + } + + getModeStack() { + return this._modeStack; + } + pushMode(m) { if (this._interp.debug) { console.log("pushMode " + m); } this._modeStack.push(this._mode); - this.mode(m); + this.setMode(m); } popMode() { @@ -188,7 +204,7 @@ export default class Lexer extends Recognizer { if (this._interp.debug) { console.log("popMode back to " + this._modeStack.slice(0, -1)); } - this.mode(this._modeStack.pop()); + this.setMode(this._modeStack.pop()); return this._mode; } @@ -252,7 +268,7 @@ export default class Lexer extends Recognizer { const stop = this._input.index; const text = this._input.getText(start, stop); const msg = "token recognition error at: '" + this.getErrorDisplay(text) + "'"; - const listener = this.getErrorListenerDispatch(); + const listener = this.getErrorListener(); listener.syntaxError(this, null, this._tokenStartLine, this._tokenStartColumn, msg, e); } diff --git a/runtime/JavaScript/src/antlr4/Parser.js b/runtime/JavaScript/src/antlr4/Parser.js index 4c434fd0db..032de9a74e 100644 --- a/runtime/JavaScript/src/antlr4/Parser.js +++ b/runtime/JavaScript/src/antlr4/Parser.js @@ -314,7 +314,7 @@ export default class Parser extends Recognizer { this._syntaxErrors += 1; const line = offendingToken.line; const column = offendingToken.column; - const listener = this.getErrorListenerDispatch(); + const listener = this.getErrorListener(); listener.syntaxError(this, offendingToken, line, column, msg, err); } diff --git a/runtime/JavaScript/src/antlr4/Recognizer.d.ts b/runtime/JavaScript/src/antlr4/Recognizer.d.ts index d77927c9a2..d3f4bae19e 100644 --- a/runtime/JavaScript/src/antlr4/Recognizer.d.ts +++ b/runtime/JavaScript/src/antlr4/Recognizer.d.ts @@ -6,4 +6,7 @@ export declare class Recognizer { removeErrorListeners(): void; addErrorListener(listener: ErrorListener): void; + getErrorListener(): ErrorListener; + getLiteralNames(): string[]; + getSymbolicNames(): string[]; } diff --git a/runtime/JavaScript/src/antlr4/Recognizer.js b/runtime/JavaScript/src/antlr4/Recognizer.js index bb726bc1a3..a18a43eaf3 100644 --- a/runtime/JavaScript/src/antlr4/Recognizer.js +++ b/runtime/JavaScript/src/antlr4/Recognizer.js @@ -126,7 +126,15 @@ export default class Recognizer { return "'" + s + "'"; } + /** + * @deprecated since ANTLR 4.13.2; use getErrorListener instead + */ getErrorListenerDispatch() { + console.warn("Calling deprecated method in Recognizer class: getErrorListenerDispatch()"); + return this.getErrorListener(); + } + + getErrorListener() { return new ProxyErrorListener(this._listeners); } diff --git a/runtime/JavaScript/src/antlr4/Token.d.ts b/runtime/JavaScript/src/antlr4/Token.d.ts index 87fb12d1f5..7a8e5b70a5 100644 --- a/runtime/JavaScript/src/antlr4/Token.d.ts +++ b/runtime/JavaScript/src/antlr4/Token.d.ts @@ -1,9 +1,10 @@ -import {CharStream} from "./CharStream"; +import { TokenSource } from "./TokenSource"; +import { CharStream } from "./CharStream"; export declare class Token { + static INVALID_TYPE: number; static EOF: number; - static DEFAULT_CHANNEL: number; static HIDDEN_CHANNEL: number; @@ -18,5 +19,6 @@ export declare class Token { clone(): Token; cloneWithType(type: number): Token; + getTokenSource(): TokenSource; getInputStream(): CharStream; } diff --git a/runtime/JavaScript/src/antlr4/action/LexerModeAction.js b/runtime/JavaScript/src/antlr4/action/LexerModeAction.js index 81f7aca154..2ac01065e4 100644 --- a/runtime/JavaScript/src/antlr4/action/LexerModeAction.js +++ b/runtime/JavaScript/src/antlr4/action/LexerModeAction.js @@ -20,7 +20,7 @@ export default class LexerModeAction extends LexerAction { * value provided by {@link //getMode}.

*/ execute(lexer) { - lexer.mode(this.mode); + lexer.setMode(this.mode); } updateHashCode(hash) { diff --git a/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js b/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js index 95b2096400..2a267c9772 100644 --- a/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js +++ b/runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js @@ -1702,7 +1702,7 @@ export default class ParserATNSimulator extends ATNSimulator { ", input=" + this.parser.getTokenStream().getText(interval)); } if (this.parser!==null) { - this.parser.getErrorListenerDispatch().reportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs); + this.parser.getErrorListener().reportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs); } } @@ -1713,7 +1713,7 @@ export default class ParserATNSimulator extends ATNSimulator { ", input=" + this.parser.getTokenStream().getText(interval)); } if (this.parser!==null) { - this.parser.getErrorListenerDispatch().reportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs); + this.parser.getErrorListener().reportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs); } } @@ -1726,7 +1726,7 @@ export default class ParserATNSimulator extends ATNSimulator { ", input=" + this.parser.getTokenStream().getText(interval)); } if (this.parser!==null) { - this.parser.getErrorListenerDispatch().reportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs); + this.parser.getErrorListener().reportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs); } } }