當前位置: 首頁>>代碼示例>>Java>>正文


Java CommonToken.getStopIndex方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:aravindc,項目名稱:jdbacl,代碼行數:13,代碼來源:SQLParserUtil.java

示例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();
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:39,代碼來源:ErrorHandler.java

示例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};
    }

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CommonTokenUtil.java


注:本文中的org.antlr.runtime.CommonToken.getStopIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。