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


Java Token.getLine方法代碼示例

本文整理匯總了Java中org.antlr.runtime.Token.getLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getLine方法的具體用法?Java Token.getLine怎麽用?Java Token.getLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.runtime.Token的用法示例。


在下文中一共展示了Token.getLine方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: appendSnippet

import org.antlr.runtime.Token; //導入方法依賴的package包/類
/**
 * Appends a query snippet to the message to help the user to understand the problem.
 *
 * @param from the first token to include within the snippet
 * @param to the last token to include within the snippet
 * @param offending the token which is responsible for the error
 */
final void appendSnippet(StringBuilder builder,
                         Token from,
                         Token to,
                         Token offending)
{
    if (!areTokensValid(from, to, offending))
        return;

    String[] lines = query.split("\n");

    boolean includeQueryStart = (from.getLine() == 1) && (from.getCharPositionInLine() == 0);
    boolean includeQueryEnd = (to.getLine() == lines.length)
            && (getLastCharPositionInLine(to) == lines[lines.length - 1].length());

    builder.append(" (");

    if (!includeQueryStart)
        builder.append("...");

    String toLine = lines[lineIndex(to)];
    int toEnd = getLastCharPositionInLine(to);
    lines[lineIndex(to)] = toEnd >= toLine.length() ? toLine : toLine.substring(0, toEnd);
    lines[lineIndex(offending)] = highlightToken(lines[lineIndex(offending)], offending);
    lines[lineIndex(from)] = lines[lineIndex(from)].substring(from.getCharPositionInLine());

    for (int i = lineIndex(from), m = lineIndex(to); i <= m; i++)
        builder.append(lines[i]);

    if (!includeQueryEnd)
        builder.append("...");

    builder.append(")");
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:41,代碼來源:ErrorCollector.java

示例2: SemanticException

import org.antlr.runtime.Token; //導入方法依賴的package包/類
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) {
    super();
    this.input = input;
    this.token = token;
    this.index = ((CommonToken)token).getStartIndex();
    this.line = token.getLine();
 this.charPositionInLine = token.getCharPositionInLine();
    this.errorMessage = String.format(errorMessage, messageArguments);
}
 
開發者ID:Miracle963,項目名稱:zjdroid,代碼行數:10,代碼來源:SemanticException.java

示例3: GrammarSyntaxMessage

import org.antlr.runtime.Token; //導入方法依賴的package包/類
public GrammarSyntaxMessage(ErrorType etype,
							String fileName,
							Token offendingToken,
							RecognitionException antlrException,
							Object... args)
{
	super(etype, antlrException, offendingToken, args);
	this.fileName = fileName;
	this.offendingToken = offendingToken;
	if ( offendingToken!=null ) {
		line = offendingToken.getLine();
		charPosition = offendingToken.getCharPositionInLine();
	}
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:15,代碼來源:GrammarSyntaxMessage.java

示例4: GrammarSemanticsMessage

import org.antlr.runtime.Token; //導入方法依賴的package包/類
public GrammarSemanticsMessage(ErrorType etype,
                                 String fileName,
                                 Token offendingToken,
                                 Object... args)
  {
      super(etype,offendingToken,args);
      this.fileName = fileName;
if ( offendingToken!=null ) {
          line = offendingToken.getLine();
          charPosition = offendingToken.getCharPositionInLine();
      }
  }
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:13,代碼來源:GrammarSemanticsMessage.java

示例5: printTokenDetails

import org.antlr.runtime.Token; //導入方法依賴的package包/類
public static String printTokenDetails(Token token)
{
    return token.getText() + " at line " + token.getLine() + " and position " + token.getCharPositionInLine();
}
 
開發者ID:jnoessner,項目名稱:rockIt,代碼行數:5,代碼來源:Messages.java

示例6: isTokenValid

import org.antlr.runtime.Token; //導入方法依賴的package包/類
/**
 * Checks that the specified token is valid.
 *
 * @param token the token to check
 * @return <code>true</code> if it is considered as valid, <code>false</code> otherwise.
 */
private static boolean isTokenValid(Token token)
{
    return token.getLine() > 0 && token.getCharPositionInLine() >= 0;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:11,代碼來源:ErrorCollector.java

示例7: lineIndex

import org.antlr.runtime.Token; //導入方法依賴的package包/類
/**
 * Returns the index of the line number on which this token was matched; index=0..n-1
 *
 * @param token the token
 * @return the index of the line number on which this token was matched; index=0..n-1
 */
private static int lineIndex(Token token)
{
    return token.getLine() - 1;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:11,代碼來源:ErrorCollector.java

示例8: getLine

import org.antlr.runtime.Token; //導入方法依賴的package包/類
/**
 * @param t the token
 * @return the line of the token or <code>-1</code> if the {@link Token} t was <code>null</code> or the token did not provide line information.
 */
public static int getLine(Token t) {
	return  t!=null ? t.getLine() : -1;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:8,代碼來源:TokenTool.java


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