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:de.epdv.plugin.netbeans.lang.go.lexer.GLLexer.java

@Override
public org.netbeans.api.lexer.Token<GLTokenId> nextToken() {
    Token token = goLexer.nextToken();
    if (token.getType() != GolangLexer.EOF) {
        GLTokenId tokenId = GLLanguageHierarchy.getToken(token.getType());
        return info.tokenFactory().createToken(tokenId);
    }/*  w ww  . j av  a2 s .co  m*/
    token.getText();
    return null;
}

From source file:de.fuerstenau.gradle.commentstripper.CommentStripper.java

License:Open Source License

private void doStrip(Path fin, Path fout, Charset cs, DocType docType) throws IOException {
    try (Reader in = Files.newBufferedReader(fin, cs);
            OutputStream out = new BufferedOutputStream(Files.newOutputStream(fout))) {
        final ANTLRInputStream stream = new ANTLRInputStream(in);

        final CommonTokenStream tokens;
        if (docType == DocType.JAVA) {
            tokens = new CommonTokenStream(new GroovyLexer(stream), GroovyLexer.COMMENT);
        } else {/*from   w  w  w.ja va  2s .  com*/
            tokens = new CommonTokenStream(new Java8Lexer(stream), Java8Lexer.COMMENTS);
        }

        TokenStreamRewriter rew = new TokenStreamRewriter(tokens);

        while (tokens.LA(1) != EOF) {
            final Token t = tokens.LT(1);
            if (cond.shouldStrip(t.getText())) {
                rew.delete(t);
            }
            tokens.consume();
        }

        out.write(rew.getText().getBytes(cs));
        out.flush();
    }
}

From source file:de.huberlin.cuneiform.language.ApplyExpression.java

License:Apache License

public void addParam(Token idToken, List<Expression> exprSet) {

    if (idToken == null)
        throw new NullPointerException("Id token must not be null.");

    addParam(idToken.getText(), exprSet);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addAssignVar(Token idToken) {

    String id;/*from   w ww .  ja  v  a  2s. com*/

    if (idToken == null)
        throw new NullPointerException("Id token must not be null.");

    id = idToken.getText();

    if (id == null)
        throw new NullPointerException("Id string must not be null.");

    if (id.isEmpty())
        throw new RuntimeException("Id string must not be empty.");

    curAssign.addVar(id);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefTask(Token idToken) {

    String name;//from  ww w. jav  a2 s .c om

    if (idToken == null)
        throw new NullPointerException("Id token must not be null.");

    name = idToken.getText();

    // check whether we have seen a declare statement yet
    if (declare == null) {

        reportError(ERROR_ORDER, idToken.getLine(),
                "Task definition for '" + name + "' must not appear prior to declare statement.");

        return;
    }

    // check whether this is the first time, this task is introduced
    if (defTaskMap.containsKey(name)) {

        reportError(ERROR_UNIQUENESS, idToken.getLine(),
                "Duplicate task definition. The task '" + name + "' has already been defined.");

        return;
    }

    defTaskMap.put(name, new DefTask(name));
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefTaskParam(Token nameToken, DefTaskParam p) {

    String name;/*from www.j av  a  2 s. c  om*/
    DefTask task;

    if (nameToken == null)
        throw new NullPointerException("Task name token must not be null.");

    if (p == null)
        throw new NullPointerException("Input parameter must not be null.");

    name = nameToken.getText();

    task = defTaskMap.get(name);
    if (task == null)
        throw new NullPointerException("Referenced task does not exits.");

    for (ParamItem invar : p)
        if (task.containsExplicitParamWithName(invar.getValue()))
            if (invar.getValue().equals(Constant.TOKEN_TASK) && task.isTaskParamExplicit()) {

                reportError(BaseParser.ERROR_UNIQUENESS, nameToken.getLine(),
                        "Duplicate definition of input variable name '" + invar + "'.");

                return;
            }

    // if this cluster contains the task parameter, it must not be of type reduce
    if (p instanceof ReduceParam)
        if (((ReduceParam) p).getValue().equals(Constant.TOKEN_TASK)) {

            reportError(ERROR_REFERENCE, nameToken.getLine(),
                    "Special task parameter cannot be marked reduce.");

            return;
        }

    task.addParam(p);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefTaskLabel(Token tasknameToken, Token labelToken) {

    String taskname;//www .  j  a v a  2s. c o m
    String label;
    DefTask task;

    if (tasknameToken == null)
        throw new NullPointerException("Task name token must not be null.");

    if (labelToken == null)
        throw new NullPointerException("Label token must not be null.");

    taskname = tasknameToken.getText();
    label = labelToken.getText();

    task = defTaskMap.get(taskname);
    if (task == null)
        throw new NullPointerException("Referenced task does not exits.");

    if (!labelMap.containsKey(label)) {

        reportError(ERROR_ORDER, labelToken.getLine(), "In definition of task '" + taskname + "' the label '"
                + label + "' is used but was not defined.");

        return;
    }

    task.addLabel(label);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefTaskOutput(Token tasknameToken, DefTaskOutput output) {

    String taskname;/*from w  w  w. j  a  v  a2  s  .  c  o m*/
    DefTask task;

    if (tasknameToken == null)
        throw new NullPointerException("Task name token must not be null.");

    if (output == null)
        throw new NullPointerException("Output variable must not be null.");

    taskname = tasknameToken.getText();

    task = defTaskMap.get(taskname);
    if (task == null)
        throw new NullPointerException("Referenced task does not exits.");

    if (task.containsOutputWithName(output.getValue())) {

        reportError(ERROR_UNIQUENESS, output.getLine(), "Duplicate use of output variable name.");

        return;
    }

    task.addOutput(output);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefMacro(Token idToken) {

    String name;//from w  w  w .ja  v  a2  s. c  o  m

    if (idToken == null)
        throw new NullPointerException("Id token must not be null.");

    name = idToken.getText();

    addDefMacro(name);
}

From source file:de.huberlin.cuneiform.language.BaseCuneiformParser.java

License:Apache License

protected void addDefMacroVar(Token idToken) {

    String param;//from w  ww  .j a va2  s  . co  m

    if (idToken == null)
        throw new NullPointerException("Id token must not be null.");

    param = idToken.getText();

    addDefMacroVar(param);
}