use of com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode in project auto by google.
the class Reparser method parseIfOrElseIf.
private Node parseIfOrElseIf(IfOrElseIfTokenNode ifOrElseIf) {
Node truePart = parseTo(ELSE_ELSE_IF_END_SET, ifOrElseIf);
Node falsePart;
Node token = currentNode();
// Skip #else or #elseif (cond) or #end.
nextNode();
if (token instanceof EndTokenNode) {
falsePart = emptyNode(token.lineNumber);
} else if (token instanceof ElseTokenNode) {
falsePart = parseTo(END_SET, ifOrElseIf);
// Skip #end
nextNode();
} else if (token instanceof ElseIfTokenNode) {
// We've seen #if (condition1) ... #elseif (condition2). currentToken is the first token
// after (condition2). We pretend that we've just seen #if (condition2) and parse out
// the remainder (which might have further #elseif and final #else). Then we pretend that
// we actually saw #if (condition1) ... #else #if (condition2) ...remainder ... #end #end.
falsePart = parseIfOrElseIf((ElseIfTokenNode) token);
} else {
throw new AssertionError(currentNode());
}
return new IfNode(ifOrElseIf.lineNumber, ifOrElseIf.condition, truePart, falsePart);
}
use of com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode in project auto by google.
the class Parser method parseIfOrElseIf.
/**
* Parses the condition following {@code #if} or {@code #elseif}.
* <pre>{@code
* <if-token> -> #if ( <condition> )
* <elseif-token> -> #elseif ( <condition> )
* }</pre>
*
* @param directive either {@code "if"} or {@code "elseif"}.
*/
private Node parseIfOrElseIf(String directive) throws IOException {
expect('(');
ExpressionNode condition = parseExpression();
expect(')');
return directive.equals("if") ? new IfTokenNode(condition) : new ElseIfTokenNode(condition);
}
Aggregations