Search in sources :

Example 1 with ForEachTokenNode

use of com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode in project auto by google.

the class Reparser method parseTokenNode.

private Node parseTokenNode() {
    TokenNode tokenNode = (TokenNode) currentNode();
    nextNode();
    if (tokenNode instanceof CommentTokenNode) {
        return emptyNode(tokenNode.lineNumber);
    } else if (tokenNode instanceof IfTokenNode) {
        return parseIfOrElseIf((IfTokenNode) tokenNode);
    } else if (tokenNode instanceof ForEachTokenNode) {
        return parseForEach((ForEachTokenNode) tokenNode);
    } else if (tokenNode instanceof MacroDefinitionTokenNode) {
        return parseMacroDefinition((MacroDefinitionTokenNode) tokenNode);
    } else {
        throw new IllegalArgumentException("Unexpected token: " + tokenNode.name() + " on line " + tokenNode.lineNumber);
    }
}
Also used : ForEachTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode) ElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode) EndTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode) CommentTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.CommentTokenNode) IfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfTokenNode) ElseTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode) IfOrElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode) MacroDefinitionTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode) CommentTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.CommentTokenNode) ElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode) IfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfTokenNode) IfOrElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode) MacroDefinitionTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode) ForEachTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode)

Example 2 with ForEachTokenNode

use of com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode in project auto by google.

the class Parser method parseForEach.

/**
   * Parses a {@code #foreach} token from the reader. <pre>{@code
   * <foreach-token> -> #foreach ( $<id> in <expression> )
   * }</pre>
   */
private Node parseForEach() throws IOException {
    expect('(');
    expect('$');
    String var = parseId("For-each variable");
    skipSpace();
    boolean bad = false;
    if (c != 'i') {
        bad = true;
    } else {
        next();
        if (c != 'n') {
            bad = true;
        }
    }
    if (bad) {
        throw parseException("Expected 'in' for #foreach");
    }
    next();
    ExpressionNode collection = parseExpression();
    expect(')');
    return new ForEachTokenNode(var, collection);
}
Also used : NotExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.NotExpressionNode) BinaryExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.BinaryExpressionNode) ForEachTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode)

Example 3 with ForEachTokenNode

use of com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode in project auto by google.

the class Reparser method parseForEach.

private Node parseForEach(ForEachTokenNode forEach) {
    Node body = parseTo(END_SET, forEach);
    // Skip #end
    nextNode();
    return new ForEachNode(forEach.lineNumber, forEach.var, forEach.collection, body);
}
Also used : ForEachNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.ForEachNode) IfNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.IfNode) MacroCallNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.MacroCallNode) ForEachTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode) ElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode) SetNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode) Node.emptyNode(com.google.auto.value.processor.escapevelocity.Node.emptyNode) EndTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode) EofNode(com.google.auto.value.processor.escapevelocity.TokenNode.EofNode) CommentTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.CommentTokenNode) IfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfTokenNode) ElseTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode) IfOrElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode) MacroDefinitionTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode) ForEachNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.ForEachNode)

Aggregations

ForEachTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode)3 CommentTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.CommentTokenNode)2 ElseIfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode)2 ElseTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode)2 EndTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode)2 IfOrElseIfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode)2 IfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.IfTokenNode)2 MacroDefinitionTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode)2 ForEachNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.ForEachNode)1 IfNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.IfNode)1 MacroCallNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.MacroCallNode)1 SetNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode)1 BinaryExpressionNode (com.google.auto.value.processor.escapevelocity.ExpressionNode.BinaryExpressionNode)1 NotExpressionNode (com.google.auto.value.processor.escapevelocity.ExpressionNode.NotExpressionNode)1 Node.emptyNode (com.google.auto.value.processor.escapevelocity.Node.emptyNode)1 EofNode (com.google.auto.value.processor.escapevelocity.TokenNode.EofNode)1