-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished CommonTokenFactory, CommonTokenStream, DefaultErrorStrategy …
…+ DiagnosticErrorListener Also removed JSDoc-only imports, as the rule for unknown JSDoc types has been disabled. Signed-off-by: Mike Lischke <[email protected]>
- Loading branch information
1 parent
bc07246
commit 199f888
Showing
20 changed files
with
240 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) The ANTLR Project. All rights reserved. | ||
* Use of this file is governed by the BSD 3-clause license that | ||
* can be found in the LICENSE.txt file in the project root. | ||
*/ | ||
|
||
import { CharStream } from "./CharStream.js"; | ||
import { CommonToken } from "./CommonToken.js"; | ||
import { TokenFactory } from "./TokenFactory.js"; | ||
import { TokenSource } from "./TokenSource.js"; | ||
|
||
/** | ||
* This default implementation of {@link TokenFactory} creates | ||
* {@link CommonToken} objects. | ||
*/ | ||
export class CommonTokenFactory extends TokenFactory<CommonToken> { | ||
/** | ||
* The default {@link CommonTokenFactory} instance. | ||
* | ||
* <p> | ||
* This token factory does not explicitly copy token text when constructing | ||
* tokens.</p> | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
public static readonly DEFAULT = new CommonTokenFactory(); | ||
|
||
/** | ||
* Indicates whether {@link CommonToken#setText} should be called after | ||
* constructing tokens to explicitly set the text. This is useful for cases | ||
* where the input stream might not be able to provide arbitrary substrings | ||
* of text from the input after the lexer creates a token (e.g. the | ||
* implementation of {@link CharStream#getText} in | ||
* {@link UnbufferedCharStream} throws an | ||
* {@link UnsupportedOperationException}). Explicitly setting the token text | ||
* allows {@link Token#getText} to be called at any time regardless of the | ||
* input stream implementation. | ||
* | ||
* <p> | ||
* The default value is {@code false} to avoid the performance and memory | ||
* overhead of copying text for every token unless explicitly requested.</p> | ||
*/ | ||
protected readonly copyText: boolean = false; | ||
|
||
public constructor(copyText?: boolean) { | ||
super(); | ||
/** | ||
* Indicates whether {@link CommonToken//setText} should be called after | ||
* constructing tokens to explicitly set the text. This is useful for cases | ||
* where the input stream might not be able to provide arbitrary substrings | ||
* of text from the input after the lexer creates a token (e.g. the | ||
* implementation of {@link CharStream//getText} in | ||
* {@link UnbufferedCharStream} throws an | ||
* {@link UnsupportedOperationException}). Explicitly setting the token text | ||
* allows {@link Token//getText} to be called at any time regardless of the | ||
* input stream implementation. | ||
* | ||
* <p> | ||
* The default value is {@code false} to avoid the performance and memory | ||
* overhead of copying text for every token unless explicitly requested.</p> | ||
*/ | ||
this.copyText = copyText ?? false; | ||
} | ||
|
||
public override create(source: [TokenSource | null, CharStream | null], type: number, text: string, channel: number, | ||
start: number, stop: number, line: number, column: number): CommonToken { | ||
const t = new CommonToken(source, type, channel, start, stop); | ||
t.line = line; | ||
t.column = column; | ||
if (text !== null) { | ||
t.text = text; | ||
} else if (this.copyText && source[1] !== null) { | ||
t.text = source[1].getText(start, stop); | ||
} | ||
|
||
return t; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) The ANTLR Project. All rights reserved. | ||
* Use of this file is governed by the BSD 3-clause license that | ||
* can be found in the LICENSE.txt file in the project root. | ||
*/ | ||
|
||
import { BaseErrorListener } from "./BaseErrorListener.js"; | ||
import { RecognitionException } from "./RecognitionException.js"; | ||
import { Recognizer } from "./Recognizer.js"; | ||
import { ATNSimulator } from "./atn/ATNSimulator.js"; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* <p> | ||
* This implementation prints messages to {@link System//err} containing the | ||
* values of {@code line}, {@code charPositionInLine}, and {@code msg} using | ||
* the following format.</p> | ||
* | ||
* <pre> | ||
* line <em>line</em>:<em>charPositionInLine</em> <em>msg</em> | ||
* </pre> | ||
* | ||
*/ | ||
export class ConsoleErrorListener extends BaseErrorListener { | ||
/** | ||
* Provides a default instance of {@link ConsoleErrorListener}. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
public static readonly INSTANCE = new ConsoleErrorListener(); | ||
|
||
public override syntaxError<T extends ATNSimulator>(recognizer: Recognizer<T> | null, | ||
offendingSymbol: unknown, | ||
line: number, | ||
charPositionInLine: number, | ||
msg: string | null, | ||
_e: RecognitionException | null): void { | ||
console.error("line " + line + ":" + charPositionInLine + " " + msg); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.