本文整理汇总了Java中org.antlr.runtime.MissingTokenException类的典型用法代码示例。如果您正苦于以下问题:Java MissingTokenException类的具体用法?Java MissingTokenException怎么用?Java MissingTokenException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MissingTokenException类属于org.antlr.runtime包,在下文中一共展示了MissingTokenException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: toString
import org.antlr.runtime.MissingTokenException; //导入依赖的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() + ">";
}
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:21,代码来源:ANTLRErrorProvidingParser.java
示例2: createException
import org.antlr.runtime.MissingTokenException; //导入依赖的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);
}
开发者ID:asupdev,项目名称:asup,代码行数:24,代码来源:LexerHelper.java
示例3: createException
import org.antlr.runtime.MissingTokenException; //导入依赖的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);
}
开发者ID:asupdev,项目名称:asup,代码行数:30,代码来源:ParserHelper.java
示例4: testVector
import org.antlr.runtime.MissingTokenException; //导入依赖的package包/类
@Test
public void testVector() throws RecognitionException
{
runParser("[.5, 2.23, .17];");
assertNoError();
assertEquals(TraciParser.BLOCK, parseTree.getType());
assertEquals(1, parseTree.getChildCount());
Tree node = parseTree.getChild(0);
assertEquals(TraciParser.VECTOR, node.getType());
assertEquals(2, node.getChildCount());
assertEquals(TraciParser.LBRACKET, node.getChild(0).getType());
node = node.getChild(1);
assertEquals(TraciParser.ARGS, node.getType());
assertEquals(3, node.getChildCount());
runParser("[.5, 2.23, .17;");
assertError(MissingTokenException.class);
runParser("[.5, 2.23 .17];");
assertError(MissingTokenException.class);
runParser("[.5, 2.23];");
assertError(MismatchedTokenException.class);
runParser("[.5, 2.23, .17, 5];");
assertError(MismatchedTokenException.class);
assertError(UnwantedTokenException.class);
}
开发者ID:erikpe,项目名称:traci,代码行数:29,代码来源:TraciParserTest.java
示例5: testColor
import org.antlr.runtime.MissingTokenException; //导入依赖的package包/类
@Test
public void testColor() throws RecognitionException
{
runParser("color [.5, 2.23, .17];");
assertNoError();
assertEquals(TraciParser.BLOCK, parseTree.getType());
assertEquals(1, parseTree.getChildCount());
Tree node = parseTree.getChild(0);
assertEquals(TraciParser.COLOR, node.getType());
assertEquals(1, node.getChildCount());
node = node.getChild(0);
assertEquals(TraciParser.ARGS, node.getType());
assertEquals(3, node.getChildCount());
runParser("color [.5, 2.23, .17, .5];");
assertNoError();
assertEquals(TraciParser.BLOCK, parseTree.getType());
assertEquals(1, parseTree.getChildCount());
node = parseTree.getChild(0);
assertEquals(TraciParser.COLOR, node.getType());
assertEquals(1, node.getChildCount());
node = node.getChild(0);
assertEquals(TraciParser.ARGS, node.getType());
assertEquals(4, node.getChildCount());
runParser("color [.5, 2.23, .17;");
assertError(MissingTokenException.class);
runParser("color [.5, 2.23 .17];");
assertError(MissingTokenException.class);
runParser("color color [.5, 2.23, .17];");
assertError(UnwantedTokenException.class);
runParser("color [.5, 2.23];");
assertError(MismatchedTokenException.class);
runParser("color [.5, 2.23, .17, 5, 7];");
assertError(MismatchedTokenException.class);
assertError(UnwantedTokenException.class);
}
开发者ID:erikpe,项目名称:traci,代码行数:42,代码来源:TraciParserTest.java
注:本文中的org.antlr.runtime.MissingTokenException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论