Java Code Examples for org.antlr.v4.runtime.TokenStream#size()
The following examples show how to use
org.antlr.v4.runtime.TokenStream#size() .
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: CQLErrorStrategy.java From PoseidonX with Apache License 2.0 | 6 votes |
@NotNull private String getText(TokenStream tokens, Interval interval) { int start = interval.a; int stop = interval.b; if (start < 0 || stop < 0) return ""; if (stop >= tokens.size()) stop = tokens.size() - 1; StringBuilder buf = new StringBuilder(); for (int i = start; i <= stop; i++) { Token t = tokens.get(i); if (t.getType() == Token.EOF) break; buf.append(t.getText()); if (i != stop) { buf.append(" "); } } return buf.toString(); }
Example 2
Source File: GrammarPredicates.java From beakerx with Apache License 2.0 | 6 votes |
public static boolean isClassName(TokenStream _input) { try { int i=1; Token token = _input.LT(i); while (token!=null && i < _input.size() && _input.LT(i+1).getType() == GroovyParser.DOT) { i = i + 2; token = _input.LT(i); } if(token==null) return false; // TODO here return Character.isUpperCase(Character.codePointAt(token.getText(), 0)); } catch(Exception e) { e.printStackTrace(); } return false; }
Example 3
Source File: GrammarParserInterpreter.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void recover(Parser recognizer, RecognitionException e) { int errIndex = recognizer.getInputStream().index(); if ( firstErrorTokenIndex == -1 ) { firstErrorTokenIndex = errIndex; // latch } // System.err.println("recover: error at " + errIndex); TokenStream input = recognizer.getInputStream(); if ( input.index()<input.size()-1 ) { // don't consume() eof recognizer.consume(); // just kill this bad token and let it continue. } }
Example 4
Source File: RefactorUtils.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Token getTokenForCharIndex(TokenStream tokens, int charIndex) { for (int i=0; i<tokens.size(); i++) { Token t = tokens.get(i); if ( charIndex>=t.getStartIndex() && charIndex<=t.getStopIndex() ) { return t; } } return null; }
Example 5
Source File: ProfilerPanel.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void setProfilerData(PreviewState previewState, long parseTime_ns) { this.previewState = previewState; Parser parser = previewState.parsingResult.parser; ParseInfo parseInfo = parser.getParseInfo(); updateTableModelPerExpertCheckBox(parseInfo); double parseTimeMS = parseTime_ns/(1000.0*1000.0); // microsecond decimal precision NumberFormat formatter = new DecimalFormat("#.###"); parseTimeField.setText(formatter.format(parseTimeMS)); double predTimeMS = parseInfo.getTotalTimeInPrediction()/(1000.0*1000.0); predictionTimeField.setText( String.format("%s = %3.2f%%", formatter.format(predTimeMS), 100*(predTimeMS)/parseTimeMS) ); TokenStream tokens = parser.getInputStream(); int numTokens = tokens.size(); Token lastToken = tokens.get(numTokens-1); int numChar = lastToken.getStopIndex(); int numLines = lastToken.getLine(); if ( lastToken.getType()==Token.EOF ) { if ( numTokens<=1 ) { numLines = 0; } else { Token secondToLastToken = tokens.get(numTokens-2); numLines = secondToLastToken.getLine(); } } inputSizeField.setText(String.format("%d char, %d lines", numChar, numLines)); numTokensField.setText(String.valueOf(numTokens)); double look = parseInfo.getTotalSLLLookaheadOps()+ parseInfo.getTotalLLLookaheadOps(); lookaheadBurdenField.setText( String.format("%d/%d = %3.2f", (long) look, numTokens, look/numTokens) ); double atnLook = parseInfo.getTotalATNLookaheadOps(); cacheMissRateField.setText( String.format("%d/%d = %3.2f%%", (long) atnLook, (long) look, atnLook*100.0/look) ); }