]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/NoViableAltException.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / NoViableAltException.cpp
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.
4  */
5
6 #include "Parser.h"
7
8 #include "NoViableAltException.h"
9
10 using namespace antlr4;
11
12 namespace {
13
14 // Create a normal shared pointer if the configurations are to be deleted. If not, then
15 // the shared pointer is created with a deleter that does nothing.
16 Ref<atn::ATNConfigSet> buildConfigsRef(atn::ATNConfigSet *configs, bool deleteConfigs) {
17   if (deleteConfigs) {
18     return Ref<atn::ATNConfigSet>(configs);
19   } else {
20     return Ref<atn::ATNConfigSet>(configs, [](atn::ATNConfigSet *){});
21   }
22 }
23
24 }
25
26 NoViableAltException::NoViableAltException(Parser *recognizer)
27   : NoViableAltException(recognizer, recognizer->getTokenStream(), recognizer->getCurrentToken(),
28                          recognizer->getCurrentToken(), nullptr, recognizer->getContext(), false) {
29 }
30
31 NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken,
32   Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs)
33   : RecognitionException("No viable alternative", recognizer, input, ctx, offendingToken),
34     _deadEndConfigs(buildConfigsRef(deadEndConfigs, deleteConfigs)), _startToken(startToken) {
35 }
36
37 NoViableAltException::~NoViableAltException() {
38 }
39
40 Token* NoViableAltException::getStartToken() const {
41   return _startToken;
42 }
43
44 atn::ATNConfigSet* NoViableAltException::getDeadEndConfigs() const {
45   return _deadEndConfigs.get();
46 }