8 extern char *fileToParse;
13 static int yyerror(char *s);
14 void startTemplateLex(Template tmpl, FILE *in);
16 static Template curTmpl;
17 extern int tmpl_yylineno;
30 %type <node> listnodes
32 %type <node> condition
33 %type <node> condition_varname
36 %type <flags> opt_escape
37 %type <flags> opt_global
38 %type <str> opt_default
39 %type <str> opt_format
46 %token <str> VAR_OPEN VAR_CLOSE EXPR_OPEN EXPR_CLOSE
47 INCLUDE_OPEN INCLUDE_CLOSE
48 %token <str> HTMLESCAPE URLESCAPE IF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P
54 listnodes { curTmpl->tree = $$ = $1; }
55 | { curTmpl->tree = $$ = NULL; }
61 if ( $1->type == CollectionNode ) {
62 GListPush( $1->nodeData.children, $2 );
65 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
66 $$->type = CollectionNode;
67 $$->nodeData.children = GListPush( $$->nodeData.children, $1 );
68 $$->nodeData.children = GListPush( $$->nodeData.children, $2 );
87 '|' HTMLESCAPE { $$=TND_HTMLESCAPE; }
88 | '|' URLESCAPE { $$=TND_URLESCAPE; }
93 '^' { $$=TND_GLOBAL; }
103 OR_P STRING { $$=$2; }
109 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
110 $$->type = ConditionNode;
111 $$->nodeData.condition.varName = $1;
112 $$->nodeData.condition.varNameLength = strlen($1);
115 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
116 $$->type = ConditionNode;
117 $$->nodeData.condition.flags = TND_GLOBAL;
118 $$->nodeData.condition.varName = $2;
119 $$->nodeData.condition.varNameLength = strlen($2);
127 | DEFINED_P condition_varname {
129 $$->nodeData.condition.flags |= TND_DEFINED;
133 if ( $$->nodeData.condition.flags & TND_NOT )
134 $$->nodeData.condition.flags &= ~TND_NOT;
136 $$->nodeData.condition.flags |= TND_NOT;
142 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
144 $$->nodeData.text.value = $1;
145 $$->nodeData.text.valueLength = strlen($1);
147 | VAR_OPEN opt_global varname opt_format opt_default opt_escape VAR_CLOSE {
148 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
149 $$->type = VariableNode;
150 $$->nodeData.variable.varName = $3;
151 $$->nodeData.variable.varNameLength = strlen($3);
152 $$->nodeData.variable.formatValue = $4;
153 $$->nodeData.variable.defaultValue = $5;
154 $$->nodeData.variable.flags = $2 | $6;
156 | INCLUDE_OPEN FILENAME INCLUDE_CLOSE {
157 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
158 $$->type = IncludeNode;
159 $$->nodeData.includeFile = $2;
161 | EXPR_OPEN LOOP_P varname EXPR_CLOSE listnodes EXPR_OPEN ENDLOOP_P EXPR_CLOSE {
162 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
164 $$->nodeData.loop.varName = $3;
165 $$->nodeData.loop.varNameLength = strlen($3);
166 $$->nodeData.loop.bodyNode = $5;
168 | EXPR_OPEN IF_P condition EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
170 $$->nodeData.condition.ifNode = $5;
172 | EXPR_OPEN IF_P condition EXPR_CLOSE listnodes EXPR_OPEN ELSE_P EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
174 $$->nodeData.condition.ifNode = $5;
175 $$->nodeData.condition.elseNode = $9;
183 tlog(TL_CRIT,"template error at line %d in '%s': %s", tmpl_yylineno, fileToParse, s);
188 parseTemplateFile(Template tmpl, char* filename ) {
189 FILE *in = fopen(filename, "r");
196 curTmpl->tree = NULL;
198 fileToParse = filename;
199 startTemplateLex(tmpl, in);