-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report errors from antlr through logger (#46)
Mismatched or extraneous input encountered during parsing will produce error messages that include the location of the error. Two tests are added to FSHImporter.test.ts for these errors.
- Loading branch information
1 parent
9ac08ce
commit 550aa39
Showing
3 changed files
with
68 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ErrorListener } from 'antlr4/error'; | ||
import { logger } from '../utils/FSHLogger'; | ||
import { Recognizer, Token } from 'antlr4'; | ||
|
||
export class FSHErrorListener extends ErrorListener { | ||
constructor(readonly file: string) { | ||
super(); | ||
} | ||
|
||
syntaxError( | ||
recognizer: Recognizer, | ||
offendingSymbol: Token, | ||
line: number, | ||
column: number, | ||
msg: string | ||
): void { | ||
logger.error(msg, { | ||
file: this.file, | ||
location: { | ||
startLine: line, | ||
startColumn: column + 1, | ||
endLine: line, | ||
endColumn: column + offendingSymbol.text.length | ||
} | ||
}); | ||
} | ||
} |
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