当前位置: 首页>>代码示例>>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;未经允许,请勿转载。