summaryrefslogtreecommitdiffstats
path: root/lib/antlr/src/NoViableAltException.cpp
blob: 67406df770027e9ce0a22d5d12f9fddb2951fd89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ANTLR Translator Generator
 * Project led by Terence Parr at http://www.jGuru.com
 * Software rights: http://www.antlr.org/license.html
 *
 * $Id$
 */

#include "antlr/NoViableAltException.h"
#include "antlr/String.h"

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
namespace antlr {
#endif

ANTLR_USING_NAMESPACE(std)

NoViableAltException::NoViableAltException(RefAST t)
  : RecognitionException("NoViableAlt","<AST>",-1,-1),
    token(0), node(t)
{
}

NoViableAltException::NoViableAltException(
	RefToken t,
	const ANTLR_USE_NAMESPACE(std)string& fileName_
) : RecognitionException("NoViableAlt",fileName_,t->getLine(),t->getColumn()),
    token(t), node(nullASTptr)
{
}

ANTLR_USE_NAMESPACE(std)string NoViableAltException::getMessage() const
{
	if (token)
	{
		if( token->getType() == Token::EOF_TYPE )
			return string("unexpected end of file");
		else if( token->getType() == Token::NULL_TREE_LOOKAHEAD )
			return string("unexpected end of tree");
		else
			return string("unexpected token: ")+token->getText();
	}

	// must a tree parser error if token==null
	if (!node)
		return "unexpected end of subtree";

	return string("unexpected AST node: ")+node->toString();
}

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
}
#endif