Fix parser bugs.

This commit is contained in:
Tor Andersson
2014-01-11 18:11:23 +01:00
parent d9588c2c98
commit 88abe2c38c
4 changed files with 26 additions and 23 deletions
+2
View File
@@ -1,2 +1,4 @@
build
tests
specs
js
+1 -1
View File
@@ -441,7 +441,7 @@ static void pstm(int d, js_Ast *stm)
case STM_WITH:
ps("with ("); pexp(d, stm->a); ps(")\n");
pblock(d, stm->b);
pstm(d, stm->b);
break;
case STM_SWITCH:
+1 -1
View File
@@ -6,7 +6,7 @@ static int jsP_loadstring(js_State *J, const char *filename, const char *source)
js_Ast *prog = jsP_parse(J, filename, source);
if (prog) {
jsP_optimize(J, prog);
jsP_dumpsyntax(J, prog);
// jsP_dumpsyntax(J, prog);
jsP_dumplist(J, prog);
jsP_freeparse(J);
return 0;
+22 -21
View File
@@ -170,26 +170,26 @@ static js_Ast *propassign(js_State *J)
{
js_Ast *name, *value, *arg, *body;
if (J->lookahead == TK_IDENTIFIER && !strcmp(J->text, "get")) {
next(J);
name = propname(J);
expect(J, '(');
expect(J, ')');
body = funcbody(J);
return EXP2(PROP_GET, name, body);
}
if (J->lookahead == TK_IDENTIFIER && !strcmp(J->text, "set")) {
next(J);
name = propname(J);
expect(J, '(');
arg = identifier(J);
expect(J, ')');
body = funcbody(J);
return EXP3(PROP_SET, name, arg, body);
}
name = propname(J);
if (J->lookahead != ':' && name->type == AST_IDENTIFIER) {
if (!strcmp(name->string, "get")) {
name = propname(J);
expect(J, '(');
expect(J, ')');
body = funcbody(J);
return EXP2(PROP_GET, name, body);
}
if (!strcmp(name->string, "set")) {
name = propname(J);
expect(J, '(');
arg = identifier(J);
expect(J, ')');
body = funcbody(J);
return EXP3(PROP_SET, name, arg, body);
}
}
expect(J, ':');
value = assignment(J, 0);
return EXP2(PROP_VAL, name, value);
@@ -574,9 +574,10 @@ static js_Ast *forstatement(js_State *J)
return NULL;
}
if (J->lookahead != ';') {
if (J->lookahead != ';')
a = expression(J, 1);
}
else
a = NULL;
if (accept(J, ';')) {
b = forexpression(J, ';');
c = forexpression(J, ')');