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"
36 /* FIXME: Inspect - For some reason these exist in the generated header but are not picked up */
41 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
43 static const WCHAR breakW
[] = {'b','r','e','a','k',0};
44 static const WCHAR caseW
[] = {'c','a','s','e',0};
45 static const WCHAR catchW
[] = {'c','a','t','c','h',0};
46 static const WCHAR continueW
[] = {'c','o','n','t','i','n','u','e',0};
47 static const WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0};
48 static const WCHAR deleteW
[] = {'d','e','l','e','t','e',0};
49 static const WCHAR doW
[] = {'d','o',0};
50 static const WCHAR elseW
[] = {'e','l','s','e',0};
51 static const WCHAR falseW
[] = {'f','a','l','s','e',0};
52 static const WCHAR finallyW
[] = {'f','i','n','a','l','l','y',0};
53 static const WCHAR forW
[] = {'f','o','r',0};
54 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
55 static const WCHAR getW
[] = {'g','e','t',0};
56 static const WCHAR ifW
[] = {'i','f',0};
57 static const WCHAR inW
[] = {'i','n',0};
58 static const WCHAR instanceofW
[] = {'i','n','s','t','a','n','c','e','o','f',0};
59 static const WCHAR newW
[] = {'n','e','w',0};
60 static const WCHAR nullW
[] = {'n','u','l','l',0};
61 static const WCHAR returnW
[] = {'r','e','t','u','r','n',0};
62 static const WCHAR setW
[] = {'s','e','t',0};
63 static const WCHAR switchW
[] = {'s','w','i','t','c','h',0};
64 static const WCHAR thisW
[] = {'t','h','i','s',0};
65 static const WCHAR throwW
[] = {'t','h','r','o','w',0};
66 static const WCHAR trueW
[] = {'t','r','u','e',0};
67 static const WCHAR tryW
[] = {'t','r','y',0};
68 static const WCHAR typeofW
[] = {'t','y','p','e','o','f',0};
69 static const WCHAR varW
[] = {'v','a','r',0};
70 static const WCHAR voidW
[] = {'v','o','i','d',0};
71 static const WCHAR whileW
[] = {'w','h','i','l','e',0};
72 static const WCHAR withW
[] = {'w','i','t','h',0};
74 static const WCHAR elifW
[] = {'e','l','i','f',0};
75 static const WCHAR endW
[] = {'e','n','d',0};
83 {breakW
, kBREAK
, TRUE
},
86 {continueW
, kCONTINUE
, TRUE
},
94 {functionW
, kFUNCTION
},
95 {getW
, kGET
, FALSE
, SCRIPTLANGUAGEVERSION_ES5
},
98 {instanceofW
, kINSTANCEOF
},
101 {returnW
, kRETURN
, TRUE
},
102 {setW
, kSET
, FALSE
, SCRIPTLANGUAGEVERSION_ES5
},
115 static int lex_error(parser_ctx_t
*ctx
, HRESULT hres
)
118 ctx
->lexer_error
= TRUE
;
122 /* ECMA-262 3rd Edition 7.6 */
123 BOOL
is_identifier_char(WCHAR c
)
125 return isalnumW(c
) || c
== '$' || c
== '_' || c
== '\\';
128 static BOOL
is_identifier_first_char(WCHAR c
)
130 return isalphaW(c
) || c
== '$' || c
== '_' || c
== '\\';
133 static int check_keyword(parser_ctx_t
*ctx
, const WCHAR
*word
, const WCHAR
**lval
)
135 const WCHAR
*p1
= ctx
->ptr
;
136 const WCHAR
*p2
= word
;
138 while(p1
< ctx
->end
&& *p2
) {
145 if(*p2
|| (p1
< ctx
->end
&& is_identifier_char(*p1
)))
154 /* ECMA-262 3rd Edition 7.3 */
155 static BOOL
is_endline(WCHAR c
)
157 return c
== '\n' || c
== '\r' || c
== 0x2028 || c
== 0x2029;
160 static int hex_to_int(WCHAR c
)
162 if('0' <= c
&& c
<= '9')
165 if('a' <= c
&& c
<= 'f')
168 if('A' <= c
&& c
<= 'F')
174 static int check_keywords(parser_ctx_t
*ctx
, const WCHAR
**lval
)
176 int min
= 0, max
= ARRAY_SIZE(keywords
)-1, r
, i
;
181 r
= check_keyword(ctx
, keywords
[i
].word
, lval
);
183 if(ctx
->script
->version
< keywords
[i
].min_version
) {
184 TRACE("ignoring keyword %s in incompatible mode\n",
185 debugstr_w(keywords
[i
].word
));
186 ctx
->ptr
-= strlenW(keywords
[i
].word
);
189 ctx
->implicit_nl_semicolon
= keywords
[i
].no_nl
;
190 return keywords
[i
].token
;
202 static BOOL
skip_html_comment(parser_ctx_t
*ctx
)
204 const WCHAR html_commentW
[] = {'<','!','-','-',0};
206 if(!ctx
->is_html
|| ctx
->ptr
+3 >= ctx
->end
||
207 memcmp(ctx
->ptr
, html_commentW
, sizeof(WCHAR
)*4))
211 while(ctx
->ptr
< ctx
->end
&& !is_endline(*ctx
->ptr
++));
216 static BOOL
skip_comment(parser_ctx_t
*ctx
)
218 if(ctx
->ptr
+1 >= ctx
->end
)
221 if(*ctx
->ptr
!= '/') {
222 if(*ctx
->ptr
== '@' && ctx
->ptr
+2 < ctx
->end
&& ctx
->ptr
[1] == '*' && ctx
->ptr
[2] == '/') {
230 switch(ctx
->ptr
[1]) {
233 if(ctx
->ptr
+2 < ctx
->end
&& *ctx
->ptr
== '@' && is_identifier_char(ctx
->ptr
[1]))
235 while(ctx
->ptr
+1 < ctx
->end
&& (ctx
->ptr
[0] != '*' || ctx
->ptr
[1] != '/'))
238 if(ctx
->ptr
[0] == '*' && ctx
->ptr
[1] == '/') {
241 WARN("unexpected end of file (missing end of comment)\n");
247 if(ctx
->ptr
+2 < ctx
->end
&& *ctx
->ptr
== '@' && is_identifier_char(ctx
->ptr
[1]))
249 while(ctx
->ptr
< ctx
->end
&& !is_endline(*ctx
->ptr
))
259 static BOOL
skip_spaces(parser_ctx_t
*ctx
)
261 while(ctx
->ptr
< ctx
->end
&& (isspaceW(*ctx
->ptr
) || *ctx
->ptr
== 0xFEFF /* UTF16 BOM */)) {
262 if(is_endline(*ctx
->ptr
++))
266 return ctx
->ptr
!= ctx
->end
;
269 BOOL
unescape(WCHAR
*str
)
305 i
= hex_to_int(*++p
);
310 i
= hex_to_int(*++p
);
316 i
= hex_to_int(*++p
);
321 i
= hex_to_int(*++p
);
326 i
= hex_to_int(*++p
);
331 i
= hex_to_int(*++p
);
340 c
= c
*8 + (*p
++ - '0');
342 c
= c
*8 + (*p
++ - '0');
358 static int parse_identifier(parser_ctx_t
*ctx
, const WCHAR
**ret
)
360 const WCHAR
*ptr
= ctx
->ptr
++;
364 while(ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
))
369 *ret
= wstr
= parser_alloc(ctx
, (len
+1)*sizeof(WCHAR
));
370 memcpy(wstr
, ptr
, len
*sizeof(WCHAR
));
373 /* FIXME: unescape */
377 static int parse_string_literal(parser_ctx_t
*ctx
, const WCHAR
**ret
, WCHAR endch
)
379 const WCHAR
*ptr
= ++ctx
->ptr
;
383 while(ctx
->ptr
< ctx
->end
&& *ctx
->ptr
!= endch
) {
384 if(*ctx
->ptr
++ == '\\')
388 if(ctx
->ptr
== ctx
->end
)
389 return lex_error(ctx
, JS_E_UNTERMINATED_STRING
);
393 *ret
= wstr
= parser_alloc(ctx
, (len
+1)*sizeof(WCHAR
));
394 memcpy(wstr
, ptr
, len
*sizeof(WCHAR
));
399 if(!unescape(wstr
)) {
400 WARN("unescape failed\n");
401 return lex_error(ctx
, E_FAIL
);
404 return tStringLiteral
;
407 static literal_t
*new_double_literal(parser_ctx_t
*ctx
, DOUBLE d
)
409 literal_t
*ret
= parser_alloc(ctx
, sizeof(literal_t
));
411 ret
->type
= LT_DOUBLE
;
416 literal_t
*new_boolean_literal(parser_ctx_t
*ctx
, BOOL bval
)
418 literal_t
*ret
= parser_alloc(ctx
, sizeof(literal_t
));
426 HRESULT
parse_decimal(const WCHAR
**iter
, const WCHAR
*end
, double *ret
)
428 const WCHAR
*ptr
= *iter
;
432 while(ptr
< end
&& isdigitW(*ptr
)) {
433 hlp
= d
*10 + *(ptr
++) - '0';
434 if(d
>MAXLONGLONG
/10 || hlp
<0) {
441 while(ptr
< end
&& isdigitW(*ptr
)) {
449 while(ptr
< end
&& isdigitW(*ptr
)) {
450 hlp
= d
*10 + *(ptr
++) - '0';
451 if(d
>MAXLONGLONG
/10 || hlp
<0)
457 while(ptr
< end
&& isdigitW(*ptr
))
461 if(ptr
< end
&& (*ptr
== 'e' || *ptr
== 'E')) {
467 }else if(*ptr
== '-') {
470 }else if(!isdigitW(*ptr
)) {
471 WARN("Expected exponent part\n");
477 WARN("unexpected end of file\n");
481 while(ptr
< end
&& isdigitW(*ptr
)) {
482 if(e
> INT_MAX
/10 || (e
= e
*10 + *ptr
++ - '0')<0)
487 if(exp
<0 && e
<0 && e
+exp
>0) exp
= INT_MIN
;
488 else if(exp
>0 && e
>0 && e
+exp
<0) exp
= INT_MAX
;
492 if(is_identifier_char(*ptr
)) {
493 WARN("wrong char after zero\n");
494 return JS_E_MISSING_SEMICOLON
;
497 *ret
= exp
>=0 ? d
*pow(10, exp
) : d
/pow(10, -exp
);
502 static BOOL
parse_numeric_literal(parser_ctx_t
*ctx
, double *ret
)
506 if(*ctx
->ptr
== '0') {
509 if(*ctx
->ptr
== 'x' || *ctx
->ptr
== 'X') {
512 if(++ctx
->ptr
== ctx
->end
) {
513 ERR("unexpected end of file\n");
517 while(ctx
->ptr
< ctx
->end
&& (d
= hex_to_int(*ctx
->ptr
)) != -1) {
522 if(ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
)) {
523 WARN("unexpected identifier char\n");
524 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
532 if(isdigitW(*ctx
->ptr
)) {
537 for(ptr
= ctx
->ptr
; ptr
< ctx
->end
&& isdigitW(*ptr
); ptr
++) {
545 val
= val
*base
+ *ctx
->ptr
-'0';
546 }while(++ctx
->ptr
< ctx
->end
&& isdigitW(*ctx
->ptr
));
548 /* FIXME: Do we need it here? */
549 if(ctx
->ptr
< ctx
->end
&& (is_identifier_char(*ctx
->ptr
) || *ctx
->ptr
== '.')) {
550 WARN("wrong char after octal literal: '%c'\n", *ctx
->ptr
);
551 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
559 if(is_identifier_char(*ctx
->ptr
)) {
560 WARN("wrong char after zero\n");
561 lex_error(ctx
, JS_E_MISSING_SEMICOLON
);
566 hres
= parse_decimal(&ctx
->ptr
, ctx
->end
, ret
);
568 lex_error(ctx
, hres
);
575 static int next_token(parser_ctx_t
*ctx
, void *lval
)
578 if(!skip_spaces(ctx
))
580 }while(skip_comment(ctx
) || skip_html_comment(ctx
));
582 if(ctx
->implicit_nl_semicolon
) {
585 ctx
->implicit_nl_semicolon
= FALSE
;
588 if(isalphaW(*ctx
->ptr
)) {
589 int ret
= check_keywords(ctx
, lval
);
593 return parse_identifier(ctx
, lval
);
596 if(isdigitW(*ctx
->ptr
)) {
599 if(!parse_numeric_literal(ctx
, &n
))
602 *(literal_t
**)lval
= new_double_literal(ctx
, n
);
603 return tNumericLiteral
;
619 *(const WCHAR
**)lval
= ctx
->ptr
++;
623 if(ctx
->ptr
+1 < ctx
->end
&& isdigitW(ctx
->ptr
[1])) {
626 hres
= parse_decimal(&ctx
->ptr
, ctx
->end
, &n
);
628 lex_error(ctx
, hres
);
631 *(literal_t
**)lval
= new_double_literal(ctx
, n
);
632 return tNumericLiteral
;
638 if(++ctx
->ptr
== ctx
->end
) {
639 *(int*)lval
= EXPR_LESS
;
646 *(int*)lval
= EXPR_LESSEQ
;
649 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* <<= */
651 *(int*)lval
= EXPR_ASSIGNLSHIFT
;
654 *(int*)lval
= EXPR_LSHIFT
;
657 *(int*)lval
= EXPR_LESS
;
662 if(++ctx
->ptr
== ctx
->end
) { /* > */
663 *(int*)lval
= EXPR_GREATER
;
670 *(int*)lval
= EXPR_GREATEREQ
;
673 if(++ctx
->ptr
< ctx
->end
) {
674 if(*ctx
->ptr
== '=') { /* >>= */
676 *(int*)lval
= EXPR_ASSIGNRSHIFT
;
679 if(*ctx
->ptr
== '>') { /* >>> */
680 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* >>>= */
682 *(int*)lval
= EXPR_ASSIGNRRSHIFT
;
685 *(int*)lval
= EXPR_RRSHIFT
;
689 *(int*)lval
= EXPR_RSHIFT
;
692 *(int*)lval
= EXPR_GREATER
;
698 if(ctx
->ptr
< ctx
->end
) {
705 *(int*)lval
= EXPR_ASSIGNADD
;
713 if(ctx
->ptr
< ctx
->end
) {
715 case '-': /* -- or --> */
717 if(ctx
->is_html
&& ctx
->nl
&& ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '>') {
724 *(int*)lval
= EXPR_ASSIGNSUB
;
731 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* *= */
733 *(int*)lval
= EXPR_ASSIGNMUL
;
739 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* %= */
741 *(int*)lval
= EXPR_ASSIGNMOD
;
747 if(++ctx
->ptr
< ctx
->end
) {
751 *(int*)lval
= EXPR_ASSIGNAND
;
761 if(++ctx
->ptr
< ctx
->end
) {
765 *(int*)lval
= EXPR_ASSIGNOR
;
775 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* ^= */
777 *(int*)lval
= EXPR_ASSIGNXOR
;
783 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* != */
784 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* !== */
786 *(int*)lval
= EXPR_NOTEQEQ
;
789 *(int*)lval
= EXPR_NOTEQ
;
795 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* == */
796 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== '=') { /* === */
798 *(int*)lval
= EXPR_EQEQ
;
801 *(int*)lval
= EXPR_EQ
;
807 if(++ctx
->ptr
< ctx
->end
) {
808 if(*ctx
->ptr
== '=') { /* /= */
810 *(int*)lval
= EXPR_ASSIGNDIV
;
817 if(++ctx
->ptr
< ctx
->end
&& *ctx
->ptr
== ':') {
825 return parse_string_literal(ctx
, lval
, *ctx
->ptr
);
829 return parse_identifier(ctx
, lval
);
835 WARN("unexpected char '%c' %d\n", *ctx
->ptr
, *ctx
->ptr
);
841 struct _cc_var_t
*next
;
846 void release_cc(cc_ctx_t
*cc
)
848 cc_var_t
*iter
, *next
;
850 for(iter
= cc
->vars
; iter
; iter
= next
) {
858 static BOOL
new_cc_var(cc_ctx_t
*cc
, const WCHAR
*name
, int len
, ccval_t v
)
865 new_v
= heap_alloc(sizeof(cc_var_t
) + (len
+1)*sizeof(WCHAR
));
870 memcpy(new_v
->name
, name
, (len
+1)*sizeof(WCHAR
));
871 new_v
->name_len
= len
;
872 new_v
->next
= cc
->vars
;
877 static cc_var_t
*find_cc_var(cc_ctx_t
*cc
, const WCHAR
*name
, unsigned name_len
)
881 for(iter
= cc
->vars
; iter
; iter
= iter
->next
) {
882 if(iter
->name_len
== name_len
&& !memcmp(iter
->name
, name
, name_len
*sizeof(WCHAR
)))
889 static BOOL
init_cc(parser_ctx_t
*ctx
)
893 static const WCHAR _win32W
[] = {'_','w','i','n','3','2',0};
894 static const WCHAR _win64W
[] = {'_','w','i','n','6','4',0};
895 static const WCHAR _x86W
[] = {'_','x','8','6',0};
896 static const WCHAR _amd64W
[] = {'_','a','m','d','6','4',0};
897 static const WCHAR _jscriptW
[] = {'_','j','s','c','r','i','p','t',0};
898 static const WCHAR _jscript_buildW
[] = {'_','j','s','c','r','i','p','t','_','b','u','i','l','d',0};
899 static const WCHAR _jscript_versionW
[] = {'_','j','s','c','r','i','p','t','_','v','e','r','s','i','o','n',0};
904 cc
= heap_alloc(sizeof(cc_ctx_t
));
906 lex_error(ctx
, E_OUTOFMEMORY
);
912 if(!new_cc_var(cc
, _jscriptW
, -1, ccval_bool(TRUE
))
913 || !new_cc_var(cc
, sizeof(void*) == 8 ? _win64W
: _win32W
, -1, ccval_bool(TRUE
))
914 || !new_cc_var(cc
, sizeof(void*) == 8 ? _amd64W
: _x86W
, -1, ccval_bool(TRUE
))
915 || !new_cc_var(cc
, _jscript_versionW
, -1, ccval_num(JSCRIPT_MAJOR_VERSION
+ (DOUBLE
)JSCRIPT_MINOR_VERSION
/10.0))
916 || !new_cc_var(cc
, _jscript_buildW
, -1, ccval_num(JSCRIPT_BUILD_VERSION
))) {
918 lex_error(ctx
, E_OUTOFMEMORY
);
922 ctx
->script
->cc
= cc
;
926 static BOOL
parse_cc_identifier(parser_ctx_t
*ctx
, const WCHAR
**ret
, unsigned *ret_len
)
928 if(*ctx
->ptr
!= '@') {
929 lex_error(ctx
, JS_E_EXPECTED_AT
);
933 if(!is_identifier_first_char(*++ctx
->ptr
)) {
934 lex_error(ctx
, JS_E_EXPECTED_IDENTIFIER
);
939 while(++ctx
->ptr
< ctx
->end
&& is_identifier_char(*ctx
->ptr
));
940 *ret_len
= ctx
->ptr
- *ret
;
944 int try_parse_ccval(parser_ctx_t
*ctx
, ccval_t
*r
)
946 if(!skip_spaces(ctx
))
949 if(isdigitW(*ctx
->ptr
)) {
952 if(!parse_numeric_literal(ctx
, &n
))
959 if(*ctx
->ptr
== '@') {
964 if(!parse_cc_identifier(ctx
, &ident
, &ident_len
))
967 cc_var
= find_cc_var(ctx
->script
->cc
, ident
, ident_len
);
968 *r
= cc_var
? cc_var
->val
: ccval_num(NAN
);
972 if(!check_keyword(ctx
, trueW
, NULL
)) {
973 *r
= ccval_bool(TRUE
);
977 if(!check_keyword(ctx
, falseW
, NULL
)) {
978 *r
= ccval_bool(FALSE
);
985 static int skip_code(parser_ctx_t
*ctx
, BOOL exec_else
)
991 ptr
= strchrW(ctx
->ptr
, '@');
994 return lex_error(ctx
, JS_E_EXPECTED_CCEND
);
998 if(!check_keyword(ctx
, endW
, NULL
)) {
1004 if(exec_else
&& !check_keyword(ctx
, elifW
, NULL
)) {
1008 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '(')
1009 return lex_error(ctx
, JS_E_MISSING_LBRACKET
);
1011 if(!parse_cc_expr(ctx
))
1014 if(!get_ccbool(ctx
->ccval
))
1015 continue; /* skip block of code */
1017 /* continue parsing */
1022 if(exec_else
&& !check_keyword(ctx
, elseW
, NULL
)) {
1026 /* parse else block */
1031 if(!check_keyword(ctx
, ifW
, NULL
)) {
1040 static int cc_token(parser_ctx_t
*ctx
, void *lval
)
1042 unsigned id_len
= 0;
1045 static const WCHAR cc_onW
[] = {'c','c','_','o','n',0};
1046 static const WCHAR setW
[] = {'s','e','t',0};
1050 if(!check_keyword(ctx
, cc_onW
, NULL
))
1051 return init_cc(ctx
) ? 0 : -1;
1053 if(!check_keyword(ctx
, setW
, NULL
)) {
1061 if(!skip_spaces(ctx
))
1062 return lex_error(ctx
, JS_E_EXPECTED_AT
);
1064 if(!parse_cc_identifier(ctx
, &ident
, &ident_len
))
1067 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '=')
1068 return lex_error(ctx
, JS_E_EXPECTED_ASSIGN
);
1071 if(!parse_cc_expr(ctx
)) {
1072 WARN("parsing CC expression failed\n");
1076 var
= find_cc_var(ctx
->script
->cc
, ident
, ident_len
);
1078 var
->val
= ctx
->ccval
;
1080 if(!new_cc_var(ctx
->script
->cc
, ident
, ident_len
, ctx
->ccval
))
1081 return lex_error(ctx
, E_OUTOFMEMORY
);
1087 if(!check_keyword(ctx
, ifW
, NULL
)) {
1091 if(!skip_spaces(ctx
) || *ctx
->ptr
!= '(')
1092 return lex_error(ctx
, JS_E_MISSING_LBRACKET
);
1094 if(!parse_cc_expr(ctx
))
1097 if(get_ccbool(ctx
->ccval
)) {
1098 /* continue parsing block inside if */
1103 return skip_code(ctx
, TRUE
);
1106 if(!check_keyword(ctx
, elifW
, NULL
) || !check_keyword(ctx
, elseW
, NULL
)) {
1107 if(!ctx
->cc_if_depth
)
1108 return lex_error(ctx
, JS_E_SYNTAX
);
1110 return skip_code(ctx
, FALSE
);
1113 if(!check_keyword(ctx
, endW
, NULL
)) {
1114 if(!ctx
->cc_if_depth
)
1115 return lex_error(ctx
, JS_E_SYNTAX
);
1121 if(!ctx
->script
->cc
)
1122 return lex_error(ctx
, JS_E_DISABLED_CC
);
1124 while(ctx
->ptr
+id_len
< ctx
->end
&& is_identifier_char(ctx
->ptr
[id_len
]))
1129 TRACE("var %s\n", debugstr_wn(ctx
->ptr
, id_len
));
1131 var
= find_cc_var(ctx
->script
->cc
, ctx
->ptr
, id_len
);
1133 if(!var
|| var
->val
.is_num
) {
1134 *(literal_t
**)lval
= new_double_literal(ctx
, var
? var
->val
.u
.n
: NAN
);
1135 return tNumericLiteral
;
1138 *(literal_t
**)lval
= new_boolean_literal(ctx
, var
->val
.u
.b
);
1139 return tBooleanLiteral
;
1142 int parser_lex(void *lval
, parser_ctx_t
*ctx
)
1146 ctx
->nl
= ctx
->ptr
== ctx
->begin
;
1149 ret
= next_token(ctx
, lval
);
1150 } while(ret
== '@' && !(ret
= cc_token(ctx
, lval
)));
1155 literal_t
*parse_regexp(parser_ctx_t
*ctx
)
1157 const WCHAR
*re
, *flags_ptr
;
1158 BOOL in_class
= FALSE
;
1159 DWORD re_len
, flags
;
1165 while(*--ctx
->ptr
!= '/');
1167 /* Simple regexp pre-parser; '/' if used in char class does not terminate regexp literal */
1169 while(ctx
->ptr
< ctx
->end
) {
1170 if(*ctx
->ptr
== '\\') {
1171 if(++ctx
->ptr
== ctx
->end
)
1173 }else if(in_class
) {
1174 if(*ctx
->ptr
== '\n')
1176 if(*ctx
->ptr
== ']')
1179 if(*ctx
->ptr
== '/')
1182 if(*ctx
->ptr
== '[')
1188 if(ctx
->ptr
== ctx
->end
|| *ctx
->ptr
!= '/') {
1189 WARN("pre-parsing failed\n");
1193 re_len
= ctx
->ptr
-re
;
1195 flags_ptr
= ++ctx
->ptr
;
1196 while(ctx
->ptr
< ctx
->end
&& isalnumW(*ctx
->ptr
))
1199 hres
= parse_regexp_flags(flags_ptr
, ctx
->ptr
-flags_ptr
, &flags
);
1203 ret
= parser_alloc(ctx
, sizeof(literal_t
));
1204 ret
->type
= LT_REGEXP
;
1205 ret
->u
.regexp
.str
= re
;
1206 ret
->u
.regexp
.str_len
= re_len
;
1207 ret
->u
.regexp
.flags
= flags
;