Skip to content

Commit

Permalink
depricate some methods
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Einhorn <robert.einhorn.hu@gmail.com>
  • Loading branch information
RobEin authored and ericvergnaud committed Mar 19, 2024
1 parent b4c12ec commit 6ba4f8c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
4 changes: 3 additions & 1 deletion runtime/JavaScript/src/antlr4/Lexer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export declare class Lexer extends Recognizer<number> {
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;
Expand Down
22 changes: 19 additions & 3 deletions runtime/JavaScript/src/antlr4/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/JavaScript/src/antlr4/Recognizer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export declare class Recognizer<TSymbol> {

removeErrorListeners(): void;
addErrorListener(listener: ErrorListener<TSymbol>): void;
getErrorListener(): ErrorListener<TSymbol>;
getLiteralNames(): string[];
getSymbolicNames(): string[];
}
8 changes: 8 additions & 0 deletions runtime/JavaScript/src/antlr4/Recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions runtime/JavaScript/src/antlr4/Token.d.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,5 +19,6 @@ export declare class Token {

clone(): Token;
cloneWithType(type: number): Token;
getTokenSource(): TokenSource;
getInputStream(): CharStream;
}
2 changes: 1 addition & 1 deletion runtime/JavaScript/src/antlr4/action/LexerModeAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class LexerModeAction extends LexerAction {
* value provided by {@link //getMode}.</p>
*/
execute(lexer) {
lexer.mode(this.mode);
lexer.setMode(this.mode);
}

updateHashCode(hash) {
Expand Down
6 changes: 3 additions & 3 deletions runtime/JavaScript/src/antlr4/atn/ParserATNSimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}

0 comments on commit 6ba4f8c

Please sign in to comment.