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
19 typedef struct _source_elements_t source_elements_t
;
20 typedef struct _expression_t expression_t
;
21 typedef struct _statement_t statement_t
;
31 typedef struct _parser_ctx_t
{
37 source_elements_t
*source
;
39 BOOL implicit_nl_semicolon
;
50 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
51 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
53 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
55 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
57 return heap_pool_alloc(&ctx
->heap
, size
);
60 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
62 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
65 BOOL
is_identifier_char(WCHAR
) DECLSPEC_HIDDEN
;
66 BOOL
unescape(WCHAR
*) DECLSPEC_HIDDEN
;
67 HRESULT
parse_decimal(const WCHAR
**,const WCHAR
*,double*) DECLSPEC_HIDDEN
;
91 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
92 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
94 typedef struct _variable_declaration_t
{
95 const WCHAR
*identifier
;
98 struct _variable_declaration_t
*next
;
99 struct _variable_declaration_t
*global_next
; /* for compiler */
100 } variable_declaration_t
;
121 struct _statement_t
{
122 statement_type_t type
;
128 statement_t
*stat_list
;
133 variable_declaration_t
*variable_list
;
139 } expression_statement_t
;
144 statement_t
*if_stat
;
145 statement_t
*else_stat
;
152 statement_t
*statement
;
157 variable_declaration_t
*variable_list
;
158 expression_t
*begin_expr
;
160 expression_t
*end_expr
;
161 statement_t
*statement
;
166 variable_declaration_t
*variable
;
168 expression_t
*in_expr
;
169 statement_t
*statement
;
174 const WCHAR
*identifier
;
175 } branch_statement_t
;
180 statement_t
*statement
;
185 const WCHAR
*identifier
;
186 statement_t
*statement
;
187 } labelled_statement_t
;
189 typedef struct _case_clausule_t
{
193 struct _case_clausule_t
*next
;
199 case_clausule_t
*case_list
;
200 } switch_statement_t
;
203 const WCHAR
*identifier
;
204 statement_t
*statement
;
209 statement_t
*try_statement
;
210 catch_block_t
*catch_block
;
211 statement_t
*finally_statement
;
275 struct _expression_t
{
276 expression_type_t type
;
279 typedef struct _parameter_t
{
280 const WCHAR
*identifier
;
281 struct _parameter_t
*next
;
284 struct _source_elements_t
{
285 statement_t
*statement
;
286 statement_t
*statement_tail
;
289 typedef struct _function_expression_t
{
291 const WCHAR
*identifier
;
292 const WCHAR
*event_target
;
293 parameter_t
*parameter_list
;
294 source_elements_t
*source_elements
;
295 const WCHAR
*src_str
;
298 struct _function_expression_t
*next
; /* for compiler */
299 } function_expression_t
;
303 expression_t
*expression1
;
304 expression_t
*expression2
;
305 } binary_expression_t
;
309 expression_t
*expression
;
310 } unary_expression_t
;
314 expression_t
*expression
;
315 expression_t
*true_expression
;
316 expression_t
*false_expression
;
317 } conditional_expression_t
;
321 expression_t
*expression
;
322 const WCHAR
*identifier
;
323 } member_expression_t
;
325 typedef struct _argument_t
{
328 struct _argument_t
*next
;
333 expression_t
*expression
;
334 argument_t
*argument_list
;
339 const WCHAR
*identifier
;
340 } identifier_expression_t
;
345 } literal_expression_t
;
347 typedef struct _array_element_t
{
351 struct _array_element_t
*next
;
356 array_element_t
*element_list
;
358 } array_literal_expression_t
;
360 typedef struct _prop_val_t
{
364 struct _prop_val_t
*next
;
369 prop_val_t
*property_list
;
370 } property_value_expression_t
;
372 BOOL
try_parse_ccval(parser_ctx_t
*,ccval_t
*) DECLSPEC_HIDDEN
;
373 BOOL
parse_cc_expr(parser_ctx_t
*) DECLSPEC_HIDDEN
;
375 static inline ccval_t
ccval_num(double n
)
383 static inline ccval_t
ccval_bool(BOOL b
)
391 static inline BOOL
get_ccbool(ccval_t v
)
393 return v
.is_num
? v
.u
.n
!= 0 : v
.u
.b
;
396 static inline double get_ccnum(ccval_t v
)
398 return v
.is_num
? v
.u
.n
: v
.u
.b
;