Reactos
1/*
2 * Copyright 2011 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#pragma once
20
21typedef enum {
22 EXPR_ADD,
23 EXPR_AND,
24 EXPR_BOOL,
25 EXPR_BRACKETS,
26 EXPR_CONCAT,
27 EXPR_DIV,
28 EXPR_DOUBLE,
29 EXPR_EMPTY,
30 EXPR_EQUAL,
31 EXPR_EQV,
32 EXPR_EXP,
33 EXPR_GT,
34 EXPR_GTEQ,
35 EXPR_IDIV,
36 EXPR_IMP,
37 EXPR_INT,
38 EXPR_IS,
39 EXPR_LT,
40 EXPR_LTEQ,
41 EXPR_ME,
42 EXPR_MEMBER,
43 EXPR_MOD,
44 EXPR_MUL,
45 EXPR_NEG,
46 EXPR_NEQUAL,
47 EXPR_NEW,
48 EXPR_NOARG, /* not a real expression */
49 EXPR_NOT,
50 EXPR_NOTHING,
51 EXPR_NULL,
52 EXPR_OR,
53 EXPR_STRING,
54 EXPR_SUB,
55 EXPR_XOR
56} expression_type_t;
57
58typedef struct _expression_t {
59 expression_type_t type;
60 struct _expression_t *next;
61} expression_t;
62
63typedef struct {
64 expression_t expr;
65 VARIANT_BOOL value;
66} bool_expression_t;
67
68typedef struct {
69 expression_t expr;
70 LONG value;
71} int_expression_t;
72
73typedef struct {
74 expression_t expr;
75 double value;
76} double_expression_t;
77
78typedef struct {
79 expression_t expr;
80 const WCHAR *value;
81} string_expression_t;
82
83typedef struct {
84 expression_t expr;
85 expression_t *subexpr;
86} unary_expression_t;
87
88typedef struct {
89 expression_t expr;
90 expression_t *left;
91 expression_t *right;
92} binary_expression_t;
93
94typedef struct {
95 expression_t expr;
96 expression_t *obj_expr;
97 const WCHAR *identifier;
98 expression_t *args;
99} member_expression_t;
100
101typedef enum {
102 STAT_ASSIGN,
103 STAT_CALL,
104 STAT_CONST,
105 STAT_DIM,
106 STAT_DOUNTIL,
107 STAT_DOWHILE,
108 STAT_EXITDO,
109 STAT_EXITFOR,
110 STAT_EXITFUNC,
111 STAT_EXITPROP,
112 STAT_EXITSUB,
113 STAT_FOREACH,
114 STAT_FORTO,
115 STAT_FUNC,
116 STAT_IF,
117 STAT_ONERROR,
118 STAT_SELECT,
119 STAT_SET,
120 STAT_STOP,
121 STAT_UNTIL,
122 STAT_WHILE,
123 STAT_WHILELOOP,
124 STAT_RETVAL
125} statement_type_t;
126
127typedef struct _statement_t {
128 statement_type_t type;
129 struct _statement_t *next;
130} statement_t;
131
132typedef struct {
133 statement_t stat;
134 member_expression_t *expr;
135 BOOL is_strict;
136} call_statement_t;
137
138typedef struct {
139 statement_t stat;
140 member_expression_t *member_expr;
141 expression_t *value_expr;
142} assign_statement_t;
143
144typedef struct _dim_list_t {
145 unsigned val;
146 struct _dim_list_t *next;
147} dim_list_t;
148
149typedef struct _dim_decl_t {
150 const WCHAR *name;
151 BOOL is_array;
152 BOOL is_public; /* Used only for class members. */
153 dim_list_t *dims;
154 struct _dim_decl_t *next;
155} dim_decl_t;
156
157typedef struct _dim_statement_t {
158 statement_t stat;
159 dim_decl_t *dim_decls;
160} dim_statement_t;
161
162typedef struct _arg_decl_t {
163 const WCHAR *name;
164 BOOL by_ref;
165 struct _arg_decl_t *next;
166} arg_decl_t;
167
168typedef struct _function_decl_t {
169 const WCHAR *name;
170 function_type_t type;
171 BOOL is_public;
172 arg_decl_t *args;
173 statement_t *body;
174 struct _function_decl_t *next;
175 struct _function_decl_t *next_prop_func;
176} function_decl_t;
177
178typedef struct {
179 statement_t stat;
180 function_decl_t *func_decl;
181} function_statement_t;
182
183typedef struct _class_decl_t {
184 const WCHAR *name;
185 function_decl_t *funcs;
186 dim_decl_t *props;
187 struct _class_decl_t *next;
188} class_decl_t;
189
190typedef struct _elseif_decl_t {
191 expression_t *expr;
192 statement_t *stat;
193 struct _elseif_decl_t *next;
194} elseif_decl_t;
195
196typedef struct {
197 statement_t stat;
198 expression_t *expr;
199 statement_t *if_stat;
200 elseif_decl_t *elseifs;
201 statement_t *else_stat;
202} if_statement_t;
203
204typedef struct {
205 statement_t stat;
206 expression_t *expr;
207 statement_t *body;
208} while_statement_t;
209
210typedef struct {
211 statement_t stat;
212 const WCHAR *identifier;
213 expression_t *from_expr;
214 expression_t *to_expr;
215 expression_t *step_expr;
216 statement_t *body;
217} forto_statement_t;
218
219typedef struct {
220 statement_t stat;
221 const WCHAR *identifier;
222 expression_t *group_expr;
223 statement_t *body;
224} foreach_statement_t;
225
226typedef struct {
227 statement_t stat;
228 BOOL resume_next;
229} onerror_statement_t;
230
231typedef struct _const_decl_t {
232 const WCHAR *name;
233 expression_t *value_expr;
234 struct _const_decl_t *next;
235} const_decl_t;
236
237typedef struct {
238 statement_t stat;
239 const_decl_t *decls;
240} const_statement_t;
241
242typedef struct _case_clausule_t {
243 expression_t *expr;
244 statement_t *stat;
245 struct _case_clausule_t *next;
246} case_clausule_t;
247
248typedef struct {
249 statement_t stat;
250 expression_t *expr;
251 case_clausule_t *case_clausules;
252} select_statement_t;
253
254typedef struct {
255 statement_t stat;
256 expression_t *expr;
257} retval_statement_t;
258
259typedef struct {
260 const WCHAR *code;
261 const WCHAR *ptr;
262 const WCHAR *end;
263
264 BOOL option_explicit;
265 BOOL parse_complete;
266 BOOL is_html;
267 HRESULT hres;
268
269 int last_token;
270 unsigned last_nl;
271
272 statement_t *stats;
273 statement_t *stats_tail;
274 class_decl_t *class_decls;
275
276 heap_pool_t heap;
277} parser_ctx_t;
278
279HRESULT parse_script(parser_ctx_t*,const WCHAR*,const WCHAR*,DWORD) DECLSPEC_HIDDEN;
280void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
281int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
282void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;