當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。