本文整理汇总了Java中org.antlr.runtime.NoViableAltException类的典型用法代码示例。如果您正苦于以下问题:Java NoViableAltException类的具体用法?Java NoViableAltException怎么用?Java NoViableAltException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoViableAltException类属于org.antlr.runtime包,在下文中一共展示了NoViableAltException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ESCAPE
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u') return UNICODE();
String text;
switch ( c ) {
case '\\' : LINEBREAK(); return SKIP;
case 'n' : text = "\n"; break;
case 't' : text = "\t"; break;
case ' ' : text = " "; break;
default :
NoViableAltException e = new NoViableAltException("",0,0,input);
errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
consume();
match(delimiterStopChar);
return SKIP;
}
consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
match(delimiterStopChar);
return t;
}
示例2: getErrorMessage
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
@Override
public String getErrorMessage(RecognitionException e, String[] tokenNames) {
String msg = null;
if (e instanceof NoViableAltException) {
@SuppressWarnings("unused")
NoViableAltException nvae = (NoViableAltException) e;
// for development, can add
// "decision=<<"+nvae.grammarDecisionDescription+">>"
// and "(decision="+nvae.decisionNumber+") and
// "state "+nvae.stateNumber
msg = "character " + getCharErrorDisplay(e.c) + " not supported here";
} else {
msg = super.getErrorMessage(e, tokenNames);
}
return msg;
}
示例3: getErrorMessage
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
public String getErrorMessage(RecognitionException e,
String[] tokenNames)
{
List stack = getRuleInvocationStack(e, this.getClass().getName());
String msg = null;
if ( e instanceof NoViableAltException ) {
NoViableAltException nvae = (NoViableAltException)e;
msg = " no viable alt; token="+e.token+
" (decision="+nvae.decisionNumber+
" state "+nvae.stateNumber+")"+
" decision=<<"+nvae.grammarDecisionDescription+">>";
}
else {
msg = super.getErrorMessage(e, tokenNames);
}
return stack+" "+msg;
}
示例4: specialStateTransition
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
public int specialStateTransition(int s, IntStream _input) throws NoViableAltException {
TokenStream input = (TokenStream)_input;
int _s = s;
switch ( s ) {
case 0 :
int LA14_3 = input.LA(1);
int index14_3 = input.index();
input.rewind();
s = -1;
if ( (synpred9_InternalJavaJRExpression()) ) {s = 19;}
else if ( (true) ) {s = 4;}
input.seek(index14_3);
if ( s>=0 ) return s;
break;
}
if (state.backtracking>0) {state.failed=true; return -1;}
NoViableAltException nvae =
new NoViableAltException(getDescription(), 14, _s, input);
error(nvae);
throw nvae;
}
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:27,代码来源:InternalJavaJRExpressionParser.java
示例5: specialStateTransition
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
public int specialStateTransition(int s, IntStream _input) throws NoViableAltException {
TokenStream input = (TokenStream)_input;
int _s = s;
switch ( s ) {
case 0 :
int LA6_3 = input.LA(1);
int index6_3 = input.index();
input.rewind();
s = -1;
if ( (synpred10_InternalJavaJRExpression()) ) {s = 19;}
else if ( (true) ) {s = 4;}
input.seek(index6_3);
if ( s>=0 ) return s;
break;
}
if (state.backtracking>0) {state.failed=true; return -1;}
NoViableAltException nvae =
new NoViableAltException(getDescription(), 6, _s, input);
error(nvae);
throw nvae;
}
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:27,代码来源:InternalJavaJRExpressionParser.java
示例6: toString
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
@Override
public String toString()
{
if (trappedException instanceof MissingTokenException)
{
return "<missing type: " +
( (MissingTokenException)trappedException ).getMissingType() +
">";
} else if (trappedException instanceof UnwantedTokenException) {
return "<extraneous: " +
( (UnwantedTokenException)trappedException ).getUnexpectedToken() +
", resync=" + getText() + ">";
} else if (trappedException instanceof MismatchedTokenException) {
return "<mismatched token: " + trappedException.token + ", resync=" + getText() + ">";
} else if (trappedException instanceof NoViableAltException) {
return "<unexpected: " + trappedException.token +
", resync=" + getText() + ">";
}
return "<error: " + getText() + ">";
}
示例7: ESCAPE
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u') return UNICODE();
String text = null;
switch ( c ) {
case '\\' : LINEBREAK(); return SKIP;
case 'n' : text = "\n"; break;
case 't' : text = "\t"; break;
case ' ' : text = " "; break;
default :
NoViableAltException e = new NoViableAltException("",0,0,input);
errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
consume();
matchAndConsumeDelimiterStop();
return SKIP;
}
consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine()-2);
matchAndConsumeDelimiterStop();
return t;
}
示例8: createException
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
/**
* Method called in AntLR grammars for AntLR lexer to CLScript exceptions conversion
*
* @param e
* @return
*/
public RuntimeException createException(RecognitionException e) {
String message = "";
if (e instanceof NoViableAltException) {
message = "Syntax error. ";
} else if (e instanceof MissingTokenException) {
message = "Missing token ";
} else if (e instanceof UnwantedTokenException) {
UnwantedTokenException ex = (UnwantedTokenException) e;
ex.getUnexpectedToken().getText();
message = "Unkow token '" + ex.getUnexpectedToken().getText() + "' at line " + e.token.getLine() + ":" + e.token.getCharPositionInLine();
} else {
message = "Syntax error near ";
}
return new CLScriptException(message,e);
}
示例9: createException
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
/**
* Method called in AntLR grammars for AntLR parser to CLScript exceptions conversion
*
* @param e
* @return
*/
public RuntimeException createException(RecognitionException e) {
String message = "";
boolean addTokenAndLine = true;
if (e instanceof NoViableAltException) {
message = "Syntax error. ";
} else if (e instanceof MissingTokenException) {
message = "Missing token ";
} else if (e instanceof UnwantedTokenException) {
UnwantedTokenException ex = (UnwantedTokenException) e;
ex.getUnexpectedToken().getText();
message = "Unkow token '" + ex.getUnexpectedToken().getText() + "' at line " + e.token.getLine() + ":" + e.token.getCharPositionInLine();
addTokenAndLine = false;
} else if(e instanceof ParserHelperException){
message = e.toString();
}
else {
message = "Syntax error near ";
}
if (addTokenAndLine) {
message = message + "'" + e.token.getText() + "' at line " + e.token.getLine() + ":" + e.token.getCharPositionInLine();
}
return new CLScriptException(message,e);
}
示例10: allowASI
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
@Override
public boolean allowASI(final RecognitionException re) {
if (re instanceof NoViableAltException) {
final NoViableAltException nvae = (NoViableAltException) re;
if (asiRecoveredEx != null && re.index == asiRecoveredEx.index
&& nvae.decisionNumber == asiRecoveredEx.decisionNumber) {
return false;
}
asiRecoveredEx = nvae;
}
return true;
}
示例11: match
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
/** Consume if {@code x} is next character on the input stream.
*/
public void match(char x) {
if ( c!= x ) {
NoViableAltException e = new NoViableAltException("", 0, 0, input);
errMgr.lexerError(input.getSourceName(),
"expecting '" +x+"', found '"+str(c)+"'",
templateToken,
e);
}
consume();
}
示例12: ESCAPE
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u' ) return UNICODE();
String text;
switch (c) {
case '\\':
LINEBREAK();
return SKIP;
case 'n':
text = "\n";
break;
case 't':
text = "\t";
break;
case ' ':
text = " ";
break;
default:
NoViableAltException e = new NoViableAltException("", 0, 0, input);
errMgr.lexerError(input.getSourceName(),
"invalid escaped char: '" +str(c)+"'",
templateToken,
e);
consume();
match(delimiterStopChar);
return SKIP;
}
consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
match(delimiterStopChar);
return t;
}
示例13: ESCAPE
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u' ) return UNICODE();
String text;
switch (c) {
case '\\' :
LINEBREAK();
return SKIP;
case 'n' :
text = "\n";
break;
case 't' :
text = "\t";
break;
case ' ' :
text = " ";
break;
default:
NoViableAltException e = new NoViableAltException("", 0, 0, input);
errMgr.lexerError(input.getSourceName(),
"invalid escaped char: '" +str(c)+"'",
templateToken,
e);
consume();
match(delimiterStopChar);
return SKIP;
}
consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
match(delimiterStopChar);
return t;
}
示例14: match
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
/** Consume if {@code x} is next character on the input stream.
*/
public void match(char x) {
if ( c!= x ) {
NoViableAltException e = new NoViableAltException("", 0, 0, input);
errMgr.lexerError(input.getSourceName(), "expecting '"+x+"', found '"+str(c)+"'", templateToken, e);
}
consume();
}
示例15: ESCAPE
import org.antlr.runtime.NoViableAltException; //导入依赖的package包/类
Token ESCAPE() {
startCharIndex = input.index();
startCharPositionInLine = input.getCharPositionInLine();
consume(); // kill \\
if ( c=='u' ) return UNICODE();
String text;
switch (c) {
case '\\' :
LINEBREAK();
return SKIP;
case 'n' :
text = "\n";
break;
case 't' :
text = "\t";
break;
case ' ' :
text = " ";
break;
default:
NoViableAltException e = new NoViableAltException("", 0, 0, input);
errMgr.lexerError(input.getSourceName(), "invalid escaped char: '"+str(c)+"'", templateToken, e);
consume();
match(delimiterStopChar);
return SKIP;
}
consume();
Token t = newToken(TEXT, text, input.getCharPositionInLine() -2);
match(delimiterStopChar);
return t;
}