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();
}
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);
}
Aggregations