X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=blobdiff_plain;f=tmpl_gram.y;h=aa7cebc9007831dde6ceca7259bf076988639d1b;hb=HEAD;hp=3335903508f491aaafdf1c1aab4d7b302eed3f5b;hpb=029b7a56ef910c2430ddb40a7383c7caa640ecc1;p=tedtools.git diff --git a/tmpl_gram.y b/tmpl_gram.y index 3335903..aa7cebc 100644 --- a/tmpl_gram.y +++ b/tmpl_gram.y @@ -26,18 +26,20 @@ static GList *makeList2(void *a, void *b); char *str; char punct; int flags; - int intval; + int64_t intval; double floatval; TemplateNode node; GList *list; } %type node +%type ifnode elsenode elsifnode %type listnodes %type template %type expression %type list_expression %type varname +%type elsif %type opt_escape %type opt_format @@ -49,7 +51,7 @@ static GList *makeList2(void *a, void *b); %token LEXEME %token VAR_OPEN VAR_CLOSE EXPR_OPEN EXPR_CLOSE INCLUDE_OPEN INCLUDE_CLOSE -%token HTMLESCAPE URLESCAPE IF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P +%token HTMLESCAPE URLESCAPE IF_P ELSIF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P SELF_P %token CMP_P %token INTEGER @@ -96,6 +98,7 @@ varname: | IF_P | ELSE_P | LOOP_P + | SELF_P | ENDIF_P | ENDLOOP_P ; @@ -205,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) ); @@ -225,6 +286,10 @@ node: $$->type = IncludeNode; $$->nodeData.includeFile = $2; } + | EXPR_OPEN SELF_P EXPR_CLOSE { + $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) ); + $$->type = NestNode; + } | EXPR_OPEN LOOP_P varname EXPR_CLOSE listnodes EXPR_OPEN ENDLOOP_P EXPR_CLOSE { $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) ); $$->type = LoopNode; @@ -232,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;} ; %%