当前位置: 首页>>代码示例>>Java>>正文


Java Token.getLine方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:loganbraga,项目名称:hogwash,代码行数:22,代码来源:ModuleImporter.java

示例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;
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:Trainer.java

示例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);
}
 
开发者ID:SwiftAnalysis,项目名称:SwiftAnalyzer,代码行数:24,代码来源:ListenerUtil.java

示例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);

	}
}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:27,代码来源:Antlr4Utils.java

示例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;
}
 
开发者ID:xephonhq,项目名称:tsdb-proxy-java,代码行数:9,代码来源:Symbol.java

示例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());
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:11,代码来源:SqlParser.java

示例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());
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:11,代码来源:SqlParser.java

示例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();
}
 
开发者ID:rockscript,项目名称:rockscript,代码行数:8,代码来源:Location.java

示例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;
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:9,代码来源:IntervalParser.java

示例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() + "\""));
  }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:37,代码来源:ExpressionParser.java

示例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);
}
 
开发者ID:loganbraga,项目名称:hogwash,代码行数:14,代码来源:SinglePassPhase.java

示例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);
}
 
开发者ID:loganbraga,项目名称:hogwash,代码行数:31,代码来源:ModuleImporter.java

示例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));
    }
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:12,代码来源:UnaryExpression.java

示例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;
}
 
开发者ID:kasonyang,项目名称:kalang,代码行数:11,代码来源:OffsetRangeHelper.java

示例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;
}
 
开发者ID:yahoo,项目名称:yql-plus,代码行数:13,代码来源:ProgramParser.java


注:本文中的org.antlr.v4.runtime.Token.getLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。