Add <@ elsif expression @>
[tedtools.git] / tmpl_gram.y
index b3a56ed..82267c3 100644 (file)
@@ -33,11 +33,13 @@ static GList *makeList2(void *a, void *b);
 }
 
 %type <node>                   node
+%type <node>                   ifnode elsenode elsifnode
 %type <node>                   listnodes
 %type <node>                   template
 %type <node>                   expression
 %type <list>                   list_expression
 %type <str>                            varname
+%type <str>                            elsif
 
 %type <flags>                  opt_escape
 %type <str>                            opt_format
@@ -49,7 +51,7 @@ static GList *makeList2(void *a, void *b);
 %token <str>                   LEXEME
 %token <str>                   VAR_OPEN VAR_CLOSE EXPR_OPEN EXPR_CLOSE 
                                                INCLUDE_OPEN INCLUDE_CLOSE
-%token <str>                   HTMLESCAPE URLESCAPE IF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P SELF_P 
+%token <str>                   HTMLESCAPE URLESCAPE IF_P ELSIF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P SELF_P 
 %token         <str>                   CMP_P
 
 %token <intval>                        INTEGER
@@ -206,6 +208,64 @@ expression:
        | '(' expression ')'                    { $$=$2; }
        ;
 
+elsif:
+       ELSIF_P
+       | ELSE_P IF_P
+       ;
+
+elsenode: 
+       EXPR_OPEN ELSE_P EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
+                               $$ = $4;
+               }
+       ;
+
+elsifnode:
+       EXPR_OPEN elsif expression EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+               }
+       | EXPR_OPEN elsif expression EXPR_CLOSE listnodes elsenode { 
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+                               $$->nodeData.condition.elseNode = $6;
+               }
+       | EXPR_OPEN elsif expression EXPR_CLOSE listnodes elsifnode {
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+                               $$->nodeData.condition.elseNode = $6;
+               }
+       ;
+
+ifnode:
+       EXPR_OPEN IF_P expression EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+               }
+       | EXPR_OPEN IF_P expression EXPR_CLOSE listnodes elsenode {
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+                               $$->nodeData.condition.elseNode = $6;
+               }
+       | EXPR_OPEN IF_P expression EXPR_CLOSE listnodes elsifnode {
+                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
+                               $$->type = ConditionNode;
+                               $$->nodeData.condition.expressionNode = $3;
+                               $$->nodeData.condition.ifNode = $5;
+                               $$->nodeData.condition.elseNode = $6;
+               }
+       ;
+       
+
 node:  
        TEXT_P  {
                                $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
@@ -237,19 +297,7 @@ node:
                                $$->nodeData.loop.varNameLength = strlen($3);
                                $$->nodeData.loop.bodyNode = $5;
                }
-       | EXPR_OPEN IF_P expression EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
-                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
-                               $$->type = ConditionNode;
-                               $$->nodeData.condition.expressionNode = $3;
-                               $$->nodeData.condition.ifNode = $5;
-               }
-       | EXPR_OPEN IF_P expression EXPR_CLOSE listnodes EXPR_OPEN ELSE_P EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
-                               $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
-                               $$->type = ConditionNode;
-                               $$->nodeData.condition.expressionNode = $3;
-                               $$->nodeData.condition.ifNode = $5;
-                               $$->nodeData.condition.elseNode = $9;
-               }
+       |       ifnode  {$$=$1;}
        ;
 
 %%