List of usage examples for org.antlr.v4.runtime Token getStartIndex
int getStartIndex();
From source file:groovy.ui.text.SmartDocumentFilter.java
License:Apache License
private List<Token> findTokensToRender(List<Token> tokenList) { int tokenListSize = tokenList.size(); int latestTokenListSize = latestTokenList.size(); if (0 == tokenListSize || 0 == latestTokenListSize) { return tokenList; }/*from w w w . j a va 2 s . c o m*/ int startTokenIndex = 0; int minSize = Math.min(tokenListSize, latestTokenListSize); for (int i = 0; i < minSize; i++) { Token token = tokenList.get(i); Token latestToken = latestTokenList.get(i); if (token.getType() == latestToken.getType() && token.getStartIndex() == latestToken.getStartIndex() && token.getStopIndex() == latestToken.getStopIndex()) { continue; } startTokenIndex = i; break; } List<Token> newTokenList = new ArrayList<>(tokenList); List<Token> newLatestTokenList = new ArrayList<>(latestTokenList); Collections.reverse(newTokenList); Collections.reverse(newLatestTokenList); int stopTokenIndex = tokenListSize; Token lastToken = newTokenList.get(0); Token lastLatestToken = newLatestTokenList.get(0); for (int i = 0; i < minSize; i++) { Token token = newTokenList.get(i); Token latestToken = newLatestTokenList.get(i); if ((token.getType() == latestToken.getType()) && (token.getStartIndex() - lastToken.getStartIndex()) == (latestToken.getStartIndex() - lastLatestToken.getStartIndex()) && ((token.getStopIndex() - lastToken.getStopIndex()) == (latestToken.getStopIndex() - lastLatestToken.getStopIndex()))) { continue; } stopTokenIndex = tokenListSize - i; break; } if (startTokenIndex <= stopTokenIndex) { return tokenList.subList(startTokenIndex, stopTokenIndex); } return Collections.emptyList(); }
From source file:jetbrick.template.parser.JetTemplateErrorListener.java
License:Open Source License
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { CommonTokenStream tokens = (CommonTokenStream) recognizer.getInputStream(); String input = tokens.getTokenSource().getInputStream().toString(); String[] sourceLines = input.split("\r?\n", -1); Token offendingToken = (Token) offendingSymbol; StringBuilder sb = new StringBuilder(128); sb.append("Template parse failed.\n"); sb.append(recognizer.getInputStream().getSourceName()); sb.append(':'); sb.append(line);/*from w ww. j ava 2s. c o m*/ sb.append("\nmessage: "); sb.append(msg); sb.append('\n'); sb.append(StringUtils.getPrettyError(sourceLines, line, charPositionInLine + 1, offendingToken.getStartIndex(), offendingToken.getStopIndex(), 5)); if (e != null) { throw new SyntaxErrorException(sb.toString(), e); } else { throw new SyntaxErrorException(sb.toString()); } }
From source file:kr.simula.formula.ide.ast.SyntaxErrorAdapter.java
License:Apache License
protected static IProblem makeProblem(String fileName, String msg, RecognitionException e) { Token offendingToken = e.getOffendingToken(); IProblem problem = new DefaultProblem(fileName, msg, IProblem.Internal, new String[0], ProblemSeverities.Fatal, offendingToken.getLine(), offendingToken.getCharPositionInLine(), offendingToken.getStartIndex(), offendingToken.getStopIndex()); return problem; }
From source file:languageTools.parser.InputStreamPosition.java
License:Open Source License
/** * TODO/* ww w . ja v a 2 s. c om*/ * * @param start * @param stop * @param sourceFile */ public InputStreamPosition(Token start, Token stop, File sourceFile) { this(start.getLine(), start.getCharPositionInLine(), start.getStartIndex(), stop.getStopIndex(), sourceFile); }
From source file:mbtarranger.editors.GenericEditor.java
License:Open Source License
private static void highlight(IEditorPart editorPart, org.antlr.v4.runtime.Token startCtx, org.antlr.v4.runtime.Token stopCtx) { if (!(editorPart instanceof ITextEditor)) { return;/* w ww . ja v a 2 s .c o m*/ } ITextEditor editor = (ITextEditor) editorPart; IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); if (document != null) { int start = startCtx.getStartIndex(); int stop = stopCtx.getStopIndex() - startCtx.getStartIndex(); editor.setHighlightRange(start, stop + 1, true); editor.selectAndReveal(start, stop + 1); } }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RBaseListen.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j av a 2s . com * <p/> * The default implementation does nothing. */ @Override public void enterE19DefFunction(@NotNull RParser.E19DefFunctionContext ctx) { /* * Insert function as current scope with a parent current scope * (scope.peek)! */ scopes.push(new RScope(scopes.peek())); Interval sourceInterval = ctx.getSourceInterval(); Token firstToken = tokens.get(sourceInterval.a); // System.out.println(ctx.getParent().getChild(0).getText()); int lineStart = firstToken.getStartIndex(); // String ct=ctx.getText(); // System.out.println("function start at line:"+lineStart); Token lastToken = tokens.get(sourceInterval.b); int lineEnd = lastToken.getStopIndex() + 1 - lineStart; // String ct2=ctx.getText(); // Add to the editor folding action if enabled in the preferences! if (store.getBoolean("FUNCTIONS_FOLDING")) { startStop.add(lineStart + "," + lineEnd); } int lineMethod = calculateLine(lineStart); int childs = ctx.getParent().getChildCount(); int posTree = 0; for (int i = 0; i < childs; i++) { if (ctx.getText().equals(ctx.getParent().getChild(i).getText())) { posTree = i; } } if (ctx.getParent().getChild(posTree - 1) != null && ctx.getParent().getChild(posTree - 2) != null) { String op = ctx.getParent().getChild(posTree - 1).getText(); String name = ctx.getParent().getChild(posTree - 2).getText(); if (op.equals("<-") || op.equals("<<-")) { if (methods.size() == 0) { methods.push(new REditorOutlineNode(name, lineMethod, "function", editor.baseNode)); } else { methods.push(new REditorOutlineNode(name, lineMethod, "function", methods.peek())); } } } else if (posTree == 0) { if (methods.size() == 0) { methods.push(new REditorOutlineNode(ctx.getText(), lineMethod, "function", editor.baseNode)); } else { methods.push(new REditorOutlineNode(ctx.getText(), lineMethod, "function", methods.peek())); } } }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RBaseListen.java
License:Open Source License
public void enterE21(@NotNull RParser.E21Context ctx) { Interval sourceInterval = ctx.getSourceInterval(); Token firstToken = tokens.get(sourceInterval.a); int lineStart = firstToken.getStartIndex(); Token lastToken = tokens.get(sourceInterval.b); int lineEnd = lastToken.getStopIndex() + 1 - lineStart; // Add to the editor folding action if enabled in the preferences! if (store.getBoolean("IF_CONDITION_FOLDING")) { startStop.add(lineStart + "," + lineEnd); }/* ww w . ja va 2 s .co m*/ }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RBaseListen.java
License:Open Source License
public void enterE22(@NotNull RParser.E22Context ctx) { Interval sourceInterval = ctx.getSourceInterval(); Token firstToken = tokens.get(sourceInterval.a); int lineStart = firstToken.getStartIndex(); Token lastToken = tokens.get(sourceInterval.b); int lineEnd = lastToken.getStopIndex() + 1 - lineStart; // Add to the editor folding action if enabled in the preferences! if (store.getBoolean("IF_CONDITION_FOLDING")) { startStop.add(lineStart + "," + lineEnd); }/*from ww w . j a v a2s. co m*/ }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RBaseListen.java
License:Open Source License
public void enterE23(@NotNull RParser.E23Context ctx) { Interval sourceInterval = ctx.getSourceInterval(); Token firstToken = tokens.get(sourceInterval.a); int lineStart = firstToken.getStartIndex(); Token lastToken = tokens.get(sourceInterval.b); int lineEnd = lastToken.getStopIndex() + 1 - lineStart; // Add to the editor folding action if enabled in the preferences! if (store.getBoolean("FOR_LOOP_FOLDING")) { startStop.add(lineStart + "," + lineEnd); }/* w w w. java 2s. c om*/ }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RBaseListen.java
License:Open Source License
public void enterE24(@NotNull RParser.E24Context ctx) { Interval sourceInterval = ctx.getSourceInterval(); Token firstToken = tokens.get(sourceInterval.a); int lineStart = firstToken.getStartIndex(); Token lastToken = tokens.get(sourceInterval.b); int lineEnd = lastToken.getStopIndex() + 1 - lineStart; // Add to the editor folding action if enabled in the preferences! if (store.getBoolean("WHILE_LOOP_FOLDING")) { startStop.add(lineStart + "," + lineEnd); }/*w w w. j a va 2s . c o m*/ }