本文整理匯總了Java中org.antlr.runtime.CommonToken.getStopIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java CommonToken.getStopIndex方法的具體用法?Java CommonToken.getStopIndex怎麽用?Java CommonToken.getStopIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.runtime.CommonToken
的用法示例。
在下文中一共展示了CommonToken.getStopIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkForSyntaxErrors
import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
private static void checkForSyntaxErrors(String text, String type,
SQLParser parser, ParserRuleReturnScope r) {
if (parser.getNumberOfSyntaxErrors() > 0)
throw new SyntaxError("Illegal " + type, text, -1, -1);
CommonToken stop = (CommonToken) r.stop;
if (text != null && stop.getStopIndex() < StringUtil.trimRight(text).length() - 1) {
if (stop.getStopIndex() == 0)
throw new SyntaxError("Syntax error after " + stop.getText(), text);
else
throw new SyntaxError("Syntax error at the beginning ", text);
}
}
示例2: getParserExceptionDetails
import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
public static String getParserExceptionDetails(RecognitionException e) {
StringBuilder sb = new StringBuilder();
if ((duplicate == null) || !duplicate.equals(e)) {
IntStream stream;
int line, position, length;
CommonToken token = (CommonToken) e.token;
String message = e.getMessage();
if (message != null) {
sb.append(message);
} else {
sb.append("Exception of type ").append(e.getClass().getCanonicalName());
}
if (token == null) {
stream = e.input;
line = e.line;
position = e.charPositionInLine;
length = 1;
} else {
sb.append(" at token ").append(token.getText());
stream = token.getInputStream();
line = token.getLine();
position = token.getCharPositionInLine();
length = token.getStopIndex() - token.getStartIndex();
}
String error = displayError(stream, line, position, length);
sb.append(error);
Throwable cause = e.getCause();
if (cause != null) {
sb.append("Caused by ").append(cause.getMessage()).append("\n");
}
}
duplicate = e;
return sb.toString();
}
示例3: getCommonTokenOffsetRange
import org.antlr.runtime.CommonToken; //導入方法依賴的package包/類
/**
* Returns a pointer to the start and end of the token image in the
* underlaying stream. The token.getStopIndex() points to the last character
* of the token which is a bit confusing.
*
* Use this method to get CommonToken's boundaries instead of using the
* getStart/StopIndex methods.
*
* @return two members array - arr[0] is the start offset, arr[1] is the end
* offset
*/
public static int[] getCommonTokenOffsetRange(CommonToken token) {
if (token.getType() == CommonToken.EOF) {
//"eof token" points at the end offset of the source, with zero length
return new int[]{token.getStartIndex(), token.getStopIndex()};
} else {
return new int[]{token.getStartIndex(), token.getStopIndex() + 1};
}
}