ref: b4fb12662da6de2f9853162572f4907b39943870
parent: 0ac4cce8b0cb0f052c871576b4fb394b414504a7
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Jan 2 08:39:56 EST 2015
Rename next/accept/expect macros in lexer and parser. Make the names regular, and don't conflict with libc function accept().
--- a/jslex.c
+++ b/jslex.c
@@ -149,11 +149,6 @@
return 0;
}
-#define PEEK (J->lexchar)
-#define NEXT() jsY_next(J)
-#define ACCEPT(x) (PEEK == x ? (NEXT(), 1) : 0)
-#define EXPECT(x) if (!ACCEPT(x)) jsY_error(J, "expected '%c'", x)
-
static void jsY_next(js_State *J)
{
Rune c;
@@ -168,15 +163,19 @@
J->lexchar = c;
}
+#define jsY_accept(J, x) (J->lexchar == x ? (jsY_next(J), 1) : 0)
+
+#define jsY_expect(J, x) if (!jsY_accept(J, x)) jsY_error(J, "expected '%c'", x)
+
static void jsY_unescape(js_State *J)
{
- if (ACCEPT('\\')) {
- if (ACCEPT('u')) {
+ if (jsY_accept(J, '\\')) {
+ if (jsY_accept(J, 'u')) {
int x = 0;
- if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 12; NEXT();
- if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 8; NEXT();
- if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 4; NEXT();
- if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK);
+ if (!jsY_ishex(J->lexchar)) goto error; x |= jsY_tohex(J->lexchar) << 12; jsY_next(J);
+ if (!jsY_ishex(J->lexchar)) goto error; x |= jsY_tohex(J->lexchar) << 8; jsY_next(J);
+ if (!jsY_ishex(J->lexchar)) goto error; x |= jsY_tohex(J->lexchar) << 4; jsY_next(J);
+ if (!jsY_ishex(J->lexchar)) goto error; x |= jsY_tohex(J->lexchar);
J->lexchar = x;
return;
}
@@ -212,21 +211,21 @@
static void lexlinecomment(js_State *J)
{
- while (PEEK && PEEK != '\n')
- NEXT();
+ while (J->lexchar && J->lexchar != '\n')
+ jsY_next(J);
}
static int lexcomment(js_State *J)
{
/* already consumed initial '/' '*' sequence */
- while (PEEK != 0) {
- if (ACCEPT('*')) {
- while (PEEK == '*')
- NEXT();
- if (ACCEPT('/'))
+ while (J->lexchar != 0) {
+ if (jsY_accept(J, '*')) {
+ while (J->lexchar == '*')
+ jsY_next(J);
+ if (jsY_accept(J, '/'))
return 0;
}
- NEXT();
+ jsY_next(J);
}
return -1;
}
@@ -234,11 +233,11 @@
static double lexhex(js_State *J)
{
double n = 0;
- if (!jsY_ishex(PEEK))
+ if (!jsY_ishex(J->lexchar))
jsY_error(J, "malformed hexadecimal number");
- while (jsY_ishex(PEEK)) {
- n = n * 16 + jsY_tohex(PEEK);
- NEXT();
+ while (jsY_ishex(J->lexchar)) {
+ n = n * 16 + jsY_tohex(J->lexchar);
+ jsY_next(J);
}
return n;
}
@@ -248,11 +247,11 @@
static double lexinteger(js_State *J)
{
double n = 0;
- if (!jsY_isdec(PEEK))
+ if (!jsY_isdec(J->lexchar))
jsY_error(J, "malformed number");
- while (jsY_isdec(PEEK)) {
- n = n * 10 + (PEEK - '0');
- NEXT();
+ while (jsY_isdec(J->lexchar)) {
+ n = n * 10 + (J->lexchar - '0');
+ jsY_next(J);
}
return n;
}
@@ -261,10 +260,10 @@
{
double n = 0;
double d = 1;
- while (jsY_isdec(PEEK)) {
- n = n * 10 + (PEEK - '0');
+ while (jsY_isdec(J->lexchar)) {
+ n = n * 10 + (J->lexchar - '0');
d = d * 10;
- NEXT();
+ jsY_next(J);
}
return n / d;
}
@@ -272,9 +271,9 @@
static double lexexponent(js_State *J)
{
double sign;
- if (ACCEPT('e') || ACCEPT('E')) {
- if (ACCEPT('-')) sign = -1;
- else if (ACCEPT('+')) sign = 1;
+ if (jsY_accept(J, 'e') || jsY_accept(J, 'E')) {
+ if (jsY_accept(J, '-')) sign = -1;
+ else if (jsY_accept(J, '+')) sign = 1;
else sign = 1;
return sign * lexinteger(J);
}
@@ -286,23 +285,23 @@
double n;
double e;
- if (ACCEPT('0')) {
- if (ACCEPT('x') || ACCEPT('X')) {
+ if (jsY_accept(J, '0')) {
+ if (jsY_accept(J, 'x') || jsY_accept(J, 'X')) {
J->number = lexhex(J);
return TK_NUMBER;
}
- if (jsY_isdec(PEEK))
+ if (jsY_isdec(J->lexchar))
jsY_error(J, "number with leading zero");
n = 0;
- if (ACCEPT('.'))
+ if (jsY_accept(J, '.'))
n += lexfraction(J);
- } else if (ACCEPT('.')) {
- if (!jsY_isdec(PEEK))
+ } else if (jsY_accept(J, '.')) {
+ if (!jsY_isdec(J->lexchar))
return '.';
n = lexfraction(J);
} else {
n = lexinteger(J);
- if (ACCEPT('.'))
+ if (jsY_accept(J, '.'))
n += lexfraction(J);
}
@@ -312,7 +311,7 @@
else if (e > 0)
n *= pow(10, e);
- if (jsY_isidentifierstart(PEEK))
+ if (jsY_isidentifierstart(J->lexchar))
jsY_error(J, "number with letter suffix");
J->number = n;
@@ -325,39 +324,39 @@
{
const char *s = J->source - 1;
- if (ACCEPT('0')) {
- if (ACCEPT('x') || ACCEPT('X')) {
+ if (jsY_accept(J, '0')) {
+ if (jsY_accept(J, 'x') || jsY_accept(J, 'X')) {
J->number = lexhex(J);
return TK_NUMBER;
}
- if (jsY_isdec(PEEK))
+ if (jsY_isdec(J->lexchar))
jsY_error(J, "number with leading zero");
- if (ACCEPT('.')) {
- while (jsY_isdec(PEEK))
- NEXT();
+ if (jsY_accept(J, '.')) {
+ while (jsY_isdec(J->lexchar))
+ jsY_next(J);
}
- } else if (ACCEPT('.')) {
- if (!jsY_isdec(PEEK))
+ } else if (jsY_accept(J, '.')) {
+ if (!jsY_isdec(J->lexchar))
return '.';
- while (jsY_isdec(PEEK))
- NEXT();
+ while (jsY_isdec(J->lexchar))
+ jsY_next(J);
} else {
- while (jsY_isdec(PEEK))
- NEXT();
- if (ACCEPT('.')) {
- while (jsY_isdec(PEEK))
- NEXT();
+ while (jsY_isdec(J->lexchar))
+ jsY_next(J);
+ if (jsY_accept(J, '.')) {
+ while (jsY_isdec(J->lexchar))
+ jsY_next(J);
}
}
- if (ACCEPT('e') || ACCEPT('E')) {
- if (PEEK == '-' || PEEK == '+')
- NEXT();
- while (jsY_isdec(PEEK))
- NEXT();
+ if (jsY_accept(J, 'e') || jsY_accept(J, 'E')) {
+ if (J->lexchar == '-' || J->lexchar == '+')
+ jsY_next(J);
+ while (jsY_isdec(J->lexchar))
+ jsY_next(J);
}
- if (jsY_isidentifierstart(PEEK))
+ if (jsY_isidentifierstart(J->lexchar))
jsY_error(J, "number with letter suffix");
J->number = js_strtod(s, NULL);
@@ -373,35 +372,35 @@
/* already consumed '\' */
- if (ACCEPT('\n'))
+ if (jsY_accept(J, '\n'))
return 0;
- switch (PEEK) {
+ switch (J->lexchar) {
case 'u':
- NEXT();
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 12; NEXT(); }
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 8; NEXT(); }
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
+ jsY_next(J);
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar) << 12; jsY_next(J); }
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar) << 8; jsY_next(J); }
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar) << 4; jsY_next(J); }
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar); jsY_next(J); }
textpush(J, x);
break;
case 'x':
- NEXT();
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
- if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
+ jsY_next(J);
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar) << 4; jsY_next(J); }
+ if (!jsY_ishex(J->lexchar)) return 1; else { x |= jsY_tohex(J->lexchar); jsY_next(J); }
textpush(J, x);
break;
- case '0': textpush(J, 0); NEXT(); break;
- case '\\': textpush(J, '\\'); NEXT(); break;
- case '\'': textpush(J, '\''); NEXT(); break;
- case '"': textpush(J, '"'); NEXT(); break;
- case 'b': textpush(J, '\b'); NEXT(); break;
- case 'f': textpush(J, '\f'); NEXT(); break;
- case 'n': textpush(J, '\n'); NEXT(); break;
- case 'r': textpush(J, '\r'); NEXT(); break;
- case 't': textpush(J, '\t'); NEXT(); break;
- case 'v': textpush(J, '\v'); NEXT(); break;
- default: textpush(J, PEEK); NEXT(); break;
+ case '0': textpush(J, 0); jsY_next(J); break;
+ case '\\': textpush(J, '\\'); jsY_next(J); break;
+ case '\'': textpush(J, '\''); jsY_next(J); break;
+ case '"': textpush(J, '"'); jsY_next(J); break;
+ case 'b': textpush(J, '\b'); jsY_next(J); break;
+ case 'f': textpush(J, '\f'); jsY_next(J); break;
+ case 'n': textpush(J, '\n'); jsY_next(J); break;
+ case 'r': textpush(J, '\r'); jsY_next(J); break;
+ case 't': textpush(J, '\t'); jsY_next(J); break;
+ case 'v': textpush(J, '\v'); jsY_next(J); break;
+ default: textpush(J, J->lexchar); jsY_next(J); break;
}
return 0;
}
@@ -410,23 +409,23 @@
{
const char *s;
- int q = PEEK;
- NEXT();
+ int q = J->lexchar;
+ jsY_next(J);
textinit(J);
- while (PEEK != q) {
- if (PEEK == 0 || PEEK == '\n')
+ while (J->lexchar != q) {
+ if (J->lexchar == 0 || J->lexchar == '\n')
jsY_error(J, "string not terminated");
- if (ACCEPT('\\')) {
+ if (jsY_accept(J, '\\')) {
if (lexescape(J))
jsY_error(J, "malformed escape sequence");
} else {
- textpush(J, PEEK);
- NEXT();
+ textpush(J, J->lexchar);
+ jsY_next(J);
}
}
- EXPECT(q);
+ jsY_expect(J, q);
s = textend(J);
@@ -465,29 +464,29 @@
textinit(J);
/* regexp body */
- while (PEEK != '/' || inclass) {
- if (PEEK == 0 || PEEK == '\n') {
+ while (J->lexchar != '/' || inclass) {
+ if (J->lexchar == 0 || J->lexchar == '\n') {
jsY_error(J, "regular expression not terminated");
- } else if (ACCEPT('\\')) {
- if (ACCEPT('/')) {
+ } else if (jsY_accept(J, '\\')) {
+ if (jsY_accept(J, '/')) {
textpush(J, '/');
} else {
textpush(J, '\\');
- if (PEEK == 0 || PEEK == '\n')
+ if (J->lexchar == 0 || J->lexchar == '\n')
jsY_error(J, "regular expression not terminated");
- textpush(J, PEEK);
- NEXT();
+ textpush(J, J->lexchar);
+ jsY_next(J);
}
} else {
- if (PEEK == '[' && !inclass)
+ if (J->lexchar == '[' && !inclass)
inclass = 1;
- if (PEEK == ']' && inclass)
+ if (J->lexchar == ']' && inclass)
inclass = 0;
- textpush(J, PEEK);
- NEXT();
+ textpush(J, J->lexchar);
+ jsY_next(J);
}
}
- EXPECT('/');
+ jsY_expect(J, '/');
s = textend(J);
@@ -494,11 +493,11 @@
/* regexp flags */
g = i = m = 0;
- while (jsY_isidentifierpart(PEEK)) {
- if (ACCEPT('g')) ++g;
- else if (ACCEPT('i')) ++i;
- else if (ACCEPT('m')) ++m;
- else jsY_error(J, "illegal flag in regular expression: %c", PEEK);
+ while (jsY_isidentifierpart(J->lexchar)) {
+ if (jsY_accept(J, 'g')) ++g;
+ else if (jsY_accept(J, 'i')) ++i;
+ else if (jsY_accept(J, 'm')) ++m;
+ else jsY_error(J, "illegal flag in regular expression: %c", J->lexchar);
}
if (g > 1 || i > 1 || m > 1)
@@ -533,10 +532,10 @@
while (1) {
J->lexline = J->line; /* save location of beginning of token */
- while (jsY_iswhite(PEEK))
- NEXT();
+ while (jsY_iswhite(J->lexchar))
+ jsY_next(J);
- if (ACCEPT('\n')) {
+ if (jsY_accept(J, '\n')) {
J->newline = 1;
if (isnlthcontext(J->lasttoken))
return ';';
@@ -543,17 +542,17 @@
continue;
}
- if (ACCEPT('/')) {
- if (ACCEPT('/')) {
+ if (jsY_accept(J, '/')) {
+ if (jsY_accept(J, '/')) {
lexlinecomment(J);
continue;
- } else if (ACCEPT('*')) {
+ } else if (jsY_accept(J, '*')) {
if (lexcomment(J))
jsY_error(J, "multi-line comment not terminated");
continue;
} else if (isregexpcontext(J->lasttoken)) {
return lexregexp(J);
- } else if (ACCEPT('=')) {
+ } else if (jsY_accept(J, '=')) {
return TK_DIV_ASS;
} else {
return '/';
@@ -560,22 +559,22 @@
}
}
- if (PEEK >= '0' && PEEK <= '9') {
+ if (J->lexchar >= '0' && J->lexchar <= '9') {
return lexnumber(J);
}
- switch (PEEK) {
- case '(': NEXT(); return '(';
- case ')': NEXT(); return ')';
- case ',': NEXT(); return ',';
- case ':': NEXT(); return ':';
- case ';': NEXT(); return ';';
- case '?': NEXT(); return '?';
- case '[': NEXT(); return '[';
- case ']': NEXT(); return ']';
- case '{': NEXT(); return '{';
- case '}': NEXT(); return '}';
- case '~': NEXT(); return '~';
+ switch (J->lexchar) {
+ case '(': jsY_next(J); return '(';
+ case ')': jsY_next(J); return ')';
+ case ',': jsY_next(J); return ',';
+ case ':': jsY_next(J); return ':';
+ case ';': jsY_next(J); return ';';
+ case '?': jsY_next(J); return '?';
+ case '[': jsY_next(J); return '[';
+ case ']': jsY_next(J); return ']';
+ case '{': jsY_next(J); return '{';
+ case '}': jsY_next(J); return '}';
+ case '~': jsY_next(J); return '~';
case '\'':
case '"':
@@ -585,36 +584,36 @@
return lexnumber(J);
case '<':
- NEXT();
- if (ACCEPT('<')) {
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '<')) {
+ if (jsY_accept(J, '='))
return TK_SHL_ASS;
return TK_SHL;
}
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_LE;
return '<';
case '>':
- NEXT();
- if (ACCEPT('>')) {
- if (ACCEPT('>')) {
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '>')) {
+ if (jsY_accept(J, '>')) {
+ if (jsY_accept(J, '='))
return TK_USHR_ASS;
return TK_USHR;
}
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_SHR_ASS;
return TK_SHR;
}
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_GE;
return '>';
case '=':
- NEXT();
- if (ACCEPT('=')) {
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '=')) {
+ if (jsY_accept(J, '='))
return TK_STRICTEQ;
return TK_EQ;
}
@@ -621,9 +620,9 @@
return '=';
case '!':
- NEXT();
- if (ACCEPT('=')) {
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '=')) {
+ if (jsY_accept(J, '='))
return TK_STRICTNE;
return TK_NE;
}
@@ -630,52 +629,52 @@
return '!';
case '+':
- NEXT();
- if (ACCEPT('+'))
+ jsY_next(J);
+ if (jsY_accept(J, '+'))
return TK_INC;
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_ADD_ASS;
return '+';
case '-':
- NEXT();
- if (ACCEPT('-'))
+ jsY_next(J);
+ if (jsY_accept(J, '-'))
return TK_DEC;
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_SUB_ASS;
return '-';
case '*':
- NEXT();
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '='))
return TK_MUL_ASS;
return '*';
case '%':
- NEXT();
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '='))
return TK_MOD_ASS;
return '%';
case '&':
- NEXT();
- if (ACCEPT('&'))
+ jsY_next(J);
+ if (jsY_accept(J, '&'))
return TK_AND;
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_AND_ASS;
return '&';
case '|':
- NEXT();
- if (ACCEPT('|'))
+ jsY_next(J);
+ if (jsY_accept(J, '|'))
return TK_OR;
- if (ACCEPT('='))
+ if (jsY_accept(J, '='))
return TK_OR_ASS;
return '|';
case '^':
- NEXT();
- if (ACCEPT('='))
+ jsY_next(J);
+ if (jsY_accept(J, '='))
return TK_XOR_ASS;
return '^';
@@ -685,15 +684,15 @@
/* Handle \uXXXX escapes in identifiers */
jsY_unescape(J);
- if (jsY_isidentifierstart(PEEK)) {
+ if (jsY_isidentifierstart(J->lexchar)) {
textinit(J);
- textpush(J, PEEK);
+ textpush(J, J->lexchar);
- NEXT();
+ jsY_next(J);
jsY_unescape(J);
- while (jsY_isidentifierpart(PEEK)) {
- textpush(J, PEEK);
- NEXT();
+ while (jsY_isidentifierpart(J->lexchar)) {
+ textpush(J, J->lexchar);
+ jsY_next(J);
jsY_unescape(J);
}
@@ -702,9 +701,9 @@
return jsY_findkeyword(J, J->lexbuf.text);
}
- if (PEEK >= 0x20 && PEEK <= 0x7E)
- jsY_error(J, "unexpected character: '%c'", PEEK);
- jsY_error(J, "unexpected character: \\u%04X", PEEK);
+ if (J->lexchar >= 0x20 && J->lexchar <= 0x7E)
+ jsY_error(J, "unexpected character: '%c'", J->lexchar);
+ jsY_error(J, "unexpected character: \\u%04X", J->lexchar);
}
}
@@ -714,7 +713,7 @@
J->source = source;
J->line = 1;
J->lasttoken = 0;
- NEXT(); /* load first lookahead character */
+ jsY_next(J); /* load first lookahead character */
}
int jsY_lex(js_State *J)
@@ -727,20 +726,20 @@
while (1) {
J->lexline = J->line; /* save location of beginning of token */
- while (jsY_iswhite(PEEK) || PEEK == '\n')
- NEXT();
+ while (jsY_iswhite(J->lexchar) || J->lexchar == '\n')
+ jsY_next(J);
- if (PEEK >= '0' && PEEK <= '9') {
+ if (J->lexchar >= '0' && J->lexchar <= '9') {
return lexnumber(J);
}
- switch (PEEK) {
- case ',': NEXT(); return ',';
- case ':': NEXT(); return ':';
- case '[': NEXT(); return '[';
- case ']': NEXT(); return ']';
- case '{': NEXT(); return '{';
- case '}': NEXT(); return '}';
+ switch (J->lexchar) {
+ case ',': jsY_next(J); return ',';
+ case ':': jsY_next(J); return ':';
+ case '[': jsY_next(J); return '[';
+ case ']': jsY_next(J); return ']';
+ case '{': jsY_next(J); return '{';
+ case '}': jsY_next(J); return '}';
case '"':
return lexstring(J);
@@ -749,15 +748,15 @@
return lexnumber(J);
case 'f':
- NEXT(); EXPECT('a'); EXPECT('l'); EXPECT('s'); EXPECT('e');
+ jsY_next(J); jsY_expect(J, 'a'); jsY_expect(J, 'l'); jsY_expect(J, 's'); jsY_expect(J, 'e');
return TK_FALSE;
case 'n':
- NEXT(); EXPECT('u'); EXPECT('l'); EXPECT('l');
+ jsY_next(J); jsY_expect(J, 'u'); jsY_expect(J, 'l'); jsY_expect(J, 'l');
return TK_NULL;
case 't':
- NEXT(); EXPECT('r'); EXPECT('u'); EXPECT('e');
+ jsY_next(J); jsY_expect(J, 'r'); jsY_expect(J, 'u'); jsY_expect(J, 'e');
return TK_TRUE;
case 0:
@@ -764,8 +763,8 @@
return 0; /* EOF */
}
- if (PEEK >= 0x20 && PEEK <= 0x7E)
- jsY_error(J, "unexpected character: '%c'", PEEK);
- jsY_error(J, "unexpected character: \\u%04X", PEEK);
+ if (J->lexchar >= 0x20 && J->lexchar <= 0x7E)
+ jsY_error(J, "unexpected character: '%c'", J->lexchar);
+ jsY_error(J, "unexpected character: \\u%04X", J->lexchar);
}
}
--- a/jsparse.c
+++ b/jsparse.c
@@ -15,8 +15,6 @@
#define STM3(x,a,b,c) jsP_newnode(J, STM_ ## x, a, b, c, 0)
#define STM4(x,a,b,c,d) jsP_newnode(J, STM_ ## x, a, b, c, d)
-#define TOKSTR jsY_tokenstring(J->lookahead)
-
static js_Ast *expression(js_State *J, int notin);
static js_Ast *assignment(js_State *J, int notin);
static js_Ast *memberexp(js_State *J);
@@ -128,37 +126,25 @@
/* Lookahead */
-static void next(js_State *J)
+static void jsP_next(js_State *J)
{
J->astline = J->lexline;
J->lookahead = jsY_lex(J);
}
-static int accept(js_State *J, int t)
-{
- if (J->lookahead == t) {
- next(J);
- return 1;
- }
- return 0;
-}
+#define jsP_accept(J,x) (J->lookahead == x ? (jsP_next(J), 1) : 0)
-static void expect(js_State *J, int t)
-{
- if (accept(J, t))
- return;
- jsP_error(J, "unexpected token: %s (expected %s)", TOKSTR, jsY_tokenstring(t));
-}
+#define jsP_expect(J,x) if (!jsP_accept(J, x)) jsP_error(J, "unexpected token: %s (expected %s)", jsY_tokenstring(J->lookahead), jsY_tokenstring(x))
static void semicolon(js_State *J)
{
if (J->lookahead == ';') {
- next(J);
+ jsP_next(J);
return;
}
if (J->newline || J->lookahead == '}' || J->lookahead == 0)
return;
- jsP_error(J, "unexpected token: %s (expected ';')", TOKSTR);
+ jsP_error(J, "unexpected token: %s (expected ';')", jsY_tokenstring(J->lookahead));
}
/* Literals */
@@ -186,10 +172,10 @@
if (J->lookahead == TK_IDENTIFIER) {
checkfutureword(J, J->text);
a = jsP_newstrnode(J, AST_IDENTIFIER, J->text);
- next(J);
+ jsP_next(J);
return a;
}
- jsP_error(J, "unexpected token: %s (expected identifier)", TOKSTR);
+ jsP_error(J, "unexpected token: %s (expected identifier)", jsY_tokenstring(J->lookahead));
}
static js_Ast *identifieropt(js_State *J)
@@ -203,10 +189,10 @@
{
if (J->lookahead == TK_IDENTIFIER || J->lookahead >= TK_BREAK) {
js_Ast *a = jsP_newstrnode(J, AST_IDENTIFIER, J->text);
- next(J);
+ jsP_next(J);
return a;
}
- jsP_error(J, "unexpected token: %s (expected identifier or keyword)", TOKSTR);
+ jsP_error(J, "unexpected token: %s (expected identifier or keyword)", jsY_tokenstring(J->lookahead));
}
static js_Ast *arrayelement(js_State *J)
@@ -222,7 +208,7 @@
if (J->lookahead == ']')
return NULL;
head = tail = LIST(arrayelement(J));
- while (accept(J, ',')) {
+ while (jsP_accept(J, ',')) {
if (J->lookahead != ']')
tail = tail->b = LIST(arrayelement(J));
}
@@ -234,10 +220,10 @@
js_Ast *name;
if (J->lookahead == TK_NUMBER) {
name = jsP_newnumnode(J, EXP_NUMBER, J->number);
- next(J);
+ jsP_next(J);
} else if (J->lookahead == TK_STRING) {
name = jsP_newstrnode(J, EXP_STRING, J->text);
- next(J);
+ jsP_next(J);
} else {
name = identifiername(J);
}
@@ -253,22 +239,22 @@
if (J->lookahead != ':' && name->type == AST_IDENTIFIER) {
if (!strcmp(name->string, "get")) {
name = propname(J);
- expect(J, '(');
- expect(J, ')');
+ jsP_expect(J, '(');
+ jsP_expect(J, ')');
body = funbody(J);
return EXP3(PROP_GET, name, NULL, body);
}
if (!strcmp(name->string, "set")) {
name = propname(J);
- expect(J, '(');
+ jsP_expect(J, '(');
arg = identifier(J);
- expect(J, ')');
+ jsP_expect(J, ')');
body = funbody(J);
return EXP3(PROP_SET, name, LIST(arg), body);
}
}
- expect(J, ':');
+ jsP_expect(J, ':');
value = assignment(J, 0);
return EXP2(PROP_VAL, name, value);
}
@@ -279,7 +265,7 @@
if (J->lookahead == '}')
return NULL;
head = tail = LIST(propassign(J));
- while (accept(J, ',')) {
+ while (jsP_accept(J, ',')) {
if (J->lookahead == '}')
break;
tail = tail->b = LIST(propassign(J));
@@ -295,7 +281,7 @@
if (J->lookahead == ')')
return NULL;
head = tail = LIST(identifier(J));
- while (accept(J, ',')) {
+ while (jsP_accept(J, ',')) {
tail = tail->b = LIST(identifier(J));
}
return jsP_list(head);
@@ -305,9 +291,9 @@
{
js_Ast *a, *b, *c;
a = identifier(J);
- expect(J, '(');
+ jsP_expect(J, '(');
b = parameters(J);
- expect(J, ')');
+ jsP_expect(J, ')');
c = funbody(J);
return jsP_newnode(J, AST_FUNDEC, a, b, c, 0);
}
@@ -316,9 +302,9 @@
{
js_Ast *a, *b, *c;
a = identifier(J);
- expect(J, '(');
+ jsP_expect(J, '(');
b = parameters(J);
- expect(J, ')');
+ jsP_expect(J, ')');
c = funbody(J);
/* rewrite function statement as "var X = function X() {}" */
return STM1(VAR, LIST(EXP2(VAR, a, EXP3(FUN, a, b, c))));
@@ -328,9 +314,9 @@
{
js_Ast *a, *b, *c;
a = identifieropt(J);
- expect(J, '(');
+ jsP_expect(J, '(');
b = parameters(J);
- expect(J, ')');
+ jsP_expect(J, ')');
c = funbody(J);
return EXP3(FUN, a, b, c);
}
@@ -344,35 +330,35 @@
if (J->lookahead == TK_IDENTIFIER) {
checkfutureword(J, J->text);
a = jsP_newstrnode(J, EXP_IDENTIFIER, J->text);
- next(J);
+ jsP_next(J);
return a;
}
if (J->lookahead == TK_STRING) {
a = jsP_newstrnode(J, EXP_STRING, J->text);
- next(J);
+ jsP_next(J);
return a;
}
if (J->lookahead == TK_REGEXP) {
a = jsP_newstrnode(J, EXP_REGEXP, J->text);
a->number = J->number;
- next(J);
+ jsP_next(J);
return a;
}
if (J->lookahead == TK_NUMBER) {
a = jsP_newnumnode(J, EXP_NUMBER, J->number);
- next(J);
+ jsP_next(J);
return a;
}
- if (accept(J, TK_THIS)) return EXP0(THIS);
- if (accept(J, TK_NULL)) return EXP0(NULL);
- if (accept(J, TK_TRUE)) return EXP0(TRUE);
- if (accept(J, TK_FALSE)) return EXP0(FALSE);
- if (accept(J, '{')) { a = EXP1(OBJECT, objectliteral(J)); expect(J, '}'); return a; }
- if (accept(J, '[')) { a = EXP1(ARRAY, arrayliteral(J)); expect(J, ']'); return a; }
- if (accept(J, '(')) { a = expression(J, 0); expect(J, ')'); return a; }
+ if (jsP_accept(J, TK_THIS)) return EXP0(THIS);
+ if (jsP_accept(J, TK_NULL)) return EXP0(NULL);
+ if (jsP_accept(J, TK_TRUE)) return EXP0(TRUE);
+ if (jsP_accept(J, TK_FALSE)) return EXP0(FALSE);
+ if (jsP_accept(J, '{')) { a = EXP1(OBJECT, objectliteral(J)); jsP_expect(J, '}'); return a; }
+ if (jsP_accept(J, '[')) { a = EXP1(ARRAY, arrayliteral(J)); jsP_expect(J, ']'); return a; }
+ if (jsP_accept(J, '(')) { a = expression(J, 0); jsP_expect(J, ')'); return a; }
- jsP_error(J, "unexpected token in expression: %s", TOKSTR);
+ jsP_error(J, "unexpected token in expression: %s", jsY_tokenstring(J->lookahead));
}
static js_Ast *arguments(js_State *J)
@@ -381,7 +367,7 @@
if (J->lookahead == ')')
return NULL;
head = tail = LIST(assignment(J, 0));
- while (accept(J, ',')) {
+ while (jsP_accept(J, ',')) {
tail = tail->b = LIST(assignment(J, 0));
}
return jsP_list(head);
@@ -391,17 +377,17 @@
{
js_Ast *a, *b;
- if (accept(J, TK_NEW)) {
+ if (jsP_accept(J, TK_NEW)) {
a = memberexp(J);
- if (accept(J, '(')) {
+ if (jsP_accept(J, '(')) {
b = arguments(J);
- expect(J, ')');
+ jsP_expect(J, ')');
return EXP2(NEW, a, b);
}
return EXP1(NEW, a);
}
- if (accept(J, TK_FUNCTION))
+ if (jsP_accept(J, TK_FUNCTION))
return funexp(J);
return primary(J);
@@ -411,8 +397,8 @@
{
js_Ast *a = newexp(J);
loop:
- if (accept(J, '.')) { a = EXP2(MEMBER, a, identifiername(J)); goto loop; }
- if (accept(J, '[')) { a = EXP2(INDEX, a, expression(J, 0)); expect(J, ']'); goto loop; }
+ if (jsP_accept(J, '.')) { a = EXP2(MEMBER, a, identifiername(J)); goto loop; }
+ if (jsP_accept(J, '[')) { a = EXP2(INDEX, a, expression(J, 0)); jsP_expect(J, ']'); goto loop; }
return a;
}
@@ -420,9 +406,9 @@
{
js_Ast *a = newexp(J);
loop:
- if (accept(J, '.')) { a = EXP2(MEMBER, a, identifiername(J)); goto loop; }
- if (accept(J, '[')) { a = EXP2(INDEX, a, expression(J, 0)); expect(J, ']'); goto loop; }
- if (accept(J, '(')) { a = EXP2(CALL, a, arguments(J)); expect(J, ')'); goto loop; }
+ if (jsP_accept(J, '.')) { a = EXP2(MEMBER, a, identifiername(J)); goto loop; }
+ if (jsP_accept(J, '[')) { a = EXP2(INDEX, a, expression(J, 0)); jsP_expect(J, ']'); goto loop; }
+ if (jsP_accept(J, '(')) { a = EXP2(CALL, a, arguments(J)); jsP_expect(J, ')'); goto loop; }
return a;
}
@@ -429,22 +415,22 @@
static js_Ast *postfix(js_State *J)
{
js_Ast *a = callexp(J);
- if (!J->newline && accept(J, TK_INC)) return EXP1(POSTINC, a);
- if (!J->newline && accept(J, TK_DEC)) return EXP1(POSTDEC, a);
+ if (!J->newline && jsP_accept(J, TK_INC)) return EXP1(POSTINC, a);
+ if (!J->newline && jsP_accept(J, TK_DEC)) return EXP1(POSTDEC, a);
return a;
}
static js_Ast *unary(js_State *J)
{
- if (accept(J, TK_DELETE)) return EXP1(DELETE, unary(J));
- if (accept(J, TK_VOID)) return EXP1(VOID, unary(J));
- if (accept(J, TK_TYPEOF)) return EXP1(TYPEOF, unary(J));
- if (accept(J, TK_INC)) return EXP1(PREINC, unary(J));
- if (accept(J, TK_DEC)) return EXP1(PREDEC, unary(J));
- if (accept(J, '+')) return EXP1(POS, unary(J));
- if (accept(J, '-')) return EXP1(NEG, unary(J));
- if (accept(J, '~')) return EXP1(BITNOT, unary(J));
- if (accept(J, '!')) return EXP1(LOGNOT, unary(J));
+ if (jsP_accept(J, TK_DELETE)) return EXP1(DELETE, unary(J));
+ if (jsP_accept(J, TK_VOID)) return EXP1(VOID, unary(J));
+ if (jsP_accept(J, TK_TYPEOF)) return EXP1(TYPEOF, unary(J));
+ if (jsP_accept(J, TK_INC)) return EXP1(PREINC, unary(J));
+ if (jsP_accept(J, TK_DEC)) return EXP1(PREDEC, unary(J));
+ if (jsP_accept(J, '+')) return EXP1(POS, unary(J));
+ if (jsP_accept(J, '-')) return EXP1(NEG, unary(J));
+ if (jsP_accept(J, '~')) return EXP1(BITNOT, unary(J));
+ if (jsP_accept(J, '!')) return EXP1(LOGNOT, unary(J));
return postfix(J);
}
@@ -452,9 +438,9 @@
{
js_Ast *a = unary(J);
loop:
- if (accept(J, '*')) { a = EXP2(MUL, a, unary(J)); goto loop; }
- if (accept(J, '/')) { a = EXP2(DIV, a, unary(J)); goto loop; }
- if (accept(J, '%')) { a = EXP2(MOD, a, unary(J)); goto loop; }
+ if (jsP_accept(J, '*')) { a = EXP2(MUL, a, unary(J)); goto loop; }
+ if (jsP_accept(J, '/')) { a = EXP2(DIV, a, unary(J)); goto loop; }
+ if (jsP_accept(J, '%')) { a = EXP2(MOD, a, unary(J)); goto loop; }
return a;
}
@@ -462,8 +448,8 @@
{
js_Ast *a = multiplicative(J);
loop:
- if (accept(J, '+')) { a = EXP2(ADD, a, multiplicative(J)); goto loop; }
- if (accept(J, '-')) { a = EXP2(SUB, a, multiplicative(J)); goto loop; }
+ if (jsP_accept(J, '+')) { a = EXP2(ADD, a, multiplicative(J)); goto loop; }
+ if (jsP_accept(J, '-')) { a = EXP2(SUB, a, multiplicative(J)); goto loop; }
return a;
}
@@ -471,9 +457,9 @@
{
js_Ast *a = additive(J);
loop:
- if (accept(J, TK_SHL)) { a = EXP2(SHL, a, additive(J)); goto loop; }
- if (accept(J, TK_SHR)) { a = EXP2(SHR, a, additive(J)); goto loop; }
- if (accept(J, TK_USHR)) { a = EXP2(USHR, a, additive(J)); goto loop; }
+ if (jsP_accept(J, TK_SHL)) { a = EXP2(SHL, a, additive(J)); goto loop; }
+ if (jsP_accept(J, TK_SHR)) { a = EXP2(SHR, a, additive(J)); goto loop; }
+ if (jsP_accept(J, TK_USHR)) { a = EXP2(USHR, a, additive(J)); goto loop; }
return a;
}
@@ -481,12 +467,12 @@
{
js_Ast *a = shift(J);
loop:
- if (accept(J, '<')) { a = EXP2(LT, a, shift(J)); goto loop; }
- if (accept(J, '>')) { a = EXP2(GT, a, shift(J)); goto loop; }
- if (accept(J, TK_LE)) { a = EXP2(LE, a, shift(J)); goto loop; }
- if (accept(J, TK_GE)) { a = EXP2(GE, a, shift(J)); goto loop; }
- if (accept(J, TK_INSTANCEOF)) { a = EXP2(INSTANCEOF, a, shift(J)); goto loop; }
- if (!notin && accept(J, TK_IN)) { a = EXP2(IN, a, shift(J)); goto loop; }
+ if (jsP_accept(J, '<')) { a = EXP2(LT, a, shift(J)); goto loop; }
+ if (jsP_accept(J, '>')) { a = EXP2(GT, a, shift(J)); goto loop; }
+ if (jsP_accept(J, TK_LE)) { a = EXP2(LE, a, shift(J)); goto loop; }
+ if (jsP_accept(J, TK_GE)) { a = EXP2(GE, a, shift(J)); goto loop; }
+ if (jsP_accept(J, TK_INSTANCEOF)) { a = EXP2(INSTANCEOF, a, shift(J)); goto loop; }
+ if (!notin && jsP_accept(J, TK_IN)) { a = EXP2(IN, a, shift(J)); goto loop; }
return a;
}
@@ -494,10 +480,10 @@
{
js_Ast *a = relational(J, notin);
loop:
- if (accept(J, TK_EQ)) { a = EXP2(EQ, a, relational(J, notin)); goto loop; }
- if (accept(J, TK_NE)) { a = EXP2(NE, a, relational(J, notin)); goto loop; }
- if (accept(J, TK_STRICTEQ)) { a = EXP2(STRICTEQ, a, relational(J, notin)); goto loop; }
- if (accept(J, TK_STRICTNE)) { a = EXP2(STRICTNE, a, relational(J, notin)); goto loop; }
+ if (jsP_accept(J, TK_EQ)) { a = EXP2(EQ, a, relational(J, notin)); goto loop; }
+ if (jsP_accept(J, TK_NE)) { a = EXP2(NE, a, relational(J, notin)); goto loop; }
+ if (jsP_accept(J, TK_STRICTEQ)) { a = EXP2(STRICTEQ, a, relational(J, notin)); goto loop; }
+ if (jsP_accept(J, TK_STRICTNE)) { a = EXP2(STRICTNE, a, relational(J, notin)); goto loop; }
return a;
}
@@ -504,7 +490,7 @@
static js_Ast *bitand(js_State *J, int notin)
{
js_Ast *a = equality(J, notin);
- while (accept(J, '&'))
+ while (jsP_accept(J, '&'))
a = EXP2(BITAND, a, equality(J, notin));
return a;
}
@@ -512,7 +498,7 @@
static js_Ast *bitxor(js_State *J, int notin)
{
js_Ast *a = bitand(J, notin);
- while (accept(J, '^'))
+ while (jsP_accept(J, '^'))
a = EXP2(BITXOR, a, bitand(J, notin));
return a;
}
@@ -520,7 +506,7 @@
static js_Ast *bitor(js_State *J, int notin)
{
js_Ast *a = bitxor(J, notin);
- while (accept(J, '|'))
+ while (jsP_accept(J, '|'))
a = EXP2(BITOR, a, bitxor(J, notin));
return a;
}
@@ -528,7 +514,7 @@
static js_Ast *logand(js_State *J, int notin)
{
js_Ast *a = bitor(J, notin);
- if (accept(J, TK_AND))
+ if (jsP_accept(J, TK_AND))
a = EXP2(LOGAND, a, logand(J, notin));
return a;
}
@@ -536,7 +522,7 @@
static js_Ast *logor(js_State *J, int notin)
{
js_Ast *a = logand(J, notin);
- if (accept(J, TK_OR))
+ if (jsP_accept(J, TK_OR))
a = EXP2(LOGOR, a, logor(J, notin));
return a;
}
@@ -545,9 +531,9 @@
{
js_Ast *a, *b, *c;
a = logor(J, notin);
- if (accept(J, '?')) {
+ if (jsP_accept(J, '?')) {
b = assignment(J, 0);
- expect(J, ':');
+ jsP_expect(J, ':');
c = assignment(J, notin);
return EXP3(COND, a, b, c);
}
@@ -557,18 +543,18 @@
static js_Ast *assignment(js_State *J, int notin)
{
js_Ast *a = conditional(J, notin);
- if (accept(J, '=')) return EXP2(ASS, a, assignment(J, notin));
- if (accept(J, TK_MUL_ASS)) return EXP2(ASS_MUL, a, assignment(J, notin));
- if (accept(J, TK_DIV_ASS)) return EXP2(ASS_DIV, a, assignment(J, notin));
- if (accept(J, TK_MOD_ASS)) return EXP2(ASS_MOD, a, assignment(J, notin));
- if (accept(J, TK_ADD_ASS)) return EXP2(ASS_ADD, a, assignment(J, notin));
- if (accept(J, TK_SUB_ASS)) return EXP2(ASS_SUB, a, assignment(J, notin));
- if (accept(J, TK_SHL_ASS)) return EXP2(ASS_SHL, a, assignment(J, notin));
- if (accept(J, TK_SHR_ASS)) return EXP2(ASS_SHR, a, assignment(J, notin));
- if (accept(J, TK_USHR_ASS)) return EXP2(ASS_USHR, a, assignment(J, notin));
- if (accept(J, TK_AND_ASS)) return EXP2(ASS_BITAND, a, assignment(J, notin));
- if (accept(J, TK_XOR_ASS)) return EXP2(ASS_BITXOR, a, assignment(J, notin));
- if (accept(J, TK_OR_ASS)) return EXP2(ASS_BITOR, a, assignment(J, notin));
+ if (jsP_accept(J, '=')) return EXP2(ASS, a, assignment(J, notin));
+ if (jsP_accept(J, TK_MUL_ASS)) return EXP2(ASS_MUL, a, assignment(J, notin));
+ if (jsP_accept(J, TK_DIV_ASS)) return EXP2(ASS_DIV, a, assignment(J, notin));
+ if (jsP_accept(J, TK_MOD_ASS)) return EXP2(ASS_MOD, a, assignment(J, notin));
+ if (jsP_accept(J, TK_ADD_ASS)) return EXP2(ASS_ADD, a, assignment(J, notin));
+ if (jsP_accept(J, TK_SUB_ASS)) return EXP2(ASS_SUB, a, assignment(J, notin));
+ if (jsP_accept(J, TK_SHL_ASS)) return EXP2(ASS_SHL, a, assignment(J, notin));
+ if (jsP_accept(J, TK_SHR_ASS)) return EXP2(ASS_SHR, a, assignment(J, notin));
+ if (jsP_accept(J, TK_USHR_ASS)) return EXP2(ASS_USHR, a, assignment(J, notin));
+ if (jsP_accept(J, TK_AND_ASS)) return EXP2(ASS_BITAND, a, assignment(J, notin));
+ if (jsP_accept(J, TK_XOR_ASS)) return EXP2(ASS_BITXOR, a, assignment(J, notin));
+ if (jsP_accept(J, TK_OR_ASS)) return EXP2(ASS_BITOR, a, assignment(J, notin));
return a;
}
@@ -575,7 +561,7 @@
static js_Ast *expression(js_State *J, int notin)
{
js_Ast *a = assignment(J, notin);
- while (accept(J, ','))
+ while (jsP_accept(J, ','))
a = EXP2(COMMA, a, assignment(J, notin));
return a;
}
@@ -585,7 +571,7 @@
static js_Ast *vardec(js_State *J, int notin)
{
js_Ast *a = identifier(J);
- if (accept(J, '='))
+ if (jsP_accept(J, '='))
return EXP2(VAR, a, assignment(J, notin));
return EXP1(VAR, a);
}
@@ -594,7 +580,7 @@
{
js_Ast *head, *tail;
head = tail = LIST(vardec(J, notin));
- while (accept(J, ','))
+ while (jsP_accept(J, ','))
tail = tail->b = LIST(vardec(J, notin));
return jsP_list(head);
}
@@ -614,20 +600,20 @@
{
js_Ast *a, *b;
- if (accept(J, TK_CASE)) {
+ if (jsP_accept(J, TK_CASE)) {
a = expression(J, 0);
- expect(J, ':');
+ jsP_expect(J, ':');
b = statementlist(J);
return STM2(CASE, a, b);
}
- if (accept(J, TK_DEFAULT)) {
- expect(J, ':');
+ if (jsP_accept(J, TK_DEFAULT)) {
+ jsP_expect(J, ':');
a = statementlist(J);
return STM1(DEFAULT, a);
}
- jsP_error(J, "unexpected token in switch: %s (expected 'case' or 'default')", TOKSTR);
+ jsP_error(J, "unexpected token in switch: %s (expected 'case' or 'default')", jsY_tokenstring(J->lookahead));
}
static js_Ast *caselist(js_State *J)
@@ -644,9 +630,9 @@
static js_Ast *block(js_State *J)
{
js_Ast *a;
- expect(J, '{');
+ jsP_expect(J, '{');
a = statementlist(J);
- expect(J, '}');
+ jsP_expect(J, '}');
return STM1(BLOCK, a);
}
@@ -655,7 +641,7 @@
js_Ast *a = NULL;
if (J->lookahead != end)
a = expression(J, 0);
- expect(J, end);
+ jsP_expect(J, end);
return a;
}
@@ -662,22 +648,22 @@
static js_Ast *forstatement(js_State *J)
{
js_Ast *a, *b, *c, *d;
- expect(J, '(');
- if (accept(J, TK_VAR)) {
+ jsP_expect(J, '(');
+ if (jsP_accept(J, TK_VAR)) {
a = vardeclist(J, 1);
- if (accept(J, ';')) {
+ if (jsP_accept(J, ';')) {
b = forexpression(J, ';');
c = forexpression(J, ')');
d = statement(J);
return STM4(FOR_VAR, a, b, c, d);
}
- if (accept(J, TK_IN)) {
+ if (jsP_accept(J, TK_IN)) {
b = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
c = statement(J);
return STM3(FOR_IN_VAR, a, b, c);
}
- jsP_error(J, "unexpected token in for-var-statement: %s", TOKSTR);
+ jsP_error(J, "unexpected token in for-var-statement: %s", jsY_tokenstring(J->lookahead));
}
if (J->lookahead != ';')
@@ -684,19 +670,19 @@
a = expression(J, 1);
else
a = NULL;
- if (accept(J, ';')) {
+ if (jsP_accept(J, ';')) {
b = forexpression(J, ';');
c = forexpression(J, ')');
d = statement(J);
return STM4(FOR, a, b, c, d);
}
- if (accept(J, TK_IN)) {
+ if (jsP_accept(J, TK_IN)) {
b = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
c = statement(J);
return STM3(FOR_IN, a, b, c);
}
- jsP_error(J, "unexpected token in for-statement: %s", TOKSTR);
+ jsP_error(J, "unexpected token in for-statement: %s", jsY_tokenstring(J->lookahead));
}
static js_Ast *statement(js_State *J)
@@ -707,7 +693,7 @@
return block(J);
}
- if (accept(J, TK_VAR)) {
+ if (jsP_accept(J, TK_VAR)) {
a = vardeclist(J, 0);
semicolon(J);
return STM1(VAR, a);
@@ -714,16 +700,16 @@
}
/* empty statement */
- if (accept(J, ';')) {
+ if (jsP_accept(J, ';')) {
return STM0(EMPTY);
}
- if (accept(J, TK_IF)) {
- expect(J, '(');
+ if (jsP_accept(J, TK_IF)) {
+ jsP_expect(J, '(');
a = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
b = statement(J);
- if (accept(J, TK_ELSE))
+ if (jsP_accept(J, TK_ELSE))
c = statement(J);
else
c = NULL;
@@ -730,41 +716,41 @@
return STM3(IF, a, b, c);
}
- if (accept(J, TK_DO)) {
+ if (jsP_accept(J, TK_DO)) {
a = statement(J);
- expect(J, TK_WHILE);
- expect(J, '(');
+ jsP_expect(J, TK_WHILE);
+ jsP_expect(J, '(');
b = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
semicolon(J);
return STM2(DO, a, b);
}
- if (accept(J, TK_WHILE)) {
- expect(J, '(');
+ if (jsP_accept(J, TK_WHILE)) {
+ jsP_expect(J, '(');
a = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
b = statement(J);
return STM2(WHILE, a, b);
}
- if (accept(J, TK_FOR)) {
+ if (jsP_accept(J, TK_FOR)) {
return forstatement(J);
}
- if (accept(J, TK_CONTINUE)) {
+ if (jsP_accept(J, TK_CONTINUE)) {
a = identifieropt(J);
semicolon(J);
return STM1(CONTINUE, a);
}
- if (accept(J, TK_BREAK)) {
+ if (jsP_accept(J, TK_BREAK)) {
a = identifieropt(J);
semicolon(J);
return STM1(BREAK, a);
}
- if (accept(J, TK_RETURN)) {
+ if (jsP_accept(J, TK_RETURN)) {
if (J->lookahead != ';' && J->lookahead != '}' && J->lookahead != 0)
a = expression(J, 0);
else
@@ -773,53 +759,53 @@
return STM1(RETURN, a);
}
- if (accept(J, TK_WITH)) {
- expect(J, '(');
+ if (jsP_accept(J, TK_WITH)) {
+ jsP_expect(J, '(');
a = expression(J, 0);
- expect(J, ')');
+ jsP_expect(J, ')');
b = statement(J);
return STM2(WITH, a, b);
}
- if (accept(J, TK_SWITCH)) {
- expect(J, '(');
+ if (jsP_accept(J, TK_SWITCH)) {
+ jsP_expect(J, '(');
a = expression(J, 0);
- expect(J, ')');
- expect(J, '{');
+ jsP_expect(J, ')');
+ jsP_expect(J, '{');
b = caselist(J);
- expect(J, '}');
+ jsP_expect(J, '}');
return STM2(SWITCH, a, b);
}
- if (accept(J, TK_THROW)) {
+ if (jsP_accept(J, TK_THROW)) {
a = expression(J, 0);
semicolon(J);
return STM1(THROW, a);
}
- if (accept(J, TK_TRY)) {
+ if (jsP_accept(J, TK_TRY)) {
a = block(J);
b = c = d = NULL;
- if (accept(J, TK_CATCH)) {
- expect(J, '(');
+ if (jsP_accept(J, TK_CATCH)) {
+ jsP_expect(J, '(');
b = identifier(J);
- expect(J, ')');
+ jsP_expect(J, ')');
c = block(J);
}
- if (accept(J, TK_FINALLY)) {
+ if (jsP_accept(J, TK_FINALLY)) {
d = block(J);
}
if (!b && !d)
- jsP_error(J, "unexpected token in try: %s (expected 'catch' or 'finally')", TOKSTR);
+ jsP_error(J, "unexpected token in try: %s (expected 'catch' or 'finally')", jsY_tokenstring(J->lookahead));
return STM4(TRY, a, b, c, d);
}
- if (accept(J, TK_DEBUGGER)) {
+ if (jsP_accept(J, TK_DEBUGGER)) {
semicolon(J);
return STM0(DEBUGGER);
}
- if (accept(J, TK_FUNCTION)) {
+ if (jsP_accept(J, TK_FUNCTION)) {
jsP_warning(J, "function statements are not standard");
return funstm(J);
}
@@ -827,7 +813,7 @@
/* labelled statement or expression statement */
if (J->lookahead == TK_IDENTIFIER) {
a = expression(J, 0);
- if (a->type == EXP_IDENTIFIER && accept(J, ':')) {
+ if (a->type == EXP_IDENTIFIER && jsP_accept(J, ':')) {
a->type = AST_IDENTIFIER;
b = statement(J);
return STM2(LABEL, a, b);
@@ -846,7 +832,7 @@
static js_Ast *scriptelement(js_State *J)
{
- if (accept(J, TK_FUNCTION))
+ if (jsP_accept(J, TK_FUNCTION))
return fundec(J);
return statement(J);
}
@@ -865,9 +851,9 @@
static js_Ast *funbody(js_State *J)
{
js_Ast *a;
- expect(J, '{');
+ jsP_expect(J, '{');
a = script(J, '}');
- expect(J, '}');
+ jsP_expect(J, '}');
return a;
}
@@ -951,7 +937,7 @@
js_Ast *p;
jsY_initlex(J, filename, source);
- next(J);
+ jsP_next(J);
p = script(J, 0);
if (p)
jsP_foldconst(p);
@@ -964,7 +950,7 @@
js_Ast *p = NULL;
if (params) {
jsY_initlex(J, filename, params);
- next(J);
+ jsP_next(J);
p = parameters(J);
}
return EXP3(FUN, NULL, p, jsP_parse(J, filename, body));