2 * Copyright 2014 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 typedef struct _source_elements_t source_elements_t
;
22 typedef struct _expression_t expression_t
;
23 typedef struct _statement_t statement_t
;
33 typedef struct _parser_ctx_t
{
39 source_elements_t
*source
;
41 BOOL implicit_nl_semicolon
;
52 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
53 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
55 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
57 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
59 return heap_pool_alloc(&ctx
->heap
, size
);
62 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
64 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
67 BOOL
is_identifier_char(WCHAR
) DECLSPEC_HIDDEN
;
68 BOOL
unescape(WCHAR
*) DECLSPEC_HIDDEN
;
69 HRESULT
parse_decimal(const WCHAR
**,const WCHAR
*,double*) DECLSPEC_HIDDEN
;
93 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
94 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
96 typedef struct _variable_declaration_t
{
97 const WCHAR
*identifier
;
100 struct _variable_declaration_t
*next
;
101 struct _variable_declaration_t
*global_next
; /* for compiler */
102 } variable_declaration_t
;
123 struct _statement_t
{
124 statement_type_t type
;
130 statement_t
*stat_list
;
135 variable_declaration_t
*variable_list
;
141 } expression_statement_t
;
146 statement_t
*if_stat
;
147 statement_t
*else_stat
;
154 statement_t
*statement
;
159 variable_declaration_t
*variable_list
;
160 expression_t
*begin_expr
;
162 expression_t
*end_expr
;
163 statement_t
*statement
;
168 variable_declaration_t
*variable
;
170 expression_t
*in_expr
;
171 statement_t
*statement
;
176 const WCHAR
*identifier
;
177 } branch_statement_t
;
182 statement_t
*statement
;
187 const WCHAR
*identifier
;
188 statement_t
*statement
;
189 } labelled_statement_t
;
191 typedef struct _case_clausule_t
{
195 struct _case_clausule_t
*next
;
201 case_clausule_t
*case_list
;
202 } switch_statement_t
;
205 const WCHAR
*identifier
;
206 statement_t
*statement
;
211 statement_t
*try_statement
;
212 catch_block_t
*catch_block
;
213 statement_t
*finally_statement
;
277 struct _expression_t
{
278 expression_type_t type
;
281 typedef struct _parameter_t
{
282 const WCHAR
*identifier
;
283 struct _parameter_t
*next
;
286 struct _source_elements_t
{
287 statement_t
*statement
;
288 statement_t
*statement_tail
;
291 typedef struct _function_expression_t
{
293 const WCHAR
*identifier
;
294 const WCHAR
*event_target
;
295 parameter_t
*parameter_list
;
296 source_elements_t
*source_elements
;
297 const WCHAR
*src_str
;
301 struct _function_expression_t
*next
; /* for compiler */
302 } function_expression_t
;
306 expression_t
*expression1
;
307 expression_t
*expression2
;
308 } binary_expression_t
;
312 expression_t
*expression
;
313 } unary_expression_t
;
317 expression_t
*expression
;
318 expression_t
*true_expression
;
319 expression_t
*false_expression
;
320 } conditional_expression_t
;
324 expression_t
*expression
;
325 const WCHAR
*identifier
;
326 } member_expression_t
;
328 typedef struct _argument_t
{
331 struct _argument_t
*next
;
336 expression_t
*expression
;
337 argument_t
*argument_list
;
342 const WCHAR
*identifier
;
343 } identifier_expression_t
;
348 } literal_expression_t
;
350 typedef struct _array_element_t
{
354 struct _array_element_t
*next
;
359 array_element_t
*element_list
;
361 } array_literal_expression_t
;
363 typedef struct _prop_val_t
{
367 struct _prop_val_t
*next
;
372 prop_val_t
*property_list
;
373 } property_value_expression_t
;
375 BOOL
try_parse_ccval(parser_ctx_t
*,ccval_t
*) DECLSPEC_HIDDEN
;
376 BOOL
parse_cc_expr(parser_ctx_t
*) DECLSPEC_HIDDEN
;
378 static inline ccval_t
ccval_num(double n
)
386 static inline ccval_t
ccval_bool(BOOL b
)
394 static inline BOOL
get_ccbool(ccval_t v
)
396 return v
.is_num
? v
.u
.n
!= 0 : v
.u
.b
;
399 static inline double get_ccnum(ccval_t v
)
401 return v
.is_num
? v
.u
.n
: v
.u
.b
;