Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some properties and methods #4525

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
getModeStack(): number[];
getMode(): number;
setMode(m: number): void;
pushMode(m: number): void;
popMode(): number;
emitToken(token: Token): void;
Expand Down
14 changes: 13 additions & 1 deletion runtime/JavaScript/src/antlr4/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -173,6 +173,18 @@ export default class Lexer extends Recognizer {
this._mode = m;
}

getMode() {
return this._mode;
}

setMode(m) {
this._mode = m;
}

getModeStack() {
return this._modeStack;
}

pushMode(m) {
if (this._interp.debug) {
console.log("pushMode " + m);
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;
getErrorListenerDispatch(): ErrorListener<TSymbol>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to say getRootErrorListener() (open to suggestions). Appreciate it's an instance of ErrorListenerDispatch but that's a terrible name...

Copy link
Contributor Author

@RobEin RobEin Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name mode is really not a good property name, because there is already a mode() method in the JavaScript Lexer.
Maybe a property for JavaScript/TypeScript called lexerMode or tokenizerMode?
And the mode() method would be depreciated in the JavaScript Lexer.

I don't like the name getErrorListenerDispatch either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we can't change that name without breaking backwards compatibility in JS...

Copy link
Contributor Author

@RobEin RobEin Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, unfortunately the getErrorListenerDispatch method should not be renamed.
I think an independent TypeScript runtime (no *.js, no *.d.ts) would be ideal for this and other more modern designs.
Maybe in ANTLR5?

I remove my setMode method because there is already a mode method that does the same thing.
However, a setMode/getMode pair would have been more elegant than a mode/getMode pair.

getLiteralNames(): string[] | [];
getSymbolicNames(): string[] | [];
}
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;
}
Loading