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
);
87 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
88 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
90 typedef struct _variable_declaration_t
{
91 const WCHAR
*identifier
;
94 struct _variable_declaration_t
*next
;
95 struct _variable_declaration_t
*global_next
; /* for compiler */
96 } variable_declaration_t
;
117 struct _statement_t
{
118 statement_type_t type
;
124 statement_t
*stat_list
;
129 variable_declaration_t
*variable_list
;
135 } expression_statement_t
;
140 statement_t
*if_stat
;
141 statement_t
*else_stat
;
148 statement_t
*statement
;
153 variable_declaration_t
*variable_list
;
154 expression_t
*begin_expr
;
156 expression_t
*end_expr
;
157 statement_t
*statement
;
162 variable_declaration_t
*variable
;
164 expression_t
*in_expr
;
165 statement_t
*statement
;
170 const WCHAR
*identifier
;
171 } branch_statement_t
;
176 statement_t
*statement
;
181 const WCHAR
*identifier
;
182 statement_t
*statement
;
183 } labelled_statement_t
;
185 typedef struct _case_clausule_t
{
189 struct _case_clausule_t
*next
;
195 case_clausule_t
*case_list
;
196 } switch_statement_t
;
199 const WCHAR
*identifier
;
200 statement_t
*statement
;
205 statement_t
*try_statement
;
206 catch_block_t
*catch_block
;
207 statement_t
*finally_statement
;
271 struct _expression_t
{
272 expression_type_t type
;
275 typedef struct _parameter_t
{
276 const WCHAR
*identifier
;
277 struct _parameter_t
*next
;
280 struct _source_elements_t
{
281 statement_t
*statement
;
282 statement_t
*statement_tail
;
285 typedef struct _function_expression_t
{
287 const WCHAR
*identifier
;
288 const WCHAR
*event_target
;
289 parameter_t
*parameter_list
;
290 source_elements_t
*source_elements
;
291 const WCHAR
*src_str
;
294 struct _function_expression_t
*next
; /* for compiler */
295 } function_expression_t
;
299 expression_t
*expression1
;
300 expression_t
*expression2
;
301 } binary_expression_t
;
305 expression_t
*expression
;
306 } unary_expression_t
;
310 expression_t
*expression
;
311 expression_t
*true_expression
;
312 expression_t
*false_expression
;
313 } conditional_expression_t
;
317 expression_t
*expression
;
318 const WCHAR
*identifier
;
319 } member_expression_t
;
321 typedef struct _argument_t
{
324 struct _argument_t
*next
;
329 expression_t
*expression
;
330 argument_t
*argument_list
;
335 const WCHAR
*identifier
;
336 } identifier_expression_t
;
341 } literal_expression_t
;
343 typedef struct _array_element_t
{
347 struct _array_element_t
*next
;
352 array_element_t
*element_list
;
354 } array_literal_expression_t
;
356 typedef struct _prop_val_t
{
360 struct _prop_val_t
*next
;
365 prop_val_t
*property_list
;
366 } property_value_expression_t
;
368 BOOL
try_parse_ccval(parser_ctx_t
*,ccval_t
*) DECLSPEC_HIDDEN
;
369 BOOL
parse_cc_expr(parser_ctx_t
*) DECLSPEC_HIDDEN
;
371 static inline ccval_t
ccval_num(double n
)
379 static inline ccval_t
ccval_bool(BOOL b
)
387 static inline BOOL
get_ccbool(ccval_t v
)
389 return v
.is_num
? v
.u
.n
!= 0 : v
.u
.b
;
392 static inline double get_ccnum(ccval_t v
)
394 return v
.is_num
? v
.u
.n
: v
.u
.b
;