UNPKG

6.06 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 */
5import { ANTLRErrorListener } from "./ANTLRErrorListener";
6import { ATNConfigSet } from "./atn/ATNConfigSet";
7import { BitSet } from "./misc/BitSet";
8import { DFA } from "./dfa/DFA";
9import { Parser } from "./Parser";
10import { SimulatorState } from "./atn/SimulatorState";
11import { Token } from "./Token";
12/** How to emit recognition errors for parsers.
13 */
14export interface ParserErrorListener extends ANTLRErrorListener<Token> {
15 /**
16 * This method is called by the parser when a full-context prediction
17 * results in an ambiguity.
18 *
19 * Each full-context prediction which does not result in a syntax error
20 * will call either {@link #reportContextSensitivity} or
21 * {@link #reportAmbiguity}.
22 *
23 * When `ambigAlts` is not `undefined`, it contains the set of potentially
24 * viable alternatives identified by the prediction algorithm. When
25 * `ambigAlts` is `undefined`, use
26 * {@link ATNConfigSet#getRepresentedAlternatives} to obtain the represented
27 * alternatives from the `configs` argument.
28 *
29 * When `exact` is `true`, *all* of the potentially
30 * viable alternatives are truly viable, i.e. this is reporting an exact
31 * ambiguity. When `exact` is `false`, *at least two* of
32 * the potentially viable alternatives are viable for the current input, but
33 * the prediction algorithm terminated as soon as it determined that at
34 * least the *minimum* potentially viable alternative is truly
35 * viable.
36 *
37 * When the {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} prediction
38 * mode is used, the parser is required to identify exact ambiguities so
39 * `exact` will always be `true`.
40 *
41 * @param recognizer the parser instance
42 * @param dfa the DFA for the current decision
43 * @param startIndex the input index where the decision started
44 * @param stopIndex the input input where the ambiguity was identified
45 * @param exact `true` if the ambiguity is exactly known, otherwise
46 * `false`. This is always `true` when
47 * {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} is used.
48 * @param ambigAlts the potentially ambiguous alternatives, or `undefined`
49 * to indicate that the potentially ambiguous alternatives are the complete
50 * set of represented alternatives in `configs`
51 * @param configs the ATN configuration set where the ambiguity was
52 * identified
53 */
54 reportAmbiguity?: (recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, exact: boolean, ambigAlts: BitSet | undefined, configs: ATNConfigSet) => void;
55 /**
56 * This method is called when an SLL conflict occurs and the parser is about
57 * to use the full context information to make an LL decision.
58 *
59 * If one or more configurations in `configs` contains a semantic
60 * predicate, the predicates are evaluated before this method is called. The
61 * subset of alternatives which are still viable after predicates are
62 * evaluated is reported in `conflictingAlts`.
63 *
64 * @param recognizer the parser instance
65 * @param dfa the DFA for the current decision
66 * @param startIndex the input index where the decision started
67 * @param stopIndex the input index where the SLL conflict occurred
68 * @param conflictingAlts The specific conflicting alternatives. If this is
69 * `undefined`, the conflicting alternatives are all alternatives
70 * represented in `configs`.
71 * @param conflictState the simulator state when the SLL conflict was
72 * detected
73 */
74 reportAttemptingFullContext?: (recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, conflictingAlts: BitSet | undefined, conflictState: SimulatorState) => void;
75 /**
76 * This method is called by the parser when a full-context prediction has a
77 * unique result.
78 *
79 * Each full-context prediction which does not result in a syntax error
80 * will call either {@link #reportContextSensitivity} or
81 * {@link #reportAmbiguity}.
82 *
83 * For prediction implementations that only evaluate full-context
84 * predictions when an SLL conflict is found (including the default
85 * {@link ParserATNSimulator} implementation), this method reports cases
86 * where SLL conflicts were resolved to unique full-context predictions,
87 * i.e. the decision was context-sensitive. This report does not necessarily
88 * indicate a problem, and it may appear even in completely unambiguous
89 * grammars.
90 *
91 * `configs` may have more than one represented alternative if the
92 * full-context prediction algorithm does not evaluate predicates before
93 * beginning the full-context prediction. In all cases, the final prediction
94 * is passed as the `prediction` argument.
95 *
96 * Note that the definition of "context sensitivity" in this method
97 * differs from the concept in {@link DecisionInfo#contextSensitivities}.
98 * This method reports all instances where an SLL conflict occurred but LL
99 * parsing produced a unique result, whether or not that unique result
100 * matches the minimum alternative in the SLL conflicting set.
101 *
102 * @param recognizer the parser instance
103 * @param dfa the DFA for the current decision
104 * @param startIndex the input index where the decision started
105 * @param stopIndex the input index where the context sensitivity was
106 * finally determined
107 * @param prediction the unambiguous result of the full-context prediction
108 * @param acceptState the simulator state when the unambiguous prediction
109 * was determined
110 */
111 reportContextSensitivity?: (recognizer: Parser, dfa: DFA, startIndex: number, stopIndex: number, prediction: number, acceptState: SimulatorState) => void;
112}