Search in sources :

Example 1 with EndTokenNode

use of com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode 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);
}
Also used : EndTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode) ElseTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode) 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) ElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode) IfOrElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode) IfNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.IfNode)

Example 2 with EndTokenNode

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

the class Parser method parseDirective.

/**
   * Parses a single directive token from the reader. Directives can be spelled with or without
   * braces, for example {@code #if} or {@code #{if}}. We omit the brace spelling in the productions
   * here: <pre>{@code
   * <directive> -> <if-token> |
   *                <else-token> |
   *                <elseif-token> |
   *                <end-token> |
   *                <foreach-token> |
   *                <set-token> |
   *                <macro-token> |
   *                <macro-call> |
   *                <comment>
   * }</pre>
   */
private Node parseDirective() throws IOException {
    String directive;
    if (c == '{') {
        next();
        directive = parseId("Directive inside #{...}");
        expect('}');
    } else {
        directive = parseId("Directive");
    }
    Node node;
    if (directive.equals("end")) {
        node = new EndTokenNode(lineNumber());
    } else if (directive.equals("if") || directive.equals("elseif")) {
        node = parseIfOrElseIf(directive);
    } else if (directive.equals("else")) {
        node = new ElseTokenNode(lineNumber());
    } else if (directive.equals("foreach")) {
        node = parseForEach();
    } else if (directive.equals("set")) {
        node = parseSet();
    } else if (directive.equals("macro")) {
        node = parseMacroDefinition();
    } else {
        node = parsePossibleMacroCall(directive);
    }
    // TODO(emcmanus): in fact it also skips space before the newline, which should be implemented.
    if (c == '\n') {
        next();
    }
    return node;
}
Also used : EndTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode) ElseTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseTokenNode) IndexReferenceNode(com.google.auto.value.processor.escapevelocity.ReferenceNode.IndexReferenceNode) ForEachTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode) NotExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.NotExpressionNode) SetNode(com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode) EofNode(com.google.auto.value.processor.escapevelocity.TokenNode.EofNode) MemberReferenceNode(com.google.auto.value.processor.escapevelocity.ReferenceNode.MemberReferenceNode) 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) BinaryExpressionNode(com.google.auto.value.processor.escapevelocity.ExpressionNode.BinaryExpressionNode) ElseIfTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.ElseIfTokenNode) MethodReferenceNode(com.google.auto.value.processor.escapevelocity.ReferenceNode.MethodReferenceNode) EndTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.EndTokenNode) PlainReferenceNode(com.google.auto.value.processor.escapevelocity.ReferenceNode.PlainReferenceNode) MacroDefinitionTokenNode(com.google.auto.value.processor.escapevelocity.TokenNode.MacroDefinitionTokenNode)

Aggregations

SetNode (com.google.auto.value.processor.escapevelocity.DirectiveNode.SetNode)2 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 EofNode (com.google.auto.value.processor.escapevelocity.TokenNode.EofNode)2 ForEachTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.ForEachTokenNode)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 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 IndexReferenceNode (com.google.auto.value.processor.escapevelocity.ReferenceNode.IndexReferenceNode)1 MemberReferenceNode (com.google.auto.value.processor.escapevelocity.ReferenceNode.MemberReferenceNode)1 MethodReferenceNode (com.google.auto.value.processor.escapevelocity.ReferenceNode.MethodReferenceNode)1 PlainReferenceNode (com.google.auto.value.processor.escapevelocity.ReferenceNode.PlainReferenceNode)1 IfOrElseIfTokenNode (com.google.auto.value.processor.escapevelocity.TokenNode.IfOrElseIfTokenNode)1