1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
6 #include "Exceptions.h"
7 #include "ParserRuleContext.h"
8 #include "InputMismatchException.h"
11 #include "BailErrorStrategy.h"
13 using namespace antlr4;
15 void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) {
16 ParserRuleContext *context = recognizer->getContext();
18 context->exception = e;
19 if (context->parent == nullptr)
21 context = static_cast<ParserRuleContext *>(context->parent);
25 std::rethrow_exception(e); // Throw the exception to be able to catch and rethrow nested.
26 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026
27 } catch (RecognitionException &inner) {
28 throw ParseCancellationException(inner.what());
30 } catch (RecognitionException & /*inner*/) {
31 std::throw_with_nested(ParseCancellationException());
36 Token* BailErrorStrategy::recoverInline(Parser *recognizer) {
37 InputMismatchException e(recognizer);
38 std::exception_ptr exception = std::make_exception_ptr(e);
40 ParserRuleContext *context = recognizer->getContext();
42 context->exception = exception;
43 if (context->parent == nullptr)
45 context = static_cast<ParserRuleContext *>(context->parent);
50 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026
51 } catch (InputMismatchException &inner) {
52 throw ParseCancellationException(inner.what());
54 } catch (InputMismatchException & /*inner*/) {
55 std::throw_with_nested(ParseCancellationException());
60 void BailErrorStrategy::sync(Parser * /*recognizer*/) {