List of usage examples for org.antlr.v4.runtime Token getCharPositionInLine
int getCharPositionInLine();
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 {//from w w w . ja va2 s. co m // 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:android.databinding.tool.store.Location.java
License:Apache License
public Location(Token start, Token end) { if (start == null) { startLine = startOffset = NaN;// w w w .ja v a 2 s . c om } 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(); }// w w w . j av a2 s.com 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);// w w w . j a v a2s . c o 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:ca.nines.ise.dom.DOMBuilder.java
License:Open Source License
/** * Set up a newly created node with information from the context. * * @param n// www .ja v a 2 s. c o m * @param ctx * @return Node */ // @TODO turn this into Node.Builder and provide a Node.builder() // etc. private Node setupNode(Node n, ParserRuleContext ctx) { Token t = ctx.getStart(); n.setOwner(dom); n.setLine(t.getLine()); n.setColumn(t.getCharPositionInLine()); n.setText(tokens.getText(ctx.getSourceInterval())); return n; }
From source file:cfml.parsing.cfscript.CFParsedStatement.java
License:Open Source License
public void setToken(Token t) { if (t != null) { line = t.getLine(); col = t.getCharPositionInLine() + 1; } token = t; }
From source file:cfml.parsing.cfscript.script.CFParsedStatement.java
License:Open Source License
protected CFParsedStatement(Token t) { this(t.getLine(), t.getCharPositionInLine()); token = t; }
From source file:ch.raffael.contracts.processor.cel.ast.Nodes.java
License:Apache License
@NotNull private static Position pos(@NotNull Token tok) { return new Position(tok.getLine(), tok.getCharPositionInLine()); }