UNPKG

2.26 kBTypeScriptView Raw
1/*!
2 * Copyright 2016 The ANTLR Project. All rights reserved.
3 * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
4 */
5/** How to emit recognition errors. */
6import { Recognizer } from "./Recognizer";
7import { RecognitionException } from "./RecognitionException";
8export interface ANTLRErrorListener<TSymbol> {
9 /**
10 * Upon syntax error, notify any interested parties. This is not how to
11 * recover from errors or compute error messages. {@link ANTLRErrorStrategy}
12 * specifies how to recover from syntax errors and how to compute error
13 * messages. This listener's job is simply to emit a computed message,
14 * though it has enough information to create its own message in many cases.
15 *
16 * The {@link RecognitionException} is non-`undefined` for all syntax errors except
17 * when we discover mismatched token errors that we can recover from
18 * in-line, without returning from the surrounding rule (via the single
19 * token insertion and deletion mechanism).
20 *
21 * @param recognizer
22 * What parser got the error. From this
23 * object, you can access the context as well
24 * as the input stream.
25 * @param offendingSymbol
26 * The offending token in the input token
27 * stream, unless recognizer is a lexer (then it's `undefined`). If
28 * no viable alternative error, `e` has token at which we
29 * started production for the decision.
30 * @param line
31 * The line number in the input where the error occurred.
32 * @param charPositionInLine
33 * The character position within that line where the error occurred.
34 * @param msg
35 * The message to emit.
36 * @param e
37 * The exception generated by the parser that led to
38 * the reporting of an error. It is `undefined` in the case where
39 * the parser was able to recover in line without exiting the
40 * surrounding rule.
41 */
42 syntaxError?: <T extends TSymbol>(recognizer: Recognizer<T, any>, offendingSymbol: T | undefined, line: number, charPositionInLine: number, msg: string, e: RecognitionException | undefined) => void;
43}