List of usage examples for org.antlr.v4.runtime Token getLine
int getLine();
From source file:tnsnamesInterfaceListener.java
License:Open Source License
@Override public void enterEveryRule(ParserRuleContext ctx) { Token startToken = ctx.getStart(); if (startToken != null) { // Lines number from 1. this.lineNumber = startToken.getLine(); // Characters from zero. Adjust. this.charPosition = 1 + startToken.getCharPositionInLine(); } else {//w w w . ja v a 2s . c om // Just in case Token can ever be null. this.lineNumber = 0; this.charPosition = 0; } // Build a location string for error messages etc. this.whereAmI = "\tLine " + lineNumber + ":" + charPosition + " "; }
From source file:Alert.java
public static void error(String s, Token t) { if (t != null) System.out.println("ERROR: in line: " + t.getLine() + " : around: " + t.getText() + " :\t" + s); else//from w ww . j av a 2 s.c o m System.out.println("ERROR: " + s); }
From source file:Alert.java
public static void info(String s, Token t) { if (t != null) System.out.println("INFO: in line: " + t.getLine() + " : around: " + t.getText() + " :\t" + s); else/*w w w .j a v a 2s . co m*/ System.out.println("ERROR: " + s); }
From source file:alfa.util.Util.java
public static String At(Token token) { String s = " @ line:"; s += token.getLine(); s += " char: "; s += token.getTokenIndex();//from w w w . ja v a 2s . c o m return s; }
From source file:android.databinding.tool.store.Location.java
License:Apache License
public Location(Token start, Token end) { if (start == null) { startLine = startOffset = NaN;// w w w. j a v a 2s. co m } else { startLine = start.getLine() - 1; //token lines start from 1 startOffset = start.getCharPositionInLine(); } if (end == null) { endLine = endOffset = NaN; } else { endLine = end.getLine() - 1; // token lines start from 1 String endText = end.getText(); int lastLineStart = endText.lastIndexOf(System.lineSeparator()); String lastLine = lastLineStart < 0 ? endText : endText.substring(lastLineStart + 1); endOffset = end.getCharPositionInLine() + lastLine.length() - 1;//end is inclusive } }
From source file:android.databinding.tool.util.XmlEditor.java
License:Apache License
private static Position toPosition(Token token) { return new Position(token.getLine() - 1, token.getCharPositionInLine()); }
From source file:android.databinding.tool.util.XmlEditor.java
License:Apache License
private static Position toEndPosition(Token token) { return new Position(token.getLine() - 1, token.getCharPositionInLine() + token.getText().length()); }
From source file:annis.ql.parser.AnnisParserAntlr.java
License:Apache License
public static ParsedEntityLocation getLocation(Token start, Token stop) { if (start == null) { return new ParsedEntityLocation(); }//from w w w .ja v a 2 s. co m if (stop == null) { stop = start; } int startLine = start.getLine(); int endLine = stop.getLine(); int startColumn = start.getCharPositionInLine(); // We assume a token can be only one line (newline character is whitespace and a separator). // Thus the end column of a token is the start position plus its actual text length; String stopTokenText = stop.getText(); int endColumn = stop.getCharPositionInLine(); if (stopTokenText != null && !stopTokenText.isEmpty()) { endColumn += stopTokenText.length() - 1; } return new ParsedEntityLocation(startLine, startColumn, endLine, endColumn); }
From source file:annis.ql.parser.ListTokenSource.java
License:Apache License
public ListTokenSource(List<Token> token) { this.token = token; Preconditions.checkNotNull(token);//from w w w. java 2 s .co m Preconditions.checkArgument(!token.isEmpty(), "Internal token list must not be empty"); for (Token t : token) { if (t.getTokenSource() != null) { this.factory = t.getTokenSource().getTokenFactory(); break; } } Preconditions.checkNotNull(this.factory, "Internal token list needs a valid TokenSource"); Token lastToken = token.get(token.size() - 1); eofToken.setLine(lastToken.getLine()); eofToken.setCharPositionInLine(lastToken.getCharPositionInLine()); }
From source file:br.beholder.memelang.model.visitor.TreePrinterListener.java
@Override public void exitEveryRule(ParserRuleContext ctx) { if (ctx.getChildCount() > 0) { Token positionToken = ctx.getStart(); if (positionToken != null) { builder.append(" [line "); builder.append(positionToken.getLine()); builder.append(", offset "); builder.append(positionToken.getStartIndex()); builder.append(':'); builder.append(positionToken.getStopIndex()); builder.append("])"); } else {/*from w ww . ja va 2 s . com*/ builder.append(')'); } } }