本文整理匯總了Java中org.antlr.runtime.Token.getCharPositionInLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getCharPositionInLine方法的具體用法?Java Token.getCharPositionInLine怎麽用?Java Token.getCharPositionInLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.runtime.Token
的用法示例。
在下文中一共展示了Token.getCharPositionInLine方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getLastCharPositionInLine
import org.antlr.runtime.Token; //導入方法依賴的package包/類
/**
* Returns the index of the last character relative to the beginning of the line 0..n-1
*
* @param token the token
* @return the index of the last character relative to the beginning of the line 0..n-1
*/
private static int getLastCharPositionInLine(Token token)
{
return token.getCharPositionInLine() + getLength(token);
}