9 extern char *fileToParse;
14 static int yyerror(char *s);
15 void startTemplateLex(Template tmpl, FILE *in);
17 static Template curTmpl;
18 extern int tmpl_yylineno;
31 %type <node> listnodes
33 %type <node> condition
34 %type <node> condition_varname
37 %type <flags> opt_escape
38 %type <flags> opt_global
39 %type <str> opt_default
40 %type <str> opt_format
47 %token <str> VAR_OPEN VAR_CLOSE EXPR_OPEN EXPR_CLOSE
48 INCLUDE_OPEN INCLUDE_CLOSE
49 %token <str> HTMLESCAPE URLESCAPE IF_P ELSE_P LOOP_P ENDIF_P ENDLOOP_P
55 listnodes { curTmpl->tree = $$ = $1; }
56 | { curTmpl->tree = $$ = NULL; }
62 if ( $1->type == CollectionNode ) {
63 GListPush( $1->nodeData.children, $2 );
66 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
67 $$->type = CollectionNode;
68 $$->nodeData.children = GListPush( $$->nodeData.children, $1 );
69 $$->nodeData.children = GListPush( $$->nodeData.children, $2 );
88 '|' HTMLESCAPE { $$=TND_HTMLESCAPE; }
89 | '|' URLESCAPE { $$=TND_URLESCAPE; }
94 '^' { $$=TND_GLOBAL; }
104 OR_P STRING { $$=$2; }
110 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
111 $$->type = ConditionNode;
112 $$->nodeData.condition.varName = $1;
113 $$->nodeData.condition.varNameLength = strlen($1);
116 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
117 $$->type = ConditionNode;
118 $$->nodeData.condition.flags = TND_GLOBAL;
119 $$->nodeData.condition.varName = $2;
120 $$->nodeData.condition.varNameLength = strlen($2);
128 | DEFINED_P condition_varname {
130 $$->nodeData.condition.flags |= TND_DEFINED;
134 if ( $$->nodeData.condition.flags & TND_NOT )
135 $$->nodeData.condition.flags &= ~TND_NOT;
137 $$->nodeData.condition.flags |= TND_NOT;
143 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
145 $$->nodeData.text.value = $1;
146 $$->nodeData.text.valueLength = strlen($1);
148 | VAR_OPEN opt_global varname opt_format opt_default opt_escape VAR_CLOSE {
149 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
150 $$->type = VariableNode;
151 $$->nodeData.variable.varName = $3;
152 $$->nodeData.variable.varNameLength = strlen($3);
153 $$->nodeData.variable.formatValue = $4;
154 $$->nodeData.variable.defaultValue = $5;
155 $$->nodeData.variable.flags = $2 | $6;
157 | INCLUDE_OPEN FILENAME INCLUDE_CLOSE {
158 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
159 $$->type = IncludeNode;
160 $$->nodeData.includeFile = $2;
162 | EXPR_OPEN LOOP_P varname EXPR_CLOSE listnodes EXPR_OPEN ENDLOOP_P EXPR_CLOSE {
163 $$ = mc0alloc( curTmpl->templateContext, sizeof(TemplateNodeData) );
165 $$->nodeData.loop.varName = $3;
166 $$->nodeData.loop.varNameLength = strlen($3);
167 $$->nodeData.loop.bodyNode = $5;
169 | EXPR_OPEN IF_P condition EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
171 $$->nodeData.condition.ifNode = $5;
173 | EXPR_OPEN IF_P condition EXPR_CLOSE listnodes EXPR_OPEN ELSE_P EXPR_CLOSE listnodes EXPR_OPEN ENDIF_P EXPR_CLOSE {
175 $$->nodeData.condition.ifNode = $5;
176 $$->nodeData.condition.elseNode = $9;
184 tlog(TL_CRIT,"template error at line %d in '%s': %s", tmpl_yylineno, fileToParse, s);
189 parseTemplateFile(Template tmpl, char* filename ) {
190 FILE *in = fopen(filename, "r");
194 tlog(TL_CRIT,"Can not open template file '%s': %s",
195 filename, strerror(errno));
200 curTmpl->tree = NULL;
202 fileToParse = filename;
203 startTemplateLex(tmpl, in);