Search in sources :

Example 1 with CommonASTWithHiddenTokens

use of antlr.CommonASTWithHiddenTokens in project processing by processing.

the class PdeEmitter method printIfThenElse.

private void printIfThenElse(final AST literalIf) throws SketchException {
    out.print(literalIf.getText());
    dumpHiddenAfter(literalIf);
    final AST condition = literalIf.getFirstChild();
    // the "if" condition: an EXPR
    print(condition);
    // the "then" clause is either an SLIST or an EXPR
    final AST thenPath = condition.getNextSibling();
    print(thenPath);
    // optional "else" clause: an SLIST or an EXPR
    // what could be simpler?
    final AST elsePath = thenPath.getNextSibling();
    if (elsePath != null) {
        out.print("else");
        final AST bestPrintableNode = getBestPrintableNode(elsePath, true);
        dumpHiddenBefore(bestPrintableNode);
        final CommonHiddenStreamToken hiddenBefore = ((CommonASTWithHiddenTokens) elsePath).getHiddenBefore();
        if (elsePath.getType() == PdeTokenTypes.SLIST && elsePath.getNumberOfChildren() == 0 && hiddenBefore == null) {
            out.print("{");
            final CommonHiddenStreamToken hiddenAfter = ((CommonASTWithHiddenTokens) elsePath).getHiddenAfter();
            if (hiddenAfter == null) {
                out.print("}");
            } else {
                dumpHiddenTokens(hiddenAfter);
            }
        } else {
            print(elsePath);
        }
    }
}
Also used : AST(antlr.collections.AST) CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) CommonASTWithHiddenTokens(antlr.CommonASTWithHiddenTokens)

Example 2 with CommonASTWithHiddenTokens

use of antlr.CommonASTWithHiddenTokens in project processing by processing.

the class PdeEmitter method dumpHiddenBefore.

/**
   * Dump the list of hidden tokens linked to before the AST node passed in.
   * The only time hidden tokens need to be dumped with this function is when
   * dealing parts of the tree where automatic tree construction was
   * turned off with the ! operator in the grammar file and the nodes were
   * manually constructed in such a way that the usual tokens don't have the
   * necessary hiddenAfter links.
   */
private void dumpHiddenBefore(final AST ast) {
    antlr.CommonHiddenStreamToken child = null, parent = ((CommonASTWithHiddenTokens) ast).getHiddenBefore();
    //
    if (parent == null) {
        return;
    }
    // traverse back to the head of the list of tokens before this node
    do {
        child = parent;
        parent = child.getHiddenBefore();
    } while (parent != null);
    // dump that list
    dumpHiddenTokens(child);
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) CommonASTWithHiddenTokens(antlr.CommonASTWithHiddenTokens)

Aggregations

CommonASTWithHiddenTokens (antlr.CommonASTWithHiddenTokens)2 CommonHiddenStreamToken (antlr.CommonHiddenStreamToken)2 AST (antlr.collections.AST)1