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

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

Introduction

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

Prototype

String getText();

Source Link

Document

Get the text of the token.

Usage

From source file:codesniffer.java8.adapter.AdapterUtil.java

License:Open Source License

private static Comment extractComment(Token ct) {
    String txt = ct.getText().trim();
    if (txt.startsWith("/**")) {
        return new DocumentComment(ct.getText());
    } else if (txt.startsWith("/*")) {
        return new BlockComment(ct.getText());
    } else if (txt.startsWith("//")) {
        return new LineComment(ct.getText());
    }/*from   w w  w  .  j av  a 2 s  .  c  o  m*/
    throw new IllegalStateException();
}

From source file:com.basho.contact.ContactWalker.java

License:Apache License

@Override
public void exitId_list(Id_listContext ctx) {
    List<String> str_ids = new ArrayList<String>();
    for (Token t : ctx.ids) {
        str_ids.add(t.getText());
    }//from  w  ww .  java 2  s .  c o m
    setValue(ctx, str_ids);
}

From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java

License:Apache License

private StringBuilder getTextWithSurroundingHiddenTokens(Token token) {
    StringBuilder sb = new StringBuilder();
    List<Token> hiddenTokens = tokens.getHiddenTokensToLeft(token.getTokenIndex());
    if (hiddenTokens != null) {
        for (Token t : hiddenTokens) {
            sb.append(t.getText());
        }//from   ww w. j  a  va  2 s  .  c om
    }
    sb.append(token.getText());
    hiddenTokens = tokens.getHiddenTokensToRight(token.getTokenIndex());
    if (hiddenTokens != null) {
        for (Token t : hiddenTokens) {
            sb.append(t.getText());
        }
    }
    return sb;
}

From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java

License:Apache License

private StringBuilder tokenListToString(List<Token> tokens) {
    StringBuilder sb = new StringBuilder();
    if (tokens != null) {
        for (Token t : tokens) {
            sb.append(t.getText());
        }//from  w  w  w.  j ava2s .  co  m
    }
    return sb;
}

From source file:com.boothen.jsonedit.editor.JsonTextEditor.java

License:Open Source License

private static void updateMarkers(IDocument doc, IResource res, List<ParseProblem> probs) throws CoreException {

    res.deleteMarkers(MARKER_ID, false, 0);

    for (final ParseProblem problem : probs) {
        try {//from   w  w w  . j  a  v a2 s .  c  om
            IMarker marker = res.createMarker(MARKER_ID);
            Token token = problem.getOffendingToken();

            int offset = doc.getLineOffset(problem.getLine() - 1) + problem.getCharPositionInLine();
            int length = token != null ? token.getText().length() : 1;
            marker.setAttribute(IMarker.SEVERITY, problem.getSeverity().getMarkerValue());
            marker.setAttribute(IMarker.LOCATION, "Line " + problem.getLine());
            marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
            marker.setAttribute(IMarker.CHAR_START, offset);
            marker.setAttribute(IMarker.CHAR_END, offset + length);
        } catch (BadLocationException e) {
            Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid position", e);
            StatusManager.getManager().handle(status);
        }
    }
}

From source file:com.cisco.yangide.core.parser.YangTokenFormatter.java

License:Open Source License

/**
 * @param token//from w ww  . ja v  a2s  . c  o m
 * @return <code>true</code> if token processed by import case
 */
private boolean processImportCase(Token token) {
    if (!compactImport) {
        return false;
    }

    if (token.getType() == YangLexer.IMPORT_KEYWORD) {
        importScope = true;
        importStatement = new StringBuilder();
    }

    if (importScope) {
        if (token.getType() == RIGHT_BRACE) {
            importScope = false;
            printIndent();
            sb.append(importStatement.toString()).append(' ');
            wasWS = true;
            nlCount = 0;
            // add indent for right brace processing
            currIndent += indent;
            return false;
        } else if (!isNewLine(token) && !isWS(token)) {
            if (importStatement.length() > 0 && token.getType() != SEMICOLON) {
                importStatement.append(' ');
            }
            importStatement.append(token.getText());
        }
        return true;
    }

    return importScope;
}

From source file:com.cisco.yangide.core.parser.YangTokenFormatter.java

License:Open Source License

/**
 * Prints formatted text of token into string buffer.
 *
 * @param token current token/*from   w  ww. j  a  v a 2  s  .  c  o  m*/
 */
private void processToken(Token token) {
    int type = token.getType();

    if (type == STRING) {
        String text = token.getText();
        if (!formatString || text.length() < maxLineLength) {
            if (!(wasWS || token.getType() == LEFT_BRACE || token.getType() == SEMICOLON)) {
                if (wasNL) {
                    printIndent();
                }
                printIndent();
            }
            sb.append(text);
        } else {
            printFormattedString(text);
        }
    } else if (type == YangLexer.END_BLOCK_COMMENT) {
        if (formatComment) {
            sb.append(lineSeparator);
            printIndent();
            String text = token.getText().substring(0, token.getText().length() - 2);
            text = text.replaceAll("(?m)^\\s+\\*", "");
            printFormattedString(text);
            sb.append(lineSeparator);
            printIndent();
            sb.append("*/");
        } else {
            sb.append(token.getText());
        }
    } else {
        if (!(wasWS || isNewLine(token) || isWS(token) || token.getType() == SEMICOLON
                || token.getType() == LEFT_BRACE)) {
            printIndent();
        }
        if (!isNewLine(token)) {
            sb.append(token.getText());
        }
    }
    if (isNewLine(token)) {
        sb.append(lineSeparator);
    }
}

From source file:com.cisco.yangide.core.parser.YangTokenFormatter.java

License:Open Source License

/**
 * @param token token to inspect/*from   w  ww .j  a v a  2  s  .  c  o m*/
 * @return <code>true</code> if token is space or space separator
 */
private boolean isWS(Token token) {
    if (token == null) {
        return false;
    }
    int type = token.getType();
    return (type == WS || type == S) && !token.getText().equals("\n") && !token.getText().equals("\r");
}

From source file:com.cisco.yangide.core.parser.YangTokenFormatter.java

License:Open Source License

/**
 * @param token token to inspect/*  w  w w  .j a  va 2  s  .  co  m*/
 * @return <code>true</code> if token is new line token.
 */
private boolean isNewLine(Token token) {
    if (token == null) {
        return false;
    }
    int type = token.getType();
    return (type == WS || type == S) && token.getText().equals("\n");
}

From source file:com.cisco.yangide.core.parser.YangTokenFormatter.java

License:Open Source License

/**
 * @param token token to inspect//from   ww w  .  j av a  2  s  . com
 * @return <code>true</code> if token is '\r' token.
 */
private boolean isCarriageReturn(Token token) {
    if (token == null) {
        return false;
    }
    int type = token.getType();
    return (type == WS || type == S) && token.getText().equals("\r");
}