Search in sources :

Example 1 with SetNode

use of com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode in project auto by google.

the class Reparser method removeSpaceBeforeSet.

/**
   * Returns a copy of the given list where spaces have been moved where appropriate after {@code
   * #set}. This hack is needed to match what appears to be special treatment in Apache Velocity of
   * spaces before {@code #set} directives. If you have <i>thing</i> <i>whitespace</i> {@code #set},
   * then the whitespace is deleted if the <i>thing</i> is a comment ({@code ##...\n}); a reference
   * ({@code $x} or {@code $x.foo} etc); a macro definition; or another {@code #set}.
   */
private static ImmutableList<Node> removeSpaceBeforeSet(ImmutableList<Node> nodes) {
    assert Iterables.getLast(nodes) instanceof EofNode;
    // Since the last node is EofNode, the i + 1 and i + 2 accesses below are safe.
    ImmutableList.Builder<Node> newNodes = ImmutableList.builder();
    for (int i = 0; i < nodes.size(); i++) {
        Node nodeI = nodes.get(i);
        newNodes.add(nodeI);
        if (shouldDeleteSpaceBetweenThisAndSet(nodeI) && isWhitespaceLiteral(nodes.get(i + 1)) && nodes.get(i + 2) instanceof SetNode) {
            // Skip the space.
            i++;
        }
    }
    return newNodes.build();
}
Also used : SetNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode) EofNode(com.google.auto.value.processor.escapevelocity.TokenNode.EofNode) ImmutableList(com.google.common.collect.ImmutableList) 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)

Example 2 with SetNode

use of com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode in project auto by google.

the class Parser method parseSet.

/**
   * Parses a {@code #set} token from the reader. <pre>{@code
   * <set-token> -> #set ( $<id> = <expression>)
   * }</pre>
   */
private Node parseSet() throws IOException {
    expect('(');
    expect('$');
    String var = parseId("#set variable");
    expect('=');
    ExpressionNode expression = parseExpression();
    expect(')');
    return new SetNode(var, expression);
}
Also used : SetNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode) NotExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.NotExpressionNode) BinaryExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.BinaryExpressionNode)

Aggregations

SetNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode)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 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 CommentTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.CommentTokenNode)1 ElseIfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode)1 ElseTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode)1 EndTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode)1 EofNode (com.google.auto.value.processor.escapevelocity.TokenNode.EofNode)1 ForEachTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode)1 IfOrElseIfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode)1 IfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.IfTokenNode)1 MacroDefinitionTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode)1 ImmutableList (com.google.common.collect.ImmutableList)1