本文整理汇总了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(")");
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}