X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/9f94b672a5dc32da5ad01742bd4e976315a30d9c..c6ad2948bb98d42f8e0883ef82cd14cd2d5eda60:/antlr4-cpp-runtime-4.9.2-source/runtime/src/ANTLRErrorStrategy.h
diff --git a/antlr4-cpp-runtime-4.9.2-source/runtime/src/ANTLRErrorStrategy.h b/antlr4-cpp-runtime-4.9.2-source/runtime/src/ANTLRErrorStrategy.h
new file mode 100644
index 0000000..a3eecd1
--- /dev/null
+++ b/antlr4-cpp-runtime-4.9.2-source/runtime/src/ANTLRErrorStrategy.h
@@ -0,0 +1,121 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "Token.h"
+
+namespace antlr4 {
+
+ ///
+ /// The interface for defining strategies to deal with syntax errors encountered
+ /// during a parse by ANTLR-generated parsers. We distinguish between three
+ /// different kinds of errors:
+ ///
+ ///
+ /// - The parser could not figure out which path to take in the ATN (none of
+ /// the available alternatives could possibly match)
+ /// - The current input does not match what we were looking for
+ /// - A predicate evaluated to false
+ ///
+ ///
+ /// Implementations of this interface report syntax errors by calling
+ /// .
+ ///
+ /// TODO: what to do about lexers
+ ///
+ class ANTLR4CPP_PUBLIC ANTLRErrorStrategy {
+ public:
+
+ ///
+ /// Reset the error handler state for the specified {@code recognizer}.
+ /// the parser instance
+ virtual ~ANTLRErrorStrategy();
+
+ virtual void reset(Parser *recognizer) = 0;
+
+ /**
+ * This method is called when an unexpected symbol is encountered during an
+ * inline match operation, such as {@link Parser#match}. If the error
+ * strategy successfully recovers from the match failure, this method
+ * returns the {@link Token} instance which should be treated as the
+ * successful result of the match.
+ *
+ *
This method handles the consumption of any tokens - the caller should
+ * not call {@link Parser#consume} after a successful recovery.
+ *
+ * Note that the calling code will not report an error if this method
+ * returns successfully. The error strategy implementation is responsible
+ * for calling {@link Parser#notifyErrorListeners} as appropriate.
+ *
+ * @param recognizer the parser instance
+ * @throws RecognitionException if the error strategy was not able to
+ * recover from the unexpected input symbol
+ */
+ virtual Token* recoverInline(Parser *recognizer) = 0;
+
+ ///
+ /// This method is called to recover from exception {@code e}. This method is
+ /// called after by the default exception handler
+ /// generated for a rule method.
+ ///
+ ///
+ /// the parser instance
+ /// the recognition exception to recover from
+ /// if the error strategy could not recover from
+ /// the recognition exception
+ virtual void recover(Parser *recognizer, std::exception_ptr e) = 0;
+
+ ///
+ /// This method provides the error handler with an opportunity to handle
+ /// syntactic or semantic errors in the input stream before they result in a
+ /// .
+ ///
+ /// The generated code currently contains calls to after
+ /// entering the decision state of a closure block ({@code (...)*} or
+ /// {@code (...)+}).
+ ///
+ /// For an implementation based on Jim Idle's "magic sync" mechanism, see
+ /// .
+ ///
+ ///
+ /// the parser instance
+ /// if an error is detected by the error
+ /// strategy but cannot be automatically recovered at the current state in
+ /// the parsing process
+ virtual void sync(Parser *recognizer) = 0;
+
+ ///
+ /// Tests whether or not {@code recognizer} is in the process of recovering
+ /// from an error. In error recovery mode, adds
+ /// symbols to the parse tree by calling
+ /// {@link Parser#createErrorNode(ParserRuleContext, Token)} then
+ /// {@link ParserRuleContext#addErrorNode(ErrorNode)} instead of
+ /// {@link Parser#createTerminalNode(ParserRuleContext, Token)}.
+ ///
+ /// the parser instance
+ /// {@code true} if the parser is currently recovering from a parse
+ /// error, otherwise {@code false}
+ virtual bool inErrorRecoveryMode(Parser *recognizer) = 0;
+
+ ///
+ /// This method is called by when the parser successfully matches an input
+ /// symbol.
+ ///
+ /// the parser instance
+ virtual void reportMatch(Parser *recognizer) = 0;
+
+ ///
+ /// Report any kind of . This method is called by
+ /// the default exception handler generated for a rule method.
+ ///
+ /// the parser instance
+ /// the recognition exception to report
+ virtual void reportError(Parser *recognizer, const RecognitionException &e) = 0;
+ };
+
+} // namespace antlr4