本文整理匯總了Java中org.antlr.v4.runtime.Token.getCharPositionInLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getCharPositionInLine方法的具體用法?Java Token.getCharPositionInLine怎麽用?Java Token.getCharPositionInLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.v4.runtime.Token
的用法示例。
在下文中一共展示了Token.getCharPositionInLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: exitImportDecl
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitImportDecl(HogwashParser.ImportDeclContext ctx) {
Token tk = ctx.IMPORT().getSymbol();
String path = ctx.string().StringLit().getText().substring(1);
path = path.substring(0, path.length() - 1);
try {
ImportDirective id = new ImportDirective(path, this.currentFile);
id.setToken(tk);
this.imports.add(id);
} catch (ModuleNotFoundException e) {
ErrorMessage message = new ErrorMessage(ErrorKind.MODULE_NOT_FOUND, path);
int line = tk.getLine();
int charPosStart = tk.getCharPositionInLine();
int charPosStop = charPosStart + tk.getText().length() - 1;
String input = tk.getInputStream().toString();
String inputName = ((NamedInputStream) tk.getInputStream()).getName();
BaseError error = new LineCharError(message, inputName,
input, line, charPosStart, charPosStart, charPosStop);
this.er.addError(error);
}
}
示例2: getInjectWSCategory
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static int getInjectWSCategory(CodeBuffTokenStream tokens, int i) {
int precedingNL = getPrecedingNL(tokens, i); // how many lines to inject
Token curToken = tokens.get(i);
Token prevToken = tokens.getPreviousRealToken(i);
int ws = 0;
if ( precedingNL==0 ) {
ws = curToken.getCharPositionInLine() -
(prevToken.getCharPositionInLine()+prevToken.getText().length());
}
int injectNL_WS = CAT_NO_WS;
if ( precedingNL>0 ) {
injectNL_WS = nlcat(precedingNL);
}
else if ( ws>0 ) {
injectNL_WS = wscat(ws);
}
return injectNL_WS;
}
示例3: getEndOfMultilineComment
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
/**
* Returns location of the end multiline comment symbol.
*
* @param comment A token representing a comment
* @return Location of the end symbol
*/
public static Location getEndOfMultilineComment(Token comment) {
String commentText = comment.getText();
if (commentText.charAt(commentText.length() - 1) == '\n') {
commentText = commentText.substring(0, commentText.length() - 1);
}
int numNewlines = 0;
int lastNewlineIndex = -1;
for (int i = 0; i < commentText.length(); i++) {
if (commentText.charAt(i) == '\n') {
lastNewlineIndex = i;
numNewlines += 1;
}
}
String lastLine = commentText.substring(lastNewlineIndex + 1);
return new Location(comment.getLine() + numNewlines,
numNewlines == 0 ? comment.getCharPositionInLine() + lastLine.length() - 1 : lastLine.length() - 1);
}
示例4: initIfFirstRun
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private void initIfFirstRun() {
if (indentations.isEmpty()) {
indentations.push(0);
// First invocation. Look for the first non-NL. Enqueue it, and possibly an indentation if that non-NL
// token doesn't start at char 0.
Token firstRealToken;
do {
firstRealToken = pullToken();
}
while(firstRealToken.getType() == nlToken);
if (firstRealToken.getCharPositionInLine() > 0) {
indentations.push(firstRealToken.getCharPositionInLine());
dentsBuffer.add(createToken(indentToken, firstRealToken));
}
dentsBuffer.add(firstRealToken);
}
}
示例5: Symbol
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public Symbol(Token token) {
this.id = token.getText();
line = token.getLine();
// TODO: do we need + 1? since in a lot of editors column and line all starts from 1
// in ANTLR line starts from 1, but char index start from 0
column = token.getCharPositionInLine();
type = DataType.UNDEFINED_TYPE;
}
示例6: exitBackQuotedIdentifier
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitBackQuotedIdentifier(SqlBaseParser.BackQuotedIdentifierContext context)
{
Token token = context.BACKQUOTED_IDENTIFIER().getSymbol();
throw new ParsingException(
"backquoted identifiers are not supported; use double quotes to quote identifiers",
null,
token.getLine(),
token.getCharPositionInLine());
}
示例7: exitDigitIdentifier
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitDigitIdentifier(SqlBaseParser.DigitIdentifierContext context)
{
Token token = context.DIGIT_IDENTIFIER().getSymbol();
throw new ParsingException(
"identifiers must not start with a digit; surround the identifier with double quotes",
null,
token.getLine(),
token.getCharPositionInLine());
}
示例8: parsePositive
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private int parsePositive(Token token) {
int number = Integer.parseInt(token.getText());
if (number < 0) {
throw new ParseRuntimeException(new ParseException(token.getLine(),
token.getCharPositionInLine(), "Interval boundary must be positive."));
}
return number;
}
示例9: binaryOperationFromToken
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private BinaryFunctionExpr.Op binaryOperationFromToken(Token token) {
switch (token.getType()) {
case CellExpressionLexer.EQUALS:
return BinaryFunctionExpr.Op.EQUALS;
case CellExpressionLexer.NOT_EQUALS:
return BinaryFunctionExpr.Op.NOT_EQUALS;
case CellExpressionLexer.GREATER_THAN:
return BinaryFunctionExpr.Op.GREATER_THAN;
case CellExpressionLexer.GREATER_EQUALS:
return BinaryFunctionExpr.Op.GREATER_EQUALS;
case CellExpressionLexer.LESS_THAN:
return BinaryFunctionExpr.Op.LESS_THAN;
case CellExpressionLexer.LESS_EQUALS:
return BinaryFunctionExpr.Op.LESS_EQUALS;
case CellExpressionLexer.AND:
return BinaryFunctionExpr.Op.AND;
case CellExpressionLexer.OR:
return BinaryFunctionExpr.Op.OR;
case CellExpressionLexer.XOR:
return BinaryFunctionExpr.Op.XOR;
case CellExpressionLexer.PLUS:
return BinaryFunctionExpr.Op.PLUS;
case CellExpressionLexer.MINUS:
return BinaryFunctionExpr.Op.MINUS;
case CellExpressionLexer.MULT:
return BinaryFunctionExpr.Op.MULTIPLICATION;
case CellExpressionLexer.DIV:
return BinaryFunctionExpr.Op.DIVISION;
case CellExpressionLexer.MOD:
return BinaryFunctionExpr.Op.MODULO;
default:
throw new ParseRuntimeException(
new ParseException(token.getLine(), token.getCharPositionInLine(),
"Unsupported singlesided operation: \"" + token.getType() + "\""));
}
}
示例10: generateError
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
protected void generateError(Token token, ErrorMessage message) {
int line = token.getLine();
int charPos = token.getCharPositionInLine();
int charPosStop = charPos + token.getText().length() - 1;
String input = token.getInputStream().toString();
String inputName = ((NamedInputStream) token.getInputStream()).getName();
BaseError warn = new LineCharError(message, inputName,
input, line, charPos, charPos, charPosStop);
warn.setLevel(ErrorLevel.WARNING);
this.er.addError(warn);
}
示例11: generateError
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
protected void generateError(Token token, ErrorMessage message, ErrorLevel level) {
int line = token.getLine();
int charPosStart = token.getCharPositionInLine();
int charPosStop = charPosStart + token.getText().length() - 1;
String input = token.getInputStream().toString();
String inputName = ((NamedInputStream) token.getInputStream()).getName();
BaseError error = new LineCharError(message, inputName,
input, line, charPosStart, charPosStart, charPosStop);
error.setLevel(level);
this.er.addError(error);
}
示例12: importModules
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
protected void importModules() {
int maxErrors = this.er.getMaxErrors();
this.er.setMaxErrors(1);
for (ImportDirective id : this.imports) {
try {
this.st.addImport(id.getPath());
} catch (ModuleAlreadyImportedException e) {
ErrorMessage message = new ErrorMessage(
ErrorKind.REDUNDANT_IMPORT, id.getPath());
Token tk = id.getToken();
int line = tk.getLine();
int charPosStart = tk.getCharPositionInLine();
int charPosStop = charPosStart + tk.getText().length() - 1;
String input = tk.getInputStream().toString();
String inputName = ((NamedInputStream) tk.getInputStream()).getName();
BaseError error = new LineCharError(message, inputName,
input, line, charPosStart, charPosStart, charPosStop);
error.setLevel(ErrorLevel.WARNING);
this.er.addError(error);
continue;
}
Compiler compiler = new Compiler(id.getPath(), this.er, this.st);
compiler.compile();
this.cleanSymbolTable();
}
this.er.setMaxErrors(maxErrors);
}
示例13: getOffsetRange
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static OffsetRange getOffsetRange(Token start, Token stop) {
OffsetRange offset = new OffsetRange();
offset.startOffset = start.getStartIndex();
offset.stopOffset = stop.getStopIndex();
offset.startLine = start.getLine();
offset.startLineColumn = start.getCharPositionInLine();
offset.stopLine = stop.getLine();
offset.stopLineColumn = stop.getCharPositionInLine();
return offset;
}
示例14: toLocation
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private Location toLocation(Scope scope, ParseTree node) {
Token start;
if (node instanceof ParserRuleContext) {
start = ((ParserRuleContext) node).start;
} else if (node instanceof TerminalNode) {
start = ((TerminalNode) node).getSymbol();
} else {
throw new ProgramCompileException("Location is not available for type " + node.getClass());
}
Location location = new Location(scope != null ? scope.programName : "<string>", start.getLine(), start.getCharPositionInLine());
return location;
}
示例15: align
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public void align(int alignOrIndent, TerminalNode node) {
int[] deltaChild = Trainer.triple(alignOrIndent);
int deltaFromAncestor = deltaChild[0];
int childIndex = deltaChild[1];
ParserRuleContext earliestLeftAncestor = earliestAncestorStartingWithToken(node);
ParserRuleContext ancestor = Trainer.getAncestor(earliestLeftAncestor, deltaFromAncestor);
Token start = null;
if ( ancestor==null ) {
// System.err.println("Whoops. No ancestor at that delta");
}
else {
ParseTree child = ancestor.getChild(childIndex);
if (child instanceof ParserRuleContext) {
start = ((ParserRuleContext) child).getStart();
}
else if (child instanceof TerminalNode) {
start = ((TerminalNode) child).getSymbol();
}
else {
// uh oh.
// System.err.println("Whoops. Tried to access invalid child");
}
}
if ( start!=null ) {
int indentCol = start.getCharPositionInLine();
charPosInLine = indentCol;
output.append(Tool.spaces(indentCol));
}
}