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 | import { DefaultErrorStrategy } from "./DefaultErrorStrategy";
|
6 | import { Parser } from "./Parser";
|
7 | import { RecognitionException } from "./RecognitionException";
|
8 | import { Token } from "./Token";
|
9 | /**
|
10 | * This implementation of {@link ANTLRErrorStrategy} responds to syntax errors
|
11 | * by immediately canceling the parse operation with a
|
12 | * {@link ParseCancellationException}. The implementation ensures that the
|
13 | * {@link ParserRuleContext#exception} field is set for all parse tree nodes
|
14 | * that were not completed prior to encountering the error.
|
15 | *
|
16 | * This error strategy is useful in the following scenarios.
|
17 | *
|
18 | * * **Two-stage parsing:** This error strategy allows the first
|
19 | * stage of two-stage parsing to immediately terminate if an error is
|
20 | * encountered, and immediately fall back to the second stage. In addition to
|
21 | * avoiding wasted work by attempting to recover from errors here, the empty
|
22 | * implementation of {@link BailErrorStrategy#sync} improves the performance of
|
23 | * the first stage.
|
24 | * * **Silent validation:** When syntax errors are not being
|
25 | * reported or logged, and the parse result is simply ignored if errors occur,
|
26 | * the {@link BailErrorStrategy} avoids wasting work on recovering from errors
|
27 | * when the result will be ignored either way.
|
28 | *
|
29 | * ```
|
30 | * myparser.errorHandler = new BailErrorStrategy();
|
31 | * ```
|
32 | *
|
33 | * @see Parser.errorHandler
|
34 | */
|
35 | export declare class BailErrorStrategy extends DefaultErrorStrategy {
|
36 | /** Instead of recovering from exception `e`, re-throw it wrapped
|
37 | * in a {@link ParseCancellationException} so it is not caught by the
|
38 | * rule function catches. Use {@link Exception#getCause()} to get the
|
39 | * original {@link RecognitionException}.
|
40 | */
|
41 | recover(recognizer: Parser, e: RecognitionException): void;
|
42 | /** Make sure we don't attempt to recover inline; if the parser
|
43 | * successfully recovers, it won't throw an exception.
|
44 | */
|
45 | recoverInline(recognizer: Parser): Token;
|
46 | /** Make sure we don't attempt to recover from problems in subrules. */
|
47 | sync(recognizer: Parser): void;
|
48 | }
|