}
%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
%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
| '(' 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) );
$$->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;}
;
%%