2 * Copyright 2008 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
20 #include "wine/port.h"
30 #include "parser.tab.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
37 static const WCHAR breakW
[] = {'b','r','e','a','k',0};
38 static const WCHAR caseW
[] = {'c','a','s','e',0};
39 static const WCHAR catchW
[] = {'c','a','t','c','h',0};
40 static const WCHAR continueW
[] = {'c','o','n','t','i','n','u','e',0};
41 static const WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0};
42 static const WCHAR deleteW
[] = {'d','e','l','e','t','e',0};
43 static const WCHAR doW
[] = {'d','o',0};
44 static const WCHAR elseW
[] = {'e','l','s','e',0};
45 static const WCHAR falseW
[] = {'f','a','l','s','e',0};
46 static const WCHAR finallyW
[] = {'f','i','n','a','l','l','y',0};
47 static const WCHAR forW
[] = {'f','o','r',0};
48 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
49 static const WCHAR ifW
[] = {'i','f',0};
50 static const WCHAR inW
[] = {'i','n',0};
51 static const WCHAR instanceofW
[] = {'i','n','s','t','a','n','c','e','o','f',0};
52 static const WCHAR newW
[] = {'n','e','w',0};
53 static const WCHAR nullW
[] = {'n','u','l','l',0};
54 static const WCHAR returnW
[] = {'r','e','t','u','r','n',0};
55 static const WCHAR switchW
[] = {'s','w','i','t','c','h',0};
56 static const WCHAR thisW
[] = {'t','h','i','s',0};
57 static const WCHAR throwW
[] = {'t','h','r','o','w',0};
58 static const WCHAR trueW
[] = {'t','r','u','e',0};
59 static const WCHAR tryW
[] = {'t','r','y',0};
60 static const WCHAR typeofW
[] = {'t','y','p','e','o','f',0};
61 static const WCHAR varW
[] = {'v','a','r',0};
62 static const WCHAR voidW
[] = {'v','o','i','d',0};
63 static const WCHAR whileW
[] = {'w','h','i','l','e',0};
64 static const WCHAR withW
[] = {'w','i','t','h',0};
66 static const WCHAR elifW
[] = {'e','l','i','f',0};
67 static const WCHAR endW
[] = {'e','n','d',0};
74 {breakW
, kBREAK
, TRUE
},
77 {continueW
, kCONTINUE
, TRUE
},
85 {functionW
, kFUNCTION
},
88 {instanceofW
, kINSTANCEOF
},
91 {returnW
, kRETURN
, TRUE
},
104 static int lex_error(parser_ctx_t
*ctx
, HRESULT hres
)
107 ctx
->lexer_error
= TRUE
;
111 /* ECMA-262 3rd Edition 7.6 */
112 BOOL
is_identifier_char(WCHAR c
)
114 return isalnumW(c
) || c
== '$' || c
== '_' || c
== '\\';
117 static BOOL
is_identifier_first_char(WCHAR c
)
119 return isalphaW(c
) || c
== '$' || c
== '_' || c
== '\\';
122 static int check_keyword(parser_ctx_t
*ctx
, const WCHAR
*word
, const WCHAR
**lval
)
124 const WCHAR
*p1
= ctx
->ptr
;
125 const WCHAR
*p2
= word
;
127 while(p1
< ctx
->end
&& *p2
) {
134 if(*p2
|| (p1
< ctx
->end
&& is_identifier_char(*p1
)))
143 /* ECMA-262 3rd Edition 7.3 */
144 static BOOL
is_endline(WCHAR c
)
146 return c
== '\n' || c
== '\r' || c
== 0x2028 || c
== 0x2029;
149 static int hex_to_int(WCHAR c
)
151 if('0' <= c
&& c
<= '9')
154 if('a' <= c
&& c
<= 'f')
157 if('A' <= c
&& c
<= 'F')
163 static int check_keywords(parser_ctx_t
*ctx
, const WCHAR
**lval
)
165 int min
= 0, max
= sizeof(keywords
)/sizeof(keywords
[0])-1, r
, i
;
170 r
= check_keyword(ctx
, keywords
[i
].word
, lval
);
172 ctx
->implicit_nl_semicolon
= keywords
[i
].no_nl
;
173 return keywords
[i
].token
;
185 static BOOL
skip_html_comment(parser_ctx_t
*ctx
)
187 const WCHAR html_commentW
[] = {'<','!','-','-',0};
189 if(!ctx
->is_html
|| ctx
->ptr
+3 >= ctx
->end
||
190 memcmp(ctx
->ptr
, html_commentW
, sizeof(WCHAR
)*4))
194 while(ctx
->ptr
< ctx
->end
&& !is_endline(*ctx
->ptr
++));
199 static BOOL
skip_comment(parser_ctx_t
*ctx
)
201 if(ctx
->ptr
+1 >= ctx
->end
)
204 if(*ctx
->ptr
!= '/') {
205 if(*ctx
->ptr
== '@' && ctx
->ptr
+2 < ctx
->end
&& ctx
->ptr
[1] == '*' && ctx
->ptr
[2] == '/') {
213 switch(ctx
->ptr
[1]) {
216 if(ctx
->ptr
+2 < ctx
->end
&& *ctx
->ptr
== '@' && is_identifier_char(ctx
->ptr
[1]))
218 while(ctx
->ptr
+1 < ctx
->end
&& (ctx
->ptr
[0] != '*' || ctx
->ptr
[1] != '/'))
221 if(ctx
->ptr
[0] == '*' && ctx
->ptr
[1] == '/') {
224 WARN("unexpected end of file (missing end of comment)\n");
230 if(ctx
->ptr
+2 < ctx
->end
&& *ctx
->ptr
== '@' && is_identifier_char(ctx
->ptr
[1]))
232 while(ctx
->ptr
< ctx
->end
&& !is_endline(*ctx
->ptr
))
242 static BOOL
skip_spaces(parser_ctx_t
*ctx
)
244 while(ctx
->ptr
< ctx
->end
&& (isspaceW(*ctx
->ptr
) || *ctx
->ptr
== 0xFEFF /* UTF16 BOM */)) {
245 if(is_endline(*ctx
->ptr
++))
249 return ctx
->ptr
!= ctx
->end
;
252 BOOL
unescape(WCHAR
*str
)
288 i
= hex_to_int(*++p
);
293 i
= hex_to_int(*++p
);
299 i
= hex_to_int(*++p
);
304 i
= hex_to_int(*++p
);
309 i
= hex_to_int(*++p
);
314 i
= hex_to_int(*++p
);
323 c
= c
*8 + (*p
++ - '0');
325 c
= c
*8 + (*p
++ - '0');
341 static int parse_identifier(parser_ctx_t
*ctx
, const WCHAR
**ret
)
343 const WCHAR
*ptr
= ctx
->ptr
++;
347 while(ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
))
352 *ret
= wstr
= parser_alloc(ctx
, (len
+1)*sizeof(WCHAR
));
353 memcpy(wstr
, ptr
, len
*sizeof(WCHAR
));
356 /* FIXME: unescape */
360 static int parse_string_literal(parser_ctx_t
*ctx
, const WCHAR
**ret
, WCHAR endch
)
362 const WCHAR
*ptr
= ++ctx
->ptr
;
366 while(ctx
->ptr
< ctx
->end
&& *ctx
->ptr
!= endch
) {
367 if(*ctx
->ptr
++ == '\\')
371 if(ctx
->ptr
== ctx
->end
)
372 return lex_error(ctx
, JS_E_UNTERMINATED_STRING
);
376 *ret
= wstr
= parser_alloc(ctx
, (len
+1)*sizeof(WCHAR
));
377 memcpy(wstr
, ptr
, len
*sizeof(WCHAR
));
382 if(!unescape(wstr
)) {
383 WARN("unescape failed\n");
384 return lex_error(ctx
, E_FAIL
);
387 return tStringLiteral
;
390 static literal_t
*new_double_literal(parser_ctx_t
*ctx
, DOUBLE d
)
392 literal_t
*ret
= parser_alloc(ctx
, sizeof(literal_t
));
394 ret
->type
= LT_DOUBLE
;
399 literal_t
*new_boolean_literal(parser_ctx_t
*ctx
, BOOL bval
)
401 literal_t
*ret
= parser_alloc(ctx
, sizeof(literal_t
));
409 HRESULT
parse_decimal(const WCHAR
**iter
, const WCHAR
*end
, double *ret
)
411 const WCHAR
*ptr
= *iter
;
415 while(ptr
< end
&& isdigitW(*ptr
)) {
416 hlp
= d
*10 + *(ptr
++) - '0';
417 if(d
>MAXLONGLONG
/10 || hlp
<0) {
424 while(ptr
< end
&& isdigitW(*ptr
)) {
432 while(ptr
< end
&& isdigitW(*ptr
)) {
433 hlp
= d
*10 + *(ptr
++) - '0';
434 if(d
>MAXLONGLONG
/10 || hlp
<0)
440 while(ptr
< end
&& isdigitW(*ptr
))
444 if(ptr
< end
&& (*ptr
== 'e' || *ptr
== 'E')) {
450 }else if(*ptr
== '-') {
453 }else if(!isdigitW(*ptr
)) {
454 WARN("Expected exponent part\n");
460 WARN("unexpected end of file\n");
464 while(ptr
< end
&& isdigitW(*ptr
)) {
465 if(e
> INT_MAX
/10 || (e
= e
*10 + *ptr
++ - '0')<0)
470 if(exp
<0 && e
<0 && e
+exp
>0) exp
= INT_MIN
;
471 else if(exp
>0 && e
>0 && e
+exp
<0) exp
= INT_MAX
;
475 if(is_identifier_char(*ptr
)) {
476 WARN("wrong char after zero\n");
477 return JS_E_MISSING_SEMICOLON
;
480 *ret
= exp
>=0 ? d
*pow(10, exp
) : d
/pow(10, -exp
);
485 static BOOL
parse_numeric_literal(parser_ctx_t
*ctx
, double *ret
)
489 if(*ctx
->ptr
== '0') {
494 if(*ctx
->ptr
== 'x' || *ctx
->ptr
== 'X') {
495 if(++ctx
->ptr
== ctx
->end
) {
496 ERR("unexpected end of file\n");
500 while(ctx
->ptr
< ctx
->end
&& (d
= hex_to_int(*ctx
->ptr
)) != -1) {
505 if(ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
)) {
506 WARN("unexpected identifier char\n");
507 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
515 if(isdigitW(*ctx
->ptr
)) {
520 for(ptr
= ctx
->ptr
; ptr
< ctx
->end
&& isdigitW(*ptr
); ptr
++) {
528 val
= val
*base
+ *ctx
->ptr
-'0';
529 }while(++ctx
->ptr
< ctx
->end
&& isdigitW(*ctx
->ptr
));
531 /* FIXME: Do we need it here? */
532 if(ctx
->ptr
< ctx
->end
&& (is_identifier_char(*ctx
->ptr
) || *ctx
->ptr
== '.')) {
533 WARN("wrong char after octal literal: '%c'\n", *ctx
->ptr
);
534 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
542 if(is_identifier_char(*ctx
->ptr
)) {
543 WARN("wrong char after zero\n");
544 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
549 hres
= parse_decimal(&ctx
->ptr
, ctx
->end
, ret
);
551 lex_error(ctx
, hres
);
558 static int next_token(parser_ctx_t
*ctx
, void *lval
)
561 if(!skip_spaces(ctx
))
563 }while(skip_comment(ctx
) || skip_html_comment(ctx
));
565 if(ctx
->implicit_nl_semicolon
) {
568 ctx
->implicit_nl_semicolon
= FALSE
;
571 if(isalphaW(*ctx
->ptr
)) {
572 int ret
= check_keywords(ctx
, lval
);
576 return parse_identifier(ctx
, lval
);
579 if(isdigitW(*ctx
->ptr
)) {
582 if(!parse_numeric_literal(ctx
, &n
))
585 *(literal_t
**)lval
= new_double_literal(ctx
, n
);
586 return tNumericLiteral
;
602 *(const WCHAR
**)lval
= ctx
->ptr
++;
606 if(++ctx
->ptr
< ctx
->end
&& isdigitW(*ctx
->ptr
)) {
609 hres
= parse_decimal(&ctx
->ptr
, ctx
->end
, &n
);
611 lex_error(ctx
, hres
);
614 *(literal_t
**)lval
= new_double_literal(ctx
, n
);
615 return tNumericLiteral
;
620 if(++ctx
->ptr
== ctx
->end
) {
621 *(int*)lval
= EXPR_LESS
;
628 *(int*)lval
= EXPR_LESSEQ
;
631 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* <<= */
633 *(int*)lval
= EXPR_ASSIGNLSHIFT
;
636 *(int*)lval
= EXPR_LSHIFT
;
639 *(int*)lval
= EXPR_LESS
;
644 if(++ctx
->ptr
== ctx
->end
) { /* > */
645 *(int*)lval
= EXPR_GREATER
;
652 *(int*)lval
= EXPR_GREATEREQ
;
655 if(++ctx
->ptr
< ctx
->end
) {
656 if(*ctx
->ptr
== '=') { /* >>= */
658 *(int*)lval
= EXPR_ASSIGNRSHIFT
;
661 if(*ctx
->ptr
== '>') { /* >>> */
662 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* >>>= */
664 *(int*)lval
= EXPR_ASSIGNRRSHIFT
;
667 *(int*)lval
= EXPR_RRSHIFT
;
671 *(int*)lval
= EXPR_RSHIFT
;
674 *(int*)lval
= EXPR_GREATER
;
680 if(ctx
->ptr
< ctx
->end
) {
687 *(int*)lval
= EXPR_ASSIGNADD
;
695 if(ctx
->ptr
< ctx
->end
) {
697 case '-': /* -- or --> */
699 if(ctx
->is_html
&& ctx
->nl
&& ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '>') {
706 *(int*)lval
= EXPR_ASSIGNSUB
;
713 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* *= */
715 *(int*)lval
= EXPR_ASSIGNMUL
;
721 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* %= */
723 *(int*)lval
= EXPR_ASSIGNMOD
;
729 if(++ctx
->ptr
< ctx
->end
) {
733 *(int*)lval
= EXPR_ASSIGNAND
;
743 if(++ctx
->ptr
< ctx
->end
) {
747 *(int*)lval
= EXPR_ASSIGNOR
;
757 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* ^= */
759 *(int*)lval
= EXPR_ASSIGNXOR
;
765 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* != */
766 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* !== */
768 *(int*)lval
= EXPR_NOTEQEQ
;
771 *(int*)lval
= EXPR_NOTEQ
;
777 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* == */
778 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* === */
780 *(int*)lval
= EXPR_EQEQ
;
783 *(int*)lval
= EXPR_EQ
;
789 if(++ctx
->ptr
< ctx
->end
) {
790 if(*ctx
->ptr
== '=') { /* /= */
792 *(int*)lval
= EXPR_ASSIGNDIV
;
799 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== ':') {
807 return parse_string_literal(ctx
, lval
, *ctx
->ptr
);
811 return parse_identifier(ctx
, lval
);
817 WARN("unexpected char '%c' %d\n", *ctx
->ptr
, *ctx
->ptr
);
823 struct _cc_var_t
*next
;
828 void release_cc(cc_ctx_t
*cc
)
830 cc_var_t
*iter
, *next
;
832 for(iter
= cc
->vars
; iter
; iter
= next
) {
840 static BOOL
new_cc_var(cc_ctx_t
*cc
, const WCHAR
*name
, int len
, ccval_t v
)
847 new_v
= heap_alloc(sizeof(cc_var_t
) + (len
+1)*sizeof(WCHAR
));
852 memcpy(new_v
->name
, name
, (len
+1)*sizeof(WCHAR
));
853 new_v
->name_len
= len
;
854 new_v
->next
= cc
->vars
;
859 static cc_var_t
*find_cc_var(cc_ctx_t
*cc
, const WCHAR
*name
, unsigned name_len
)
863 for(iter
= cc
->vars
; iter
; iter
= iter
->next
) {
864 if(iter
->name_len
== name_len
&& !memcmp(iter
->name
, name
, name_len
*sizeof(WCHAR
)))
871 static BOOL
init_cc(parser_ctx_t
*ctx
)
875 static const WCHAR _win32W
[] = {'_','w','i','n','3','2',0};
876 static const WCHAR _win64W
[] = {'_','w','i','n','6','4',0};
877 static const WCHAR _x86W
[] = {'_','x','8','6',0};
878 static const WCHAR _amd64W
[] = {'_','a','m','d','6','4',0};
879 static const WCHAR _jscriptW
[] = {'_','j','s','c','r','i','p','t',0};
880 static const WCHAR _jscript_buildW
[] = {'_','j','s','c','r','i','p','t','_','b','u','i','l','d',0};
881 static const WCHAR _jscript_versionW
[] = {'_','j','s','c','r','i','p','t','_','v','e','r','s','i','o','n',0};
886 cc
= heap_alloc(sizeof(cc_ctx_t
));
888 lex_error(ctx
, E_OUTOFMEMORY
);
894 if(!new_cc_var(cc
, _jscriptW
, -1, ccval_bool(TRUE
))
895 || !new_cc_var(cc
, sizeof(void*) == 8 ? _win64W
: _win32W
, -1, ccval_bool(TRUE
))
896 || !new_cc_var(cc
, sizeof(void*) == 8 ? _amd64W
: _x86W
, -1, ccval_bool(TRUE
))
897 || !new_cc_var(cc
, _jscript_versionW
, -1, ccval_num(JSCRIPT_MAJOR_VERSION
+ (DOUBLE
)JSCRIPT_MINOR_VERSION
/10.0))
898 || !new_cc_var(cc
, _jscript_buildW
, -1, ccval_num(JSCRIPT_BUILD_VERSION
))) {
900 lex_error(ctx
, E_OUTOFMEMORY
);
904 ctx
->script
->cc
= cc
;
908 static BOOL
parse_cc_identifier(parser_ctx_t
*ctx
, const WCHAR
**ret
, unsigned *ret_len
)
910 if(*ctx
->ptr
!= '@') {
911 lex_error(ctx
, JS_E_EXPECTED_AT
);
915 if(!is_identifier_first_char(*++ctx
->ptr
)) {
916 lex_error(ctx
, JS_E_EXPECTED_IDENTIFIER
);
921 while(++ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
));
922 *ret_len
= ctx
->ptr
- *ret
;
926 int try_parse_ccval(parser_ctx_t
*ctx
, ccval_t
*r
)
928 if(!skip_spaces(ctx
))
931 if(isdigitW(*ctx
->ptr
)) {
934 if(!parse_numeric_literal(ctx
, &n
))
941 if(*ctx
->ptr
== '@') {
946 if(!parse_cc_identifier(ctx
, &ident
, &ident_len
))
949 cc_var
= find_cc_var(ctx
->script
->cc
, ident
, ident_len
);
950 *r
= cc_var
? cc_var
->val
: ccval_num(NAN
);
954 if(!check_keyword(ctx
, trueW
, NULL
)) {
955 *r
= ccval_bool(TRUE
);
959 if(!check_keyword(ctx
, falseW
, NULL
)) {
960 *r
= ccval_bool(FALSE
);
967 static int skip_code(parser_ctx_t
*ctx
, BOOL exec_else
)
973 ptr
= strchrW(ctx
->ptr
, '@');
976 return lex_error(ctx
, JS_E_EXPECTED_CCEND
);
980 if(!check_keyword(ctx
, endW
, NULL
)) {
986 if(exec_else
&& !check_keyword(ctx
, elifW
, NULL
)) {
990 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '(')
991 return lex_error(ctx
, JS_E_MISSING_LBRACKET
);
993 if(!parse_cc_expr(ctx
))
996 if(!get_ccbool(ctx
->ccval
))
997 continue; /* skip block of code */
999 /* continue parsing */
1004 if(exec_else
&& !check_keyword(ctx
, elseW
, NULL
)) {
1008 /* parse else block */
1013 if(!check_keyword(ctx
, ifW
, NULL
)) {
1022 static int cc_token(parser_ctx_t
*ctx
, void *lval
)
1024 unsigned id_len
= 0;
1027 static const WCHAR cc_onW
[] = {'c','c','_','o','n',0};
1028 static const WCHAR setW
[] = {'s','e','t',0};
1032 if(!check_keyword(ctx
, cc_onW
, NULL
))
1033 return init_cc(ctx
) ? 0 : -1;
1035 if(!check_keyword(ctx
, setW
, NULL
)) {
1043 if(!skip_spaces(ctx
))
1044 return lex_error(ctx
, JS_E_EXPECTED_AT
);
1046 if(!parse_cc_identifier(ctx
, &ident
, &ident_len
))
1049 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '=')
1050 return lex_error(ctx
, JS_E_EXPECTED_ASSIGN
);
1053 if(!parse_cc_expr(ctx
)) {
1054 WARN("parsing CC expression failed\n");
1058 var
= find_cc_var(ctx
->script
->cc
, ident
, ident_len
);
1060 var
->val
= ctx
->ccval
;
1062 if(!new_cc_var(ctx
->script
->cc
, ident
, ident_len
, ctx
->ccval
))
1063 return lex_error(ctx
, E_OUTOFMEMORY
);
1069 if(!check_keyword(ctx
, ifW
, NULL
)) {
1073 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '(')
1074 return lex_error(ctx
, JS_E_MISSING_LBRACKET
);
1076 if(!parse_cc_expr(ctx
))
1079 if(get_ccbool(ctx
->ccval
)) {
1080 /* continue parsing block inside if */
1085 return skip_code(ctx
, TRUE
);
1088 if(!check_keyword(ctx
, elifW
, NULL
) || !check_keyword(ctx
, elseW
, NULL
)) {
1089 if(!ctx
->cc_if_depth
)
1090 return lex_error(ctx
, JS_E_SYNTAX
);
1092 return skip_code(ctx
, FALSE
);
1095 if(!check_keyword(ctx
, endW
, NULL
)) {
1096 if(!ctx
->cc_if_depth
)
1097 return lex_error(ctx
, JS_E_SYNTAX
);
1103 if(!ctx
->script
->cc
)
1104 return lex_error(ctx
, JS_E_DISABLED_CC
);
1106 while(ctx
->ptr
+id_len
< ctx
->end
&& is_identifier_char(ctx
->ptr
[id_len
]))
1111 TRACE("var %s\n", debugstr_wn(ctx
->ptr
, id_len
));
1113 var
= find_cc_var(ctx
->script
->cc
, ctx
->ptr
, id_len
);
1115 if(!var
|| var
->val
.is_num
) {
1116 *(literal_t
**)lval
= new_double_literal(ctx
, var
? var
->val
.u
.n
: NAN
);
1117 return tNumericLiteral
;
1120 *(literal_t
**)lval
= new_boolean_literal(ctx
, var
->val
.u
.b
);
1121 return tBooleanLiteral
;
1124 int parser_lex(void *lval
, parser_ctx_t
*ctx
)
1128 ctx
->nl
= ctx
->ptr
== ctx
->begin
;
1131 ret
= next_token(ctx
, lval
);
1132 } while(ret
== '@' && !(ret
= cc_token(ctx
, lval
)));
1137 literal_t
*parse_regexp(parser_ctx_t
*ctx
)
1139 const WCHAR
*re
, *flags_ptr
;
1140 BOOL in_class
= FALSE
;
1141 DWORD re_len
, flags
;
1147 while(*--ctx
->ptr
!= '/');
1149 /* Simple regexp pre-parser; '/' if used in char class does not terminate regexp literal */
1151 while(ctx
->ptr
< ctx
->end
) {
1152 if(*ctx
->ptr
== '\\') {
1153 if(++ctx
->ptr
== ctx
->end
)
1155 }else if(in_class
) {
1156 if(*ctx
->ptr
== '\n')
1158 if(*ctx
->ptr
== ']')
1161 if(*ctx
->ptr
== '/')
1164 if(*ctx
->ptr
== '[')
1170 if(ctx
->ptr
== ctx
->end
|| *ctx
->ptr
!= '/') {
1171 WARN("pre-parsing failed\n");
1175 re_len
= ctx
->ptr
-re
;
1177 flags_ptr
= ++ctx
->ptr
;
1178 while(ctx
->ptr
< ctx
->end
&& isalnumW(*ctx
->ptr
))
1181 hres
= parse_regexp_flags(flags_ptr
, ctx
->ptr
-flags_ptr
, &flags
);
1185 ret
= parser_alloc(ctx
, sizeof(literal_t
));
1186 ret
->type
= LT_REGEXP
;
1187 ret
->u
.regexp
.str
= re
;
1188 ret
->u
.regexp
.str_len
= re_len
;
1189 ret
->u
.regexp
.flags
= flags
;