cmd/tests: Make sure for /f doesn't loop infinitely on NULs.
[wine.git] / dlls / vbscript / parser.y
blob90ed921c2a940747595209449dcd3ba654bd7d1f
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "vbscript.h"
22 #include "parse.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
28 static int parser_error(unsigned*,parser_ctx_t*,const char*);
30 static void handle_isexpression_script(parser_ctx_t *ctx, expression_t *expr);
32 static void source_add_statement(parser_ctx_t*,statement_t*);
33 static void source_add_class(parser_ctx_t*,class_decl_t*);
35 static void *new_expression(parser_ctx_t*,expression_type_t,size_t);
36 static expression_t *new_bool_expression(parser_ctx_t*,VARIANT_BOOL);
37 static expression_t *new_date_expression(parser_ctx_t*,DATE);
38 static expression_t *new_string_expression(parser_ctx_t*,const WCHAR*);
39 static expression_t *new_long_expression(parser_ctx_t*,expression_type_t,LONG);
40 static expression_t *new_double_expression(parser_ctx_t*,double);
41 static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
42 static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
43 static expression_t *new_new_expression(parser_ctx_t*,const WCHAR*);
45 static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
46 static call_expression_t *new_call_expression(parser_ctx_t*,expression_t*,expression_t*);
47 static call_expression_t *make_call_expression(parser_ctx_t*,expression_t*,expression_t*);
49 static void *new_statement(parser_ctx_t*,statement_type_t,size_t,unsigned);
50 static statement_t *new_call_statement(parser_ctx_t*,unsigned,expression_t*);
51 static statement_t *new_assign_statement(parser_ctx_t*,unsigned,expression_t*,expression_t*);
52 static statement_t *new_set_statement(parser_ctx_t*,unsigned,expression_t*,expression_t*);
53 static statement_t *new_dim_statement(parser_ctx_t*,unsigned,dim_decl_t*);
54 static statement_t *new_redim_statement(parser_ctx_t*,unsigned,const WCHAR*,BOOL,expression_t*);
55 static statement_t *new_while_statement(parser_ctx_t*,unsigned,statement_type_t,expression_t*,statement_t*);
56 static statement_t *new_forto_statement(parser_ctx_t*,unsigned,const WCHAR*,expression_t*,expression_t*,expression_t*,statement_t*);
57 static statement_t *new_foreach_statement(parser_ctx_t*,unsigned,const WCHAR*,expression_t*,statement_t*);
58 static statement_t *new_if_statement(parser_ctx_t*,unsigned,expression_t*,statement_t*,elseif_decl_t*,statement_t*);
59 static statement_t *new_function_statement(parser_ctx_t*,unsigned,function_decl_t*);
60 static statement_t *new_onerror_statement(parser_ctx_t*,unsigned,BOOL);
61 static statement_t *new_const_statement(parser_ctx_t*,unsigned,const_decl_t*);
62 static statement_t *new_select_statement(parser_ctx_t*,unsigned,expression_t*,case_clausule_t*);
63 static statement_t *new_with_statement(parser_ctx_t*,unsigned,expression_t*,statement_t*);
65 static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,BOOL,dim_list_t*);
66 static dim_list_t *new_dim(parser_ctx_t*,unsigned,dim_list_t*);
67 static elseif_decl_t *new_elseif_decl(parser_ctx_t*,unsigned,expression_t*,statement_t*);
68 static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*);
69 static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
70 static const_decl_t *new_const_decl(parser_ctx_t*,const WCHAR*,expression_t*);
71 static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_t*,case_clausule_t*);
73 static class_decl_t *new_class_decl(parser_ctx_t*);
74 static class_decl_t *add_class_function(parser_ctx_t*,class_decl_t*,function_decl_t*);
75 static class_decl_t *add_dim_prop(parser_ctx_t*,class_decl_t*,dim_decl_t*,unsigned);
77 static statement_t *link_statements(statement_t*,statement_t*);
79 #define STORAGE_IS_PRIVATE 1
80 #define STORAGE_IS_DEFAULT 2
82 #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
84 #define PARSER_LTYPE unsigned
85 #define YYLLOC_DEFAULT(Cur, Rhs, N) Cur = YYRHSLOC((Rhs), (N) ? 1 : 0)
89 %lex-param { parser_ctx_t *ctx }
90 %parse-param { parser_ctx_t *ctx }
91 %define api.prefix {parser_}
92 %define api.pure
93 %start Program
95 %union {
96 const WCHAR *string;
97 statement_t *statement;
98 expression_t *expression;
99 member_expression_t *member;
100 elseif_decl_t *elseif;
101 dim_decl_t *dim_decl;
102 dim_list_t *dim_list;
103 function_decl_t *func_decl;
104 arg_decl_t *arg_decl;
105 class_decl_t *class_decl;
106 const_decl_t *const_decl;
107 case_clausule_t *case_clausule;
108 unsigned uint;
109 LONG integer;
110 BOOL boolean;
111 double dbl;
112 DATE date;
115 %token tEXPRESSION tNL tEMPTYBRACKETS tEXPRLBRACKET
116 %token tLTEQ tGTEQ tNEQ
117 %token tSTOP tME tREM tDOT
118 %token <string> tTRUE tFALSE
119 %token <string> tNOT tAND tOR tXOR tEQV tIMP
120 %token <string> tIS tMOD
121 %token <string> tCALL tSUB tFUNCTION tGET tLET tCONST
122 %token <string> tDIM tREDIM tPRESERVE
123 %token <string> tIF tELSE tELSEIF tEND tTHEN tEXIT
124 %token <string> tWHILE tWEND tDO tLOOP tUNTIL tFOR tTO tEACH tIN
125 %token <string> tSELECT tCASE tWITH
126 %token <string> tBYREF tBYVAL
127 %token <string> tOPTION
128 %token <string> tNOTHING tEMPTY tNULL
129 %token <string> tCLASS tSET tNEW tPUBLIC tPRIVATE
130 %token <string> tNEXT tON tRESUME tGOTO
131 %token <string> tIdentifier tString
132 %token <string> tDEFAULT tERROR tEXPLICIT tPROPERTY tSTEP
133 %token <integer> tInt
134 %token <dbl> tDouble
135 %token <date> tDate
137 %type <statement> Statement SimpleStatement StatementNl StatementsNl StatementsNl_opt BodyStatements IfStatement Else_opt
138 %type <statement> GlobalDimDeclaration
139 %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression ExpressionNl_opt
140 %type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
141 %type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression SignExpression
142 %type <expression> ConstExpression NumericLiteralExpression
143 %type <member> MemberExpression
144 %type <expression> Arguments ArgumentList ArgumentList_opt Step_opt ExpressionList
145 %type <boolean> DoType Preserve_opt
146 %type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
147 %type <func_decl> FunctionDecl PropertyDecl
148 %type <elseif> ElseIfs_opt ElseIfs ElseIf
149 %type <class_decl> ClassDeclaration ClassBody
150 %type <uint> Storage Storage_opt IntegerValue
151 %type <dim_decl> DimDeclList DimDecl
152 %type <dim_list> DimList
153 %type <const_decl> ConstDecl ConstDeclList
154 %type <string> Identifier
155 %type <case_clausule> CaseClausules
159 Program
160 : OptionExplicit_opt SourceElements
161 | tEXPRESSION ExpressionNl_opt { handle_isexpression_script(ctx, $2); }
163 OptionExplicit_opt
164 : /* empty */
165 | tOPTION tEXPLICIT StSep { ctx->option_explicit = TRUE; }
167 SourceElements
168 : /* empty */
169 | SourceElements GlobalDimDeclaration StSep
170 { source_add_statement(ctx, $2); }
171 | SourceElements StatementNl { source_add_statement(ctx, $2); }
172 | SourceElements ClassDeclaration { source_add_class(ctx, $2); }
174 GlobalDimDeclaration
175 : tPRIVATE DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; }
176 | tPUBLIC DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; }
178 ExpressionNl_opt
179 : /* empty */ { $$ = NULL; }
180 | Expression tNL { $$ = $1; }
182 BodyStatements
183 : /* empty */ { $$ = NULL; }
184 | Statement { $$ = $1; }
185 | StatementNl BodyStatements { $$ = link_statements($1, $2); }
187 StatementsNl_opt
188 : /* empty */ { $$ = NULL; }
189 | StatementsNl { $$ = $1; }
191 StatementsNl
192 : SimpleStatement StSep { $$ = $1; }
193 | SimpleStatement StSep StatementsNl { $$ = link_statements($1, $3); }
195 StatementNl
196 : Statement tNL { $$ = $1; }
198 Statement
199 : ':' { $$ = NULL; }
200 | ':' Statement { $$ = $2; }
201 | SimpleStatement { $$ = $1; }
202 | SimpleStatement ':' Statement { $1->next = $3; $$ = $1; }
203 | SimpleStatement ':' { $$ = $1; }
205 SimpleStatement
206 : CallExpression ArgumentList_opt { call_expression_t *call_expr = make_call_expression(ctx, $1, $2); CHECK_ERROR;
207 $$ = new_call_statement(ctx, @$, &call_expr->expr); CHECK_ERROR; };
208 | tCALL UnaryExpression { $$ = new_call_statement(ctx, @$, $2); CHECK_ERROR; }
209 | CallExpression '=' Expression
210 { $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; }
211 | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; }
212 | tREDIM Preserve_opt tIdentifier '(' ArgumentList ')'
213 { $$ = new_redim_statement(ctx, @$, $3, $2, $5); CHECK_ERROR; }
214 | IfStatement { $$ = $1; }
215 | tWHILE Expression StSep StatementsNl_opt tWEND
216 { $$ = new_while_statement(ctx, @$, STAT_WHILE, $2, $4); CHECK_ERROR; }
217 | tDO DoType Expression StSep StatementsNl_opt tLOOP
218 { $$ = new_while_statement(ctx, @$, $2 ? STAT_WHILELOOP : STAT_UNTIL, $3, $5);
219 CHECK_ERROR; }
220 | tDO StSep StatementsNl_opt tLOOP DoType Expression
221 { $$ = new_while_statement(ctx, @4, $5 ? STAT_DOWHILE : STAT_DOUNTIL, $6, $3);
222 CHECK_ERROR; }
223 | tDO StSep StatementsNl_opt tLOOP { $$ = new_while_statement(ctx, @$, STAT_DOWHILE, NULL, $3); CHECK_ERROR; }
224 | FunctionDecl { $$ = new_function_statement(ctx, @$, $1); CHECK_ERROR; }
225 | tEXIT tDO { $$ = new_statement(ctx, STAT_EXITDO, 0, @$); CHECK_ERROR; }
226 | tEXIT tFOR { $$ = new_statement(ctx, STAT_EXITFOR, 0, @$); CHECK_ERROR; }
227 | tEXIT tFUNCTION { $$ = new_statement(ctx, STAT_EXITFUNC, 0, @$); CHECK_ERROR; }
228 | tEXIT tPROPERTY { $$ = new_statement(ctx, STAT_EXITPROP, 0, @$); CHECK_ERROR; }
229 | tEXIT tSUB { $$ = new_statement(ctx, STAT_EXITSUB, 0, @$); CHECK_ERROR; }
230 | tSET CallExpression '=' Expression { $$ = new_set_statement(ctx, @$, $2, $4); CHECK_ERROR; }
231 | tSTOP { $$ = new_statement(ctx, STAT_STOP, 0, @$); CHECK_ERROR; }
232 | tON tERROR tRESUME tNEXT { $$ = new_onerror_statement(ctx, @$, TRUE); CHECK_ERROR; }
233 | tON tERROR tGOTO '0' { $$ = new_onerror_statement(ctx, @$, FALSE); CHECK_ERROR; }
234 | tCONST ConstDeclList { $$ = new_const_statement(ctx, @$, $2); CHECK_ERROR; }
235 | tFOR Identifier '=' Expression tTO Expression Step_opt StSep StatementsNl_opt tNEXT
236 { $$ = new_forto_statement(ctx, @$, $2, $4, $6, $7, $9); CHECK_ERROR; }
237 | tFOR tEACH Identifier tIN Expression StSep StatementsNl_opt tNEXT
238 { $$ = new_foreach_statement(ctx, @$, $3, $5, $7); }
239 | tSELECT tCASE Expression StSep CaseClausules tEND tSELECT
240 { $$ = new_select_statement(ctx, @$, $3, $5); }
241 | tWITH Expression StSep StatementsNl_opt tEND tWITH
242 { $$ = new_with_statement(ctx, @$, $2, $4); }
244 MemberExpression
245 : Identifier { $$ = new_member_expression(ctx, NULL, $1); CHECK_ERROR; }
246 | CallExpression '.' tIdentifier { $$ = new_member_expression(ctx, $1, $3); CHECK_ERROR; }
247 | tDOT tIdentifier { expression_t *dot_expr = new_expression(ctx, EXPR_DOT, sizeof(*dot_expr)); CHECK_ERROR;
248 $$ = new_member_expression(ctx, dot_expr, $2); CHECK_ERROR; }
250 Preserve_opt
251 : /* empty */ { $$ = FALSE; }
252 | tPRESERVE { $$ = TRUE; }
254 DimDeclList
255 : DimDecl { $$ = $1; }
256 | DimDecl ',' DimDeclList { $1->next = $3; $$ = $1; }
258 DimDecl
259 : Identifier { $$ = new_dim_decl(ctx, $1, FALSE, NULL); CHECK_ERROR; }
260 | Identifier '(' DimList ')' { $$ = new_dim_decl(ctx, $1, TRUE, $3); CHECK_ERROR; }
261 | Identifier tEMPTYBRACKETS { $$ = new_dim_decl(ctx, $1, TRUE, NULL); CHECK_ERROR; }
263 DimList
264 : IntegerValue { $$ = new_dim(ctx, $1, NULL); }
265 | IntegerValue ',' DimList { $$ = new_dim(ctx, $1, $3); }
267 ConstDeclList
268 : ConstDecl { $$ = $1; }
269 | ConstDecl ',' ConstDeclList { $1->next = $3; $$ = $1; }
271 ConstDecl
272 : Identifier '=' ConstExpression { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; }
274 ConstExpression
275 : LiteralExpression { $$ = $1; }
276 | '-' NumericLiteralExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
278 DoType
279 : tWHILE { $$ = TRUE; }
280 | tUNTIL { $$ = FALSE; }
282 Step_opt
283 : /* empty */ { $$ = NULL;}
284 | tSTEP Expression { $$ = $2; }
286 IfStatement
287 : tIF Expression tTHEN tNL StatementsNl_opt ElseIfs_opt Else_opt tEND tIF
288 { $$ = new_if_statement(ctx, @$, $2, $5, $6, $7); CHECK_ERROR; }
289 | tIF Expression tTHEN Statement EndIf_opt { $$ = new_if_statement(ctx, @$, $2, $4, NULL, NULL); CHECK_ERROR; }
290 | tIF Expression tTHEN Statement tELSE Statement EndIf_opt
291 { $$ = new_if_statement(ctx, @$, $2, $4, NULL, $6); CHECK_ERROR; }
293 EndIf_opt
294 : /* empty */
295 | tEND tIF
297 ElseIfs_opt
298 : /* empty */ { $$ = NULL; }
299 | ElseIfs { $$ = $1; }
301 ElseIfs
302 : ElseIf { $$ = $1; }
303 | ElseIf ElseIfs { $1->next = $2; $$ = $1; }
305 ElseIf
306 : tELSEIF Expression tTHEN tNL StatementsNl_opt
307 { $$ = new_elseif_decl(ctx, @$, $2, $5); }
309 Else_opt
310 : /* empty */ { $$ = NULL; }
311 | tELSE tNL StatementsNl_opt { $$ = $3; }
313 CaseClausules
314 : /* empty */ { $$ = NULL; }
315 | tCASE tELSE StSep StatementsNl_opt { $$ = new_case_clausule(ctx, NULL, $4, NULL); }
316 | tCASE ExpressionList StSep StatementsNl_opt CaseClausules
317 { $$ = new_case_clausule(ctx, $2, $4, $5); }
319 Arguments
320 : tEMPTYBRACKETS { $$ = NULL; }
321 | '(' ArgumentList ')' { $$ = $2; }
323 ArgumentList_opt
324 : /* empty */ { $$ = NULL; }
325 | ArgumentList { $$ = $1; }
327 ArgumentList
328 : Expression { $$ = $1; }
329 | Expression ',' ArgumentList { $1->next = $3; $$ = $1; }
330 | ',' ArgumentList { $$ = new_expression(ctx, EXPR_NOARG, 0); CHECK_ERROR; $$->next = $2; }
332 EmptyBrackets_opt
333 : /* empty */
334 | tEMPTYBRACKETS
336 ExpressionList
337 : Expression { $$ = $1; }
338 | Expression ',' ExpressionList { $1->next = $3; $$ = $1; }
340 Expression
341 : EqvExpression { $$ = $1; }
342 | Expression tIMP EqvExpression { $$ = new_binary_expression(ctx, EXPR_IMP, $1, $3); CHECK_ERROR; }
344 EqvExpression
345 : XorExpression { $$ = $1; }
346 | EqvExpression tEQV XorExpression { $$ = new_binary_expression(ctx, EXPR_EQV, $1, $3); CHECK_ERROR; }
348 XorExpression
349 : OrExpression { $$ = $1; }
350 | XorExpression tXOR OrExpression { $$ = new_binary_expression(ctx, EXPR_XOR, $1, $3); CHECK_ERROR; }
352 OrExpression
353 : AndExpression { $$ = $1; }
354 | OrExpression tOR AndExpression { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); CHECK_ERROR; }
356 AndExpression
357 : NotExpression { $$ = $1; }
358 | AndExpression tAND NotExpression { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); CHECK_ERROR; }
360 NotExpression
361 : EqualityExpression { $$ = $1; }
362 | tNOT NotExpression { $$ = new_unary_expression(ctx, EXPR_NOT, $2); CHECK_ERROR; }
364 EqualityExpression
365 : ConcatExpression { $$ = $1; }
366 | EqualityExpression '=' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_EQUAL, $1, $3); CHECK_ERROR; }
367 | EqualityExpression tNEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_NEQUAL, $1, $3); CHECK_ERROR; }
368 | EqualityExpression '>' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GT, $1, $3); CHECK_ERROR; }
369 | EqualityExpression '<' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LT, $1, $3); CHECK_ERROR; }
370 | EqualityExpression tGTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GTEQ, $1, $3); CHECK_ERROR; }
371 | EqualityExpression tLTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LTEQ, $1, $3); CHECK_ERROR; }
372 | EqualityExpression tIS ConcatExpression { $$ = new_binary_expression(ctx, EXPR_IS, $1, $3); CHECK_ERROR; }
374 ConcatExpression
375 : AdditiveExpression { $$ = $1; }
376 | ConcatExpression '&' AdditiveExpression { $$ = new_binary_expression(ctx, EXPR_CONCAT, $1, $3); CHECK_ERROR; }
378 AdditiveExpression
379 : ModExpression { $$ = $1; }
380 | AdditiveExpression '+' ModExpression { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); CHECK_ERROR; }
381 | AdditiveExpression '-' ModExpression { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); CHECK_ERROR; }
383 ModExpression
384 : IntdivExpression { $$ = $1; }
385 | ModExpression tMOD IntdivExpression { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); CHECK_ERROR; }
387 IntdivExpression
388 : MultiplicativeExpression { $$ = $1; }
389 | IntdivExpression '\\' MultiplicativeExpression
390 { $$ = new_binary_expression(ctx, EXPR_IDIV, $1, $3); CHECK_ERROR; }
392 MultiplicativeExpression
393 : ExpExpression { $$ = $1; }
394 | MultiplicativeExpression '*' ExpExpression
395 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); CHECK_ERROR; }
396 | MultiplicativeExpression '/' ExpExpression
397 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); CHECK_ERROR; }
399 ExpExpression
400 : SignExpression { $$ = $1; }
401 | ExpExpression '^' SignExpression { $$ = new_binary_expression(ctx, EXPR_EXP, $1, $3); CHECK_ERROR; }
403 SignExpression
404 : UnaryExpression { $$ = $1; }
405 | '-' SignExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
406 | '+' SignExpression { $$ = $2; }
408 UnaryExpression
409 : LiteralExpression { $$ = $1; }
410 | CallExpression { $$ = $1; }
411 | tNEW Identifier { $$ = new_new_expression(ctx, $2); CHECK_ERROR; }
413 CallExpression
414 : PrimaryExpression { $$ = $1; }
415 | MemberExpression { $$ = &$1->expr; }
416 | CallExpression Arguments { call_expression_t *expr = new_call_expression(ctx, $1, $2); CHECK_ERROR;
417 $$ = &expr->expr; }
419 LiteralExpression
420 : tTRUE { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; }
421 | tFALSE { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; }
422 | tString { $$ = new_string_expression(ctx, $1); CHECK_ERROR; }
423 | tDate { $$ = new_date_expression(ctx, $1); CHECK_ERROR; }
424 | NumericLiteralExpression { $$ = $1; }
425 | tEMPTY { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; }
426 | tNULL { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; }
427 | tNOTHING { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; }
429 NumericLiteralExpression
430 : '0' { $$ = new_long_expression(ctx, EXPR_INT, 0); CHECK_ERROR; }
431 | tInt { $$ = new_long_expression(ctx, EXPR_INT, $1); CHECK_ERROR; }
432 | tDouble { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
434 IntegerValue
435 : '0' { $$ = 0; }
436 | tInt { $$ = $1; }
438 PrimaryExpression
439 : tEXPRLBRACKET Expression ')' { $$ = new_unary_expression(ctx, EXPR_BRACKETS, $2); }
440 | tME { $$ = new_expression(ctx, EXPR_ME, 0); CHECK_ERROR; }
442 ClassDeclaration
443 : tCLASS Identifier StSep ClassBody tEND tCLASS StSep { $4->name = $2; $$ = $4; }
445 ClassBody
446 : /* empty */ { $$ = new_class_decl(ctx); }
447 | FunctionDecl { $$ = add_class_function(ctx, new_class_decl(ctx), $1); CHECK_ERROR; }
448 | FunctionDecl StSep ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
449 /* FIXME: We should use DimDecl here to support arrays, but that conflicts with PropertyDecl. */
450 | Storage tIdentifier { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR;
451 $$ = add_dim_prop(ctx, new_class_decl(ctx), dim_decl, $1); CHECK_ERROR; }
452 | Storage tIdentifier StSep ClassBody { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR;
453 $$ = add_dim_prop(ctx, $4, dim_decl, $1); CHECK_ERROR; }
454 | tDIM DimDecl { $$ = add_dim_prop(ctx, new_class_decl(ctx), $2, 0); CHECK_ERROR; }
455 | tDIM DimDecl StSep ClassBody { $$ = add_dim_prop(ctx, $4, $2, 0); CHECK_ERROR; }
456 | PropertyDecl { $$ = add_class_function(ctx, new_class_decl(ctx), $1); CHECK_ERROR; }
457 | PropertyDecl StSep ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
459 PropertyDecl
460 : Storage_opt tPROPERTY tGET Identifier ArgumentsDecl_opt StSep BodyStatements tEND tPROPERTY
461 { $$ = new_function_decl(ctx, $4, FUNC_PROPGET, $1, $5, $7); CHECK_ERROR; }
462 | Storage_opt tPROPERTY tLET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND tPROPERTY
463 { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, $1, $6, $9); CHECK_ERROR; }
464 | Storage_opt tPROPERTY tSET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND tPROPERTY
465 { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, $1, $6, $9); CHECK_ERROR; }
467 FunctionDecl
468 : Storage_opt tSUB Identifier ArgumentsDecl_opt StSep BodyStatements tEND tSUB
469 { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
470 | Storage_opt tFUNCTION Identifier ArgumentsDecl_opt StSep BodyStatements tEND tFUNCTION
471 { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; }
473 Storage_opt
474 : /* empty*/ { $$ = 0; }
475 | Storage { $$ = $1; }
477 Storage
478 : tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; }
479 | tPUBLIC { $$ = 0; }
480 | tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
482 ArgumentsDecl_opt
483 : EmptyBrackets_opt { $$ = NULL; }
484 | '(' ArgumentDeclList ')' { $$ = $2; }
486 ArgumentDeclList
487 : ArgumentDecl { $$ = $1; }
488 | ArgumentDecl ',' ArgumentDeclList { $1->next = $3; $$ = $1; }
490 ArgumentDecl
491 : Identifier EmptyBrackets_opt { $$ = new_argument_decl(ctx, $1, TRUE); }
492 | tBYREF Identifier EmptyBrackets_opt { $$ = new_argument_decl(ctx, $2, TRUE); }
493 | tBYVAL Identifier EmptyBrackets_opt { $$ = new_argument_decl(ctx, $2, FALSE); }
495 /* these keywords may also be an identifier, depending on context */
496 Identifier
497 : tIdentifier { $$ = $1; }
498 | tDEFAULT { ctx->last_token = tIdentifier; $$ = $1; }
499 | tERROR { ctx->last_token = tIdentifier; $$ = $1; }
500 | tEXPLICIT { ctx->last_token = tIdentifier; $$ = $1; }
501 | tPROPERTY { ctx->last_token = tIdentifier; $$ = $1; }
502 | tSTEP { ctx->last_token = tIdentifier; $$ = $1; }
504 /* Most statements accept both new line and ':' as separators */
505 StSep
506 : tNL
507 | ':'
508 | tNL StSep
509 | ':' StSep
513 static int parser_error(unsigned *loc, parser_ctx_t *ctx, const char *str)
515 if(ctx->error_loc == -1)
516 ctx->error_loc = *loc;
517 if(ctx->hres == S_OK) {
518 FIXME("%s: %s\n", debugstr_w(ctx->code + *loc), debugstr_a(str));
519 ctx->hres = E_FAIL;
520 }else {
521 WARN("%s: %08lx\n", debugstr_w(ctx->code + *loc), ctx->hres);
523 return 0;
526 static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
528 if(!stat)
529 return;
531 /* concatenate both linked lists */
532 if(ctx->stats) {
533 ctx->stats_tail->next = stat;
534 ctx->stats_tail = stat;
535 }else {
536 ctx->stats = ctx->stats_tail = stat;
538 /* find new tail */
539 while(ctx->stats_tail->next) {
540 ctx->stats_tail=ctx->stats_tail->next;
544 static void source_add_class(parser_ctx_t *ctx, class_decl_t *class_decl)
546 class_decl->next = ctx->class_decls;
547 ctx->class_decls = class_decl;
550 static void handle_isexpression_script(parser_ctx_t *ctx, expression_t *expr)
552 retval_statement_t *stat;
554 if(!expr)
555 return;
557 stat = new_statement(ctx, STAT_RETVAL, sizeof(*stat), 0);
558 if(!stat)
559 return;
561 stat->expr = expr;
562 ctx->stats = &stat->stat;
565 static void *new_expression(parser_ctx_t *ctx, expression_type_t type, size_t size)
567 expression_t *expr;
569 expr = parser_alloc(ctx, size ? size : sizeof(*expr));
570 if(expr) {
571 expr->type = type;
572 expr->next = NULL;
575 return expr;
578 static expression_t *new_bool_expression(parser_ctx_t *ctx, VARIANT_BOOL value)
580 bool_expression_t *expr;
582 expr = new_expression(ctx, EXPR_BOOL, sizeof(*expr));
583 if(!expr)
584 return NULL;
586 expr->value = value;
587 return &expr->expr;
590 static expression_t *new_string_expression(parser_ctx_t *ctx, const WCHAR *value)
592 string_expression_t *expr;
594 expr = new_expression(ctx, EXPR_STRING, sizeof(*expr));
595 if(!expr)
596 return NULL;
598 expr->value = value;
599 return &expr->expr;
602 static expression_t *new_date_expression(parser_ctx_t *ctx, DATE value)
604 date_expression_t *expr;
606 expr = new_expression(ctx, EXPR_DATE, sizeof(*expr));
607 if(!expr)
608 return NULL;
610 expr->value = value;
611 return &expr->expr;
614 static expression_t *new_long_expression(parser_ctx_t *ctx, expression_type_t type, LONG value)
616 int_expression_t *expr;
618 expr = new_expression(ctx, type, sizeof(*expr));
619 if(!expr)
620 return NULL;
622 expr->value = value;
623 return &expr->expr;
626 static expression_t *new_double_expression(parser_ctx_t *ctx, double value)
628 double_expression_t *expr;
630 expr = new_expression(ctx, EXPR_DOUBLE, sizeof(*expr));
631 if(!expr)
632 return NULL;
634 expr->value = value;
635 return &expr->expr;
638 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *subexpr)
640 unary_expression_t *expr;
642 expr = new_expression(ctx, type, sizeof(*expr));
643 if(!expr)
644 return NULL;
646 expr->subexpr = subexpr;
647 return &expr->expr;
650 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *left, expression_t *right)
652 binary_expression_t *expr;
654 expr = new_expression(ctx, type, sizeof(*expr));
655 if(!expr)
656 return NULL;
658 expr->left = left;
659 expr->right = right;
660 return &expr->expr;
663 static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
665 member_expression_t *expr;
667 expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
668 if(!expr)
669 return NULL;
671 expr->obj_expr = obj_expr;
672 expr->identifier = identifier;
673 return expr;
676 static call_expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expr, expression_t *arguments)
678 call_expression_t *call_expr;
680 call_expr = new_expression(ctx, EXPR_CALL, sizeof(*call_expr));
681 if(!call_expr)
682 return NULL;
684 call_expr->call_expr = expr;
685 call_expr->args = arguments;
686 return call_expr;
689 static call_expression_t *make_call_expression(parser_ctx_t *ctx, expression_t *callee_expr, expression_t *arguments)
691 call_expression_t *call_expr;
693 if(callee_expr->type == EXPR_MEMBER)
694 return new_call_expression(ctx, callee_expr, arguments);
695 if(callee_expr->type != EXPR_CALL) {
696 FIXME("Unhandled for expr type %u\n", callee_expr->type);
697 ctx->hres = E_FAIL;
698 return NULL;
700 call_expr = (call_expression_t*)callee_expr;
701 if(!call_expr->args) {
702 call_expr->args = arguments;
703 return call_expr;
706 if(call_expr->args->next) {
707 FIXME("Invalid syntax: invalid use of parentheses for arguments\n");
708 ctx->hres = E_FAIL;
709 return NULL;
712 call_expr->args = new_unary_expression(ctx, EXPR_BRACKETS, call_expr->args);
713 if(!call_expr->args)
714 return NULL;
715 if(!arguments)
716 return call_expr;
718 if(arguments->type != EXPR_NOARG) {
719 FIXME("Invalid syntax: missing comma\n");
720 ctx->hres = E_FAIL;
721 return NULL;
724 call_expr->args->next = arguments->next;
725 return call_expr;
728 static expression_t *new_new_expression(parser_ctx_t *ctx, const WCHAR *identifier)
730 string_expression_t *expr;
732 expr = new_expression(ctx, EXPR_NEW, sizeof(*expr));
733 if(!expr)
734 return NULL;
736 expr->value = identifier;
737 return &expr->expr;
740 static void *new_statement(parser_ctx_t *ctx, statement_type_t type, size_t size, unsigned loc)
742 statement_t *stat;
744 stat = parser_alloc(ctx, size ? size : sizeof(*stat));
745 if(stat) {
746 stat->type = type;
747 stat->loc = loc;
748 stat->next = NULL;
751 return stat;
754 static statement_t *new_call_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr)
756 call_expression_t *call_expr = NULL;
757 call_statement_t *stat;
759 stat = new_statement(ctx, STAT_CALL, sizeof(*stat), loc);
760 if(!stat)
761 return NULL;
763 switch(expr->type) {
764 case EXPR_MEMBER:
765 call_expr = new_call_expression(ctx, expr, NULL);
766 break;
767 case EXPR_CALL:
768 call_expr = (call_expression_t*)expr;
769 break;
770 default:
771 FIXME("Unsupported expr type %u\n", expr->type);
772 ctx->hres = E_NOTIMPL;
774 if(!call_expr)
775 return NULL;
777 stat->expr = call_expr;
778 return &stat->stat;
781 static statement_t *new_assign_statement(parser_ctx_t *ctx, unsigned loc, expression_t *left, expression_t *right)
783 assign_statement_t *stat;
785 stat = new_statement(ctx, STAT_ASSIGN, sizeof(*stat), loc);
786 if(!stat)
787 return NULL;
789 stat->left_expr = left;
790 stat->value_expr = right;
792 return &stat->stat;
795 static statement_t *new_set_statement(parser_ctx_t *ctx, unsigned loc, expression_t *left, expression_t *right)
797 assign_statement_t *stat;
799 stat = new_statement(ctx, STAT_SET, sizeof(*stat), loc);
800 if(!stat)
801 return NULL;
803 stat->left_expr = left;
804 stat->value_expr = right;
806 return &stat->stat;
809 static dim_decl_t *new_dim_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL is_array, dim_list_t *dims)
811 dim_decl_t *decl;
813 decl = parser_alloc(ctx, sizeof(*decl));
814 if(!decl)
815 return NULL;
817 decl->name = name;
818 decl->is_array = is_array;
819 decl->dims = dims;
820 decl->next = NULL;
821 return decl;
824 static dim_list_t *new_dim(parser_ctx_t *ctx, unsigned val, dim_list_t *next)
826 dim_list_t *ret;
828 ret = parser_alloc(ctx, sizeof(*ret));
829 if(!ret)
830 return NULL;
832 ret->val = val;
833 ret->next = next;
834 return ret;
837 static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, dim_decl_t *decls)
839 dim_statement_t *stat;
841 stat = new_statement(ctx, STAT_DIM, sizeof(*stat), loc);
842 if(!stat)
843 return NULL;
845 stat->dim_decls = decls;
846 return &stat->stat;
849 static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier, BOOL preserve, expression_t *dims)
851 redim_statement_t *stat;
853 stat = new_statement(ctx, STAT_REDIM, sizeof(*stat), loc);
854 if(!stat)
855 return NULL;
857 stat->identifier = identifier;
858 stat->preserve = preserve;
859 stat->dims = dims;
860 return &stat->stat;
863 static elseif_decl_t *new_elseif_decl(parser_ctx_t *ctx, unsigned loc, expression_t *expr, statement_t *stat)
865 elseif_decl_t *decl;
867 decl = parser_alloc(ctx, sizeof(*decl));
868 if(!decl)
869 return NULL;
871 decl->expr = expr;
872 decl->stat = stat;
873 decl->loc = loc;
874 decl->next = NULL;
875 return decl;
878 static statement_t *new_while_statement(parser_ctx_t *ctx, unsigned loc, statement_type_t type, expression_t *expr, statement_t *body)
880 while_statement_t *stat;
882 stat = new_statement(ctx, type, sizeof(*stat), loc);
883 if(!stat)
884 return NULL;
886 stat->expr = expr;
887 stat->body = body;
888 return &stat->stat;
891 static statement_t *new_forto_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier, expression_t *from_expr,
892 expression_t *to_expr, expression_t *step_expr, statement_t *body)
894 forto_statement_t *stat;
896 stat = new_statement(ctx, STAT_FORTO, sizeof(*stat), loc);
897 if(!stat)
898 return NULL;
900 stat->identifier = identifier;
901 stat->from_expr = from_expr;
902 stat->to_expr = to_expr;
903 stat->step_expr = step_expr;
904 stat->body = body;
905 return &stat->stat;
908 static statement_t *new_foreach_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier, expression_t *group_expr,
909 statement_t *body)
911 foreach_statement_t *stat;
913 stat = new_statement(ctx, STAT_FOREACH, sizeof(*stat), loc);
914 if(!stat)
915 return NULL;
917 stat->identifier = identifier;
918 stat->group_expr = group_expr;
919 stat->body = body;
920 return &stat->stat;
923 static statement_t *new_if_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr, statement_t *if_stat, elseif_decl_t *elseif_decl,
924 statement_t *else_stat)
926 if_statement_t *stat;
928 stat = new_statement(ctx, STAT_IF, sizeof(*stat), loc);
929 if(!stat)
930 return NULL;
932 stat->expr = expr;
933 stat->if_stat = if_stat;
934 stat->elseifs = elseif_decl;
935 stat->else_stat = else_stat;
936 return &stat->stat;
939 static statement_t *new_select_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr, case_clausule_t *case_clausules)
941 select_statement_t *stat;
943 stat = new_statement(ctx, STAT_SELECT, sizeof(*stat), loc);
944 if(!stat)
945 return NULL;
947 stat->expr = expr;
948 stat->case_clausules = case_clausules;
949 return &stat->stat;
952 static statement_t *new_with_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr, statement_t *body)
954 with_statement_t *stat;
956 stat = new_statement(ctx, STAT_WITH, sizeof(*stat), loc);
957 if(!stat)
958 return NULL;
960 stat->expr = expr;
961 stat->body = body;
962 return &stat->stat;
965 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_t *stat, case_clausule_t *next)
967 case_clausule_t *ret;
969 ret = parser_alloc(ctx, sizeof(*ret));
970 if(!ret)
971 return NULL;
973 ret->expr = expr;
974 ret->stat = stat;
975 ret->next = next;
976 return ret;
979 static statement_t *new_onerror_statement(parser_ctx_t *ctx, unsigned loc, BOOL resume_next)
981 onerror_statement_t *stat;
983 stat = new_statement(ctx, STAT_ONERROR, sizeof(*stat), loc);
984 if(!stat)
985 return NULL;
987 stat->resume_next = resume_next;
988 return &stat->stat;
991 static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL by_ref)
993 arg_decl_t *arg_decl;
995 arg_decl = parser_alloc(ctx, sizeof(*arg_decl));
996 if(!arg_decl)
997 return NULL;
999 arg_decl->name = name;
1000 arg_decl->by_ref = by_ref;
1001 arg_decl->next = NULL;
1002 return arg_decl;
1005 static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type,
1006 unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body)
1008 function_decl_t *decl;
1009 BOOL is_default = FALSE;
1011 if(storage_flags & STORAGE_IS_DEFAULT) {
1012 if(type == FUNC_PROPGET || type == FUNC_FUNCTION || type == FUNC_SUB) {
1013 is_default = TRUE;
1014 }else {
1015 FIXME("Invalid default property\n");
1016 ctx->hres = E_FAIL;
1017 return NULL;
1021 decl = parser_alloc(ctx, sizeof(*decl));
1022 if(!decl)
1023 return NULL;
1025 decl->name = name;
1026 decl->type = type;
1027 decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
1028 decl->is_default = is_default;
1029 decl->args = arg_decl;
1030 decl->body = body;
1031 decl->next = NULL;
1032 decl->next_prop_func = NULL;
1033 return decl;
1036 static statement_t *new_function_statement(parser_ctx_t *ctx, unsigned loc, function_decl_t *decl)
1038 function_statement_t *stat;
1040 stat = new_statement(ctx, STAT_FUNC, sizeof(*stat), loc);
1041 if(!stat)
1042 return NULL;
1044 stat->func_decl = decl;
1045 return &stat->stat;
1048 static class_decl_t *new_class_decl(parser_ctx_t *ctx)
1050 class_decl_t *class_decl;
1052 class_decl = parser_alloc(ctx, sizeof(*class_decl));
1053 if(!class_decl)
1054 return NULL;
1056 class_decl->funcs = NULL;
1057 class_decl->props = NULL;
1058 class_decl->next = NULL;
1059 return class_decl;
1062 static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_decl, function_decl_t *decl)
1064 function_decl_t *iter;
1066 for(iter = class_decl->funcs; iter; iter = iter->next) {
1067 if(!wcsicmp(iter->name, decl->name)) {
1068 if(decl->type == FUNC_SUB || decl->type == FUNC_FUNCTION) {
1069 FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
1070 ctx->hres = E_FAIL;
1071 return NULL;
1074 while(1) {
1075 if(iter->type == decl->type) {
1076 FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
1077 ctx->hres = E_FAIL;
1078 return NULL;
1080 if(!iter->next_prop_func)
1081 break;
1082 iter = iter->next_prop_func;
1085 iter->next_prop_func = decl;
1086 return class_decl;
1090 decl->next = class_decl->funcs;
1091 class_decl->funcs = decl;
1092 return class_decl;
1095 static class_decl_t *add_dim_prop(parser_ctx_t *ctx, class_decl_t *class_decl, dim_decl_t *dim_decl, unsigned storage_flags)
1097 if(storage_flags & STORAGE_IS_DEFAULT) {
1098 FIXME("variant prop van't be default value\n");
1099 ctx->hres = E_FAIL;
1100 return NULL;
1103 dim_decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
1104 dim_decl->next = class_decl->props;
1105 class_decl->props = dim_decl;
1106 return class_decl;
1109 static const_decl_t *new_const_decl(parser_ctx_t *ctx, const WCHAR *name, expression_t *expr)
1111 const_decl_t *decl;
1113 decl = parser_alloc(ctx, sizeof(*decl));
1114 if(!decl)
1115 return NULL;
1117 decl->name = name;
1118 decl->value_expr = expr;
1119 decl->next = NULL;
1120 return decl;
1123 static statement_t *new_const_statement(parser_ctx_t *ctx, unsigned loc, const_decl_t *decls)
1125 const_statement_t *stat;
1127 stat = new_statement(ctx, STAT_CONST, sizeof(*stat), loc);
1128 if(!stat)
1129 return NULL;
1131 stat->decls = decls;
1132 return &stat->stat;
1135 static statement_t *link_statements(statement_t *head, statement_t *tail)
1137 statement_t *iter;
1139 for(iter = head; iter->next; iter = iter->next);
1140 iter->next = tail;
1142 return head;
1145 void *parser_alloc(parser_ctx_t *ctx, size_t size)
1147 void *ret;
1149 ret = heap_pool_alloc(&ctx->heap, size);
1150 if(!ret)
1151 ctx->hres = E_OUTOFMEMORY;
1152 return ret;
1155 HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter, DWORD flags)
1157 ctx->code = ctx->ptr = code;
1158 ctx->end = ctx->code + lstrlenW(ctx->code);
1160 heap_pool_init(&ctx->heap);
1162 ctx->hres = S_OK;
1163 ctx->error_loc = -1;
1164 ctx->last_token = tNL;
1165 ctx->last_nl = 0;
1166 ctx->stats = ctx->stats_tail = NULL;
1167 ctx->class_decls = NULL;
1168 ctx->option_explicit = FALSE;
1169 ctx->is_html = delimiter && !wcsicmp(delimiter, L"</script>");
1171 if(flags & SCRIPTTEXT_ISEXPRESSION)
1172 ctx->last_token = tEXPRESSION;
1174 parser_parse(ctx);
1176 return ctx->hres;
1179 void parser_release(parser_ctx_t *ctx)
1181 heap_pool_free(&ctx->heap);