ref: 88abe2c38c317c76254773085aa7557ec42fbdaf
parent: d9588c2c985dfe8bd917ae193913efefb3a4a93a
author: Tor Andersson <tor@ccxvii.net>
date: Sat Jan 11 11:31:24 EST 2014
Fix parser bugs.
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
build
+tests
+specs
js
--- a/jsdump.c
+++ b/jsdump.c
@@ -441,7 +441,7 @@
case STM_WITH:
ps("with ("); pexp(d, stm->a); ps(")\n");
- pblock(d, stm->b);
+ pstm(d, stm->b);
break;
case STM_SWITCH:
--- a/jsload.c
+++ b/jsload.c
@@ -6,7 +6,7 @@
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;
--- a/jsparse.c
+++ b/jsparse.c
@@ -170,26 +170,26 @@
{
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);
- }
+ name = propname(J);
- 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);
+ 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);
+ }
}
- name = propname(J);
expect(J, ':');
value = assignment(J, 0);
return EXP2(PROP_VAL, name, value);
@@ -574,9 +574,10 @@
return NULL;
}
- if (J->lookahead != ';') {
+ if (J->lookahead != ';')
a = expression(J, 1);
- }
+ else
+ a = NULL;
if (accept(J, ';')) {
b = forexpression(J, ';');
c = forexpression(J, ')');