Example usage for org.antlr.v4.runtime Token getTokenIndex

List of usage examples for org.antlr.v4.runtime Token getTokenIndex

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Token getTokenIndex.

Prototype

int getTokenIndex();

Source Link

Document

An index from 0..n-1 of the token object in the input stream.

Usage

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public Token getTokenFollowing(Token token) {
    int index = null != token ? token.getTokenIndex() + 1 : tokens.size();
    if (index < tokens.size())
        return tokens.get(index);
    return null;/* w w  w. ja v  a2 s. c o  m*/
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public Token getTokenPreceding(Token token) {
    int index = null != token ? token.getTokenIndex() - 1 : -1;
    if (index >= 0)
        return tokens.get(index);
    return null;//www .  j a v  a2s. c  om
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void insertComment(String comment, Token token, CommentWhere where) {
    insertComment(comment, token.getTokenIndex(), where);
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void deleteAndAdjustWhitespace(Token token) {
    int i = token.getTokenIndex();
    deleteAndAdjustWhitespace(i, i);
}

From source file:com.satisfyingstructures.J2S.J2SRewriter.java

License:Open Source License

public void replaceAndAdjustWhitespace(Token token, String text) {
    int i = token.getTokenIndex();
    replaceAndAdjustWhitespace(i, i, text);
}

From source file:com.satisfyingstructures.J2S.ParseTreeRewriter.java

License:Open Source License

public String getText(String programName, Token t) {
    return getText(programName, Interval.of(t.getTokenIndex(), t.getTokenIndex()));
}

From source file:com.yahoo.yqlplus.language.internal.ast.ErrorNode.java

public ErrorNode(TokenStream input, Token start, Token stop, RecognitionException e) {
    //System.out.println("start: "+start+", stop: "+stop);
    if (stop == null || (stop.getTokenIndex() < start.getTokenIndex() && stop.getType() != Token.EOF)) {
        // sometimes resync does not consume a token (when LT(1) is
        // in follow set.  So, stop will be 1 to left to start. adjust.
        // Also handle case where start is the first token and no token
        // is consumed during recovery; LT(-1) will return null.
        stop = start;/* w w  w.  j  a va2s  .  c  o  m*/
    }
    this.input = input;
    this.start = start;
    this.stop = stop;
    this.trappedException = e;
}

From source file:javasharp.XmlEmittingVisitor.java

License:Open Source License

private void emitWhiteSpace(Token t) {
    int tokenIndex = t.getTokenIndex();
    if (tokenIndex > cursor && t.getType() == JavaLexer.WS) {
        String ws = t.getText().replaceAll("\r\n", "\n");
        try {//from  w w w. jav a  2 s . c  om
            contentHandler.characters(ws.toCharArray(), 0, ws.length());
        } catch (SAXException ex) {
            Logger.getLogger(XmlEmittingVisitor.class.getName()).log(Level.SEVERE, null, ex);
        }
        cursor = t.getTokenIndex();
    }
}

From source file:javasharp.XmlEmittingVisitor.java

License:Open Source License

void emitToken(String elementName, Token token) {
    int tokenIndex = token.getTokenIndex();
    assert tokenIndex > cursor;
    String tokenText = token.getText().replaceAll("\r\n", "\n");
    try {/*from   w w w.ja v a2s  . co  m*/
        AttributesImpl atts = new AttributesImpl();
        int tokenType = token.getType();
        tokenType = tokenType <= 0 ? 0 : tokenType;
        atts.addAttribute("", "type", "type", "", JavaLexer.tokenTypes[tokenType]);
        contentHandler.startElement("", elementName, elementName, atts);
        contentHandler.characters(tokenText.toCharArray(), 0, tokenText.length());
        contentHandler.endElement("", elementName, elementName);
    } catch (SAXException ex) {
        Logger.getLogger(XmlEmittingVisitor.class.getName()).log(Level.SEVERE, null, ex);
        throw new RuntimeException(ex);
    }
    cursor = tokenIndex;
}

From source file:javasharp.XmlEmittingVisitor.java

License:Open Source License

@Override
public Object visitTerminal(TerminalNode node) {
    Token symbol = node.getSymbol();
    int tokenIndex = symbol.getTokenIndex();
    emitComments(tokenIndex);/*from   w  w w  . ja  v a 2 s .c o  m*/
    TokenSource tokenSource = symbol.getTokenSource();
    emitToken("Symbol", symbol);
    return null;
}