Java Code Examples for org.antlr.runtime.Token#getLine()
The following examples show how to use
org.antlr.runtime.Token#getLine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ANTLRUtil.java From ghidra with Apache License 2.0 | 6 votes |
public static void debugNodeStream(BufferedTreeNodeStream nodes, PrintStream out) { Iterator<Object> iterator = nodes.iterator(); int indent = 0; while (iterator.hasNext()) { Object object = iterator.next(); CommonTree node = (CommonTree) object; Token token = node.token; if (token != null) { if (token.getType() == 2) { ++indent; continue; } else if (token.getType() == 3) { --indent; continue; } } String line = token == null ? "no pos" : token.getLine() + ":" + token.getCharPositionInLine(); out.println(indent(indent) + "'" + object + "' (" + line + ")"); } }
Example 2
Source File: SemanticException.java From ZjDroid with Apache License 2.0 | 5 votes |
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { super(); this.input = input; this.token = token; this.index = ((CommonToken)token).getStartIndex(); this.line = token.getLine(); this.charPositionInLine = token.getCharPositionInLine(); this.errorMessage = String.format(errorMessage, messageArguments); }
Example 3
Source File: SemanticException.java From zjdroid with Apache License 2.0 | 5 votes |
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { super(); this.input = input; this.token = token; this.index = ((CommonToken)token).getStartIndex(); this.line = token.getLine(); this.charPositionInLine = token.getCharPositionInLine(); this.errorMessage = String.format(errorMessage, messageArguments); }
Example 4
Source File: GrammarSyntaxMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public GrammarSyntaxMessage(ErrorType etype, String fileName, Token offendingToken, RecognitionException antlrException, Object... args) { super(etype, antlrException, offendingToken, args); this.fileName = fileName; this.offendingToken = offendingToken; if ( offendingToken!=null ) { line = offendingToken.getLine(); charPosition = offendingToken.getCharPositionInLine(); } }
Example 5
Source File: GrammarSemanticsMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public GrammarSemanticsMessage(ErrorType etype, String fileName, Token offendingToken, Object... args) { super(etype,offendingToken,args); this.fileName = fileName; if ( offendingToken!=null ) { line = offendingToken.getLine(); charPosition = offendingToken.getCharPositionInLine(); } }
Example 6
Source File: SemanticException.java From AppTroy with Apache License 2.0 | 5 votes |
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { super(); this.input = input; this.token = token; this.index = ((CommonToken)token).getStartIndex(); this.line = token.getLine(); this.charPositionInLine = token.getCharPositionInLine(); this.errorMessage = String.format(errorMessage, messageArguments); }
Example 7
Source File: SemanticException.java From HeyGirl with Apache License 2.0 | 5 votes |
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { super(); this.input = input; this.token = token; this.index = ((CommonToken)token).getStartIndex(); this.line = token.getLine(); this.charPositionInLine = token.getCharPositionInLine(); this.errorMessage = String.format(errorMessage, messageArguments); }
Example 8
Source File: ErrorCollector.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Appends a query snippet to the message to help the user to understand the problem. * * @param from the first token to include within the snippet * @param to the last token to include within the snippet * @param offending the token which is responsible for the error */ final void appendSnippet(StringBuilder builder, Token from, Token to, Token offending) { if (!areTokensValid(from, to, offending)) return; String[] lines = query.split("\n"); boolean includeQueryStart = (from.getLine() == 1) && (from.getCharPositionInLine() == 0); boolean includeQueryEnd = (to.getLine() == lines.length) && (getLastCharPositionInLine(to) == lines[lines.length - 1].length()); builder.append(" ("); if (!includeQueryStart) builder.append("..."); lines[lineIndex(to)] = lines[lineIndex(to)].substring(0, getLastCharPositionInLine(to)); lines[lineIndex(offending)] = highlightToken(lines[lineIndex(offending)], offending); lines[lineIndex(from)] = lines[lineIndex(from)].substring(from.getCharPositionInLine()); for (int i = lineIndex(from), m = lineIndex(to); i <= m; i++) builder.append(lines[i]); if (!includeQueryEnd) builder.append("..."); builder.append(")"); }
Example 9
Source File: SemanticException.java From ZjDroid with Apache License 2.0 | 5 votes |
SemanticException(IntStream input, Token token, String errorMessage, Object... messageArguments) { super(); this.input = input; this.token = token; this.index = ((CommonToken)token).getStartIndex(); this.line = token.getLine(); this.charPositionInLine = token.getCharPositionInLine(); this.errorMessage = String.format(errorMessage, messageArguments); }
Example 10
Source File: CFParsedStatement.java From openbd-core with GNU General Public License v3.0 | 4 votes |
protected CFParsedStatement( Token t ) { this(t.getLine(), t.getCharPositionInLine()); }
Example 11
Source File: CFParsedStatement.java From openbd-core with GNU General Public License v3.0 | 4 votes |
public CFParsedStatement( Token t ) { this(t.getLine(), t.getCharPositionInLine()); }
Example 12
Source File: PigParserNode.java From spork with Apache License 2.0 | 4 votes |
public PigParserNode(Token t, String fileName, Token start) { this(t, fileName, 0); this.startLine = start.getLine(); }
Example 13
Source File: TokenTool.java From xtext-core with Eclipse Public License 2.0 | 2 votes |
/** * @param t the token * @return the line of the token or <code>-1</code> if the {@link Token} t was <code>null</code> or the token did not provide line information. */ public static int getLine(Token t) { return t!=null ? t.getLine() : -1; }
Example 14
Source File: ErrorCollector.java From stratio-cassandra with Apache License 2.0 | 2 votes |
/** * Checks that the specified token is valid. * * @param token the token to check * @return <code>true</code> if it is considered as valid, <code>false</code> otherwise. */ private static boolean isTokenValid(Token token) { return token.getLine() > 0 && token.getCharPositionInLine() >= 0; }
Example 15
Source File: ErrorCollector.java From stratio-cassandra with Apache License 2.0 | 2 votes |
/** * Returns the index of the line number on which this token was matched; index=0..n-1 * * @param token the token * @return the index of the line number on which this token was matched; index=0..n-1 */ private static int lineIndex(Token token) { return token.getLine() - 1; }