]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/LexerNoViableAltException.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / LexerNoViableAltException.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 "misc/Interval.h"
7 #include "support/CPPUtils.h"
8 #include "CharStream.h"
9 #include "Lexer.h"
10
11 #include "LexerNoViableAltException.h"
12
13 using namespace antlr4;
14
15 LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex,
16                                                      atn::ATNConfigSet *deadEndConfigs)
17   : RecognitionException(lexer, input, nullptr, nullptr), _startIndex(startIndex), _deadEndConfigs(deadEndConfigs) {
18 }
19
20 size_t LexerNoViableAltException::getStartIndex() {
21   return _startIndex;
22 }
23
24 atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() {
25   return _deadEndConfigs;
26 }
27
28 std::string LexerNoViableAltException::toString() {
29   std::string symbol;
30   if (_startIndex < getInputStream()->size()) {
31     symbol = static_cast<CharStream *>(getInputStream())->getText(misc::Interval(_startIndex, _startIndex));
32     symbol = antlrcpp::escapeWhitespace(symbol, false);
33   }
34   std::string format = "LexerNoViableAltException('" + symbol + "')";
35   return format;
36 }