本文整理汇总了Java中org.antlr.v4.runtime.Token.getLine方法的典型用法代码示例。如果您正苦于以下问题:Java Token.getLine方法的具体用法?Java Token.getLine怎么用?Java Token.getLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.Token
的用法示例。
在下文中一共展示了Token.getLine方法的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: getMatchingSymbolEndsLine
import org.antlr.v4.runtime.Token; //导入方法依赖的package包/类
public static int getMatchingSymbolEndsLine(Corpus corpus,
InputDocument doc,
TerminalNode node)
{
TerminalNode matchingLeftNode = getMatchingLeftSymbol(corpus, doc, node);
if ( matchingLeftNode != null ) {
Token matchingLeftToken = matchingLeftNode.getSymbol();
int i = matchingLeftToken.getTokenIndex();
Token tokenAfterMatchingToken = doc.tokens.getNextRealToken(i);
// System.out.printf("doc=%s node=%s, pair=%s, after=%s\n",
// new File(doc.fileName).getName(), node.getSymbol(), matchingLeftToken, tokenAfterMatchingToken);
if ( tokenAfterMatchingToken!=null ) {
if ( tokenAfterMatchingToken.getType()==Token.EOF ) {
return 1;
}
return tokenAfterMatchingToken.getLine()>matchingLeftToken.getLine() ? 1 : 0;
}
}
return NOT_PAIR;
}
示例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: print
import org.antlr.v4.runtime.Token; //导入方法依赖的package包/类
public static void print(final ParseTree node, final int level, CommonTokenStream stream) {
final Interval sourceInterval = node.getSourceInterval();
final Token firstToken = stream.get(sourceInterval.a);
int line = firstToken.getLine();
int charStart = firstToken.getCharPositionInLine();
int endLine = line;
int endChar = charStart + firstToken.getText().length();
String data = "@(" + line + ":" + charStart + "," + endLine + ":" + endChar + ") with text: "
+ firstToken.getText();
final int tmp = level + 1;
final StringBuilder sb = new StringBuilder();
sb.append(StringUtils.repeat("\t", level));
sb.append(node.getClass().getSimpleName() + ": " + data + " :" + node.getText());
System.out.println(sb.toString());
final int n = node.getChildCount();
for (int i = 0; i < n; i++) {
final ParseTree c = node.getChild(i);
print(c, tmp, stream);
}
}
示例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: Location
import org.antlr.v4.runtime.Token; //导入方法依赖的package包/类
public Location(ParserRuleContext parserRuleContext) {
Token start = parserRuleContext.getStart();
this.start = start.getStartIndex();
Token stop = parserRuleContext.getStop();
end = stop.getStopIndex();
line = start.getLine();
}
示例9: 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;
}
示例10: 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() + "\""));
}
}
示例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: requireNonNull
import org.antlr.v4.runtime.Token; //导入方法依赖的package包/类
private static Expression requireNonNull(Expression expression, Token token) {
if (expression != null) {
return expression;
} else {
final int line = token.getLine();
final int positionInLine = token.getCharPositionInLine();
final String msg = "Invalid expression (line: " + line + ", column: " + positionInLine + ")";
final SyntaxError syntaxError = new SyntaxError(token.getText(), line, positionInLine, msg, null);
throw new ParseException(Collections.singleton(syntaxError));
}
}
示例14: 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;
}
示例15: 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;
}