Skip to content

Instantly share code, notes, and snippets.

@amazzalel-habib
Last active May 11, 2020 23:35
Show Gist options
  • Save amazzalel-habib/c290da845fb21d492fcb5b877d92e08b to your computer and use it in GitHub Desktop.
Save amazzalel-habib/c290da845fb21d492fcb5b877d92e08b to your computer and use it in GitHub Desktop.
import { ANTLRErrorListener, RecognitionException, Recognizer } from "antlr4ts";
export interface ITodoLangError {
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
message: string;
code: string;
}
export default class TodoLangErrorListener implements ANTLRErrorListener<any>{
private errors: ITodoLangError[] = []
syntaxError(recognizer: Recognizer<any, any>, offendingSymbol: any, line: number, charPositionInLine: number, message: string, e: RecognitionException | undefined): void {
this.errors.push(
{
startLineNumber:line,
endLineNumber: line,
startColumn: charPositionInLine,
endColumn: charPositionInLine+1,//Let's suppose the length of the error is only 1 char for simplicity
message,
code: "1" // This the error code you can customize them as you want
}
)
}
getErrors(): ITodoLangError[] {
return this.errors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment