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; }
private String spliceParens(int startIndex, int initialParenCount) { TokenStreamRewriter r = new TokenStreamRewriter(tokenStream); int i = startIndex, parens = initialParenCount; for ( ; i < tokenStream.size(); i++ ) { String tokenText = tokenStream.get(i).getText(); if ( tokenText.equals("(") ) parens++; else if ( tokenText.equals(")") ) parens--; if ( parens == 0 ) break; } r.insertBefore(startIndex, "/__MAXWELL__/"); r.delete(startIndex, i); return r.getText(); }
public void replace(String programName, int from, int to, Object text) { if ( from > to || from<0 || to<0 || to >= tokens.size() ) { throw new IllegalArgumentException("replace: range invalid: "+from+".."+to+"(size="+tokens.size()+")"); } RewriteOperation op = new ReplaceOp(from, to, text); List<RewriteOperation> rewrites = getProgram(programName); op.instructionIndex = rewrites.size(); rewrites.add(op); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter in programName. */ public String getText(String programName) { return getText(programName, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter. */ public String getText() { return getText(DEFAULT_PROGRAM_NAME, Interval.of(0,tokens.size()-1)); }
public void replace(String programName, int from, int to, Object text) { if ( from > to || from<0 || to<0 || to >= tokens.size() ) { throw new IllegalArgumentException("replace: range invalid: "+from+".."+to+"(size="+tokens.size()+")"); } RewriteOperation op = new ReplaceOp(from, to, text); List<RewriteOperation> rewrites = getProgram(programName); op.instructionIndex = rewrites.size(); rewrites.add(op); }
public void replace(String programName, int from, int to, Object text) { if ( from > to || from<0 || to<0 || to >= tokens.size() ) { throw new IllegalArgumentException("replace: range invalid: "+from+".."+to+"(size="+tokens.size()+")"); } RewriteOperation op = new ReplaceOp(from, to, text); List<RewriteOperation> rewrites = getProgram(programName); op.instructionIndex = rewrites.size(); rewrites.add(op); }
public void replace(String programName, int from, int to, Object text) { if ( from > to || from<0 || to<0 || to >= tokens.size() ) { throw new IllegalArgumentException("replace: range invalid: "+from+".."+to+"(size="+tokens.size()+")"); } RewriteOperation op = new ReplaceOp(from, to, text); List<RewriteOperation> rewrites = getProgram(programName); op.instructionIndex = rewrites.size(); rewrites.add(op); }
public void replace(String programName, int from, int to, @Nullable Object text) { if ( from > to || from<0 || to<0 || to >= tokens.size() ) { throw new IllegalArgumentException("replace: range invalid: "+from+".."+to+"(size="+tokens.size()+")"); } RewriteOperation op = new ReplaceOp(tokens, from, to, text); List<RewriteOperation> rewrites = getProgram(programName); op.instructionIndex = rewrites.size(); rewrites.add(op); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter. */ public String getText() { return getText(DEFAULT_PROGRAM_NAME, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter in programName. */ public String getText(String programName) { return getText(programName, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter in programName. * * @since 4.5 */ public String getText(String programName) { return getText(programName, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter. */ public String getText() { return getText(DEFAULT_PROGRAM_NAME, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter. */ public String getText() { return getText(DEFAULT_PROGRAM_NAME, Interval.of(0,tokens.size()-1)); }
/** Return the text from the original tokens altered per the * instructions given to this rewriter. */ public String getText() { return getText(DEFAULT_PROGRAM_NAME, Interval.of(0,tokens.size()-1)); }
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; }
@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. } }
@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. } }
@Override public Token recoverInline(Parser recognizer) throws RecognitionException { int errIndex = recognizer.getInputStream().index(); if ( firstErrorTokenIndex == -1 ) { firstErrorTokenIndex = errIndex; // latch } // System.err.println("recoverInline: error at " + errIndex); InputMismatchException e = new InputMismatchException(recognizer); TokenStream input = recognizer.getInputStream(); // seek EOF input.seek(input.size() - 1); throw e; // throw after seek so exception has bad token }