*** parser.y.~1~ Tue Feb 29 02:29:00 2000 --- parser.y Sat Mar 17 20:42:06 2001 *************** *** 1,8 **** /* -------------------------------------------------------------------------- * Hugs parser (included as part of input.c) * ! * Expect 15 shift/reduce conflicts when passing this grammar through yacc, * but don't worry; they should all be resolved in an appropriate manner. * * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the * Yale Haskell Group, and the Oregon Graduate Institute of Science and --- 1,8 ---- /* -------------------------------------------------------------------------- * Hugs parser (included as part of input.c) * ! * Expect 16 shift/reduce conflicts when passing this grammar through yacc, * but don't worry; they should all be resolved in an appropriate manner. * * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the * Yale Haskell Group, and the Oregon Graduate Institute of Science and *************** *** 421,429 **** /*- Class declarations: ---------------------------------------------------*/ topDecl : TCLASS crule fds wherePart {classDefn(intOf($1),$2,$4,$3); sp-=4;} ! | TINSTANCE irule wherePart {instDefn(intOf($1),$2,$3); sp-=3;} | DEFAULT '(' dtypes ')' {defaultDefn(intOf($1),$3); sp-=4;} | TCLASS error {syntaxError("class declaration");} | TINSTANCE error {syntaxError("instance declaration");} | DEFAULT error {syntaxError("default declaration");} --- 421,429 ---- /*- Class declarations: ---------------------------------------------------*/ topDecl : TCLASS crule fds wherePart {classDefn(intOf($1),$2,$4,$3); sp-=4;} ! | TINSTANCE irule iwherePart {instDefn(intOf($1),$2,$3); sp-=3;} | DEFAULT '(' dtypes ')' {defaultDefn(intOf($1),$3); sp-=4;} | TCLASS error {syntaxError("class declaration");} | TINSTANCE error {syntaxError("instance declaration");} | DEFAULT error {syntaxError("default declaration");} *************** *** 611,618 **** --- 611,630 ---- pair($1,ap(RSIGN, ap($4,$3)))));} | pat0 rhs {$$ = gc2(ap(PATBIND,pair($1,$2)));} ; + idecls : '{' idecls0 end {$$ = gc3($2);} + | '{' idecls1 end {$$ = gc3($2);} + ; + idecls0 : /* empty */ {$$ = gc0(NIL);} + | idecls0 ';' {$$ = gc2($1);} + | idecls1 ';' {$$ = gc2($1);} + ; + idecls1 : idecls0 idecl {$$ = gc2(cons($2,$1));} + + idecl : qfunlhs rhs {$$ = gc2(ap(FUNBIND,pair($1,$2)));} + | qvar rhs {$$ = gc2(ap(PATBIND,pair($1,$2)));} + ; funlhs : funlhs0 {$$ = $1;} | funlhs1 {$$ = $1;} | npk {$$ = $1;} ; *************** *** 627,634 **** --- 639,659 ---- | '(' npk ')' apat {$$ = gc4(ap($2,$4));} | var apat {$$ = gc2(ap($1,$2));} | funlhs1 apat {$$ = gc2(ap($1,$2));} ; + qfunlhs : qfunlhs0 {$$ = $1;} + | qfunlhs1 {$$ = $1;} + ; + qfunlhs0 : pat10_vI qvarop pat0 {$$ = gc3(ap2($2,$1,$3));} + | infixPat qvarop pat0 {$$ = gc3(ap2($2,$1,$3));} + | NUMLIT qvarop pat0 {$$ = gc3(ap2($2,$1,$3));} + | var qvarop_mi pat0 {$$ = gc3(ap2($2,$1,$3));} + ; + qfunlhs1 : '(' qfunlhs0 ')' apat {$$ = gc4(ap($2,$4));} + | '(' qfunlhs1 ')' apat {$$ = gc4(ap($2,$4));} + | qvar apat {$$ = gc2(ap($1,$2));} + | qfunlhs1 apat {$$ = gc2(ap($1,$2));} + ; rhs : rhs1 wherePart {$$ = gc2(letrec($2,$1));} | error {syntaxError("declaration");} ; rhs1 : '=' exp {$$ = gc2(pair($1,$2));} *************** *** 642,649 **** --- 667,680 ---- wherePart : /* empty */ {$$ = gc0(NIL);} | WHERE decls {$$ = gc2($2);} ; + /* Body of instance decls, differs from wherePart in that + qualified names can be bound on the LHS. + */ + iwherePart : /* empty */ {$$ = gc0(NIL);} + | WHERE idecls {$$ = gc2($2);} + ; /*- Patterns: -------------------------------------------------------------*/ pat : npk {$$ = $1;} | pat_npk {$$ = $1;} *** static.c.~2~ Sat Mar 3 19:43:08 2001 --- static.c Sat Mar 17 20:41:46 2001 *************** *** 1984,2007 **** String where; /* Check validity of bindings bs */ Class c; /* for class c (or an inst of c) */ List bs; { /* sort into approp. member order */ List nbs = NIL; for (; nonNull(bs); bs=tl(bs)) { Cell b = hd(bs); Cell body = snd(snd(b)); Name mnm; ! if (!isVar(fst(b))) { /* Only allow function bindings */ ERRMSG(rhsLine(snd(body))) "Pattern binding illegal in %s declaration", where EEND; } ! if (isNull(mnm=memberName(c,textOf(fst(b))))) { ERRMSG(rhsLine(snd(hd(body)))) "No member \"%s\" in class \"%s\"", ! textToStr(textOf(fst(b))), textToStr(cclass(c).text) EEND; } snd(b) = body; nbs = numInsert(mfunOf(mnm)-1,b,nbs); --- 1984,2015 ---- String where; /* Check validity of bindings bs */ Class c; /* for class c (or an inst of c) */ List bs; { /* sort into approp. member order */ List nbs = NIL; + Text nm; for (; nonNull(bs); bs=tl(bs)) { Cell b = hd(bs); Cell body = snd(snd(b)); Name mnm; ! if ( !(isVar(fst(b)) || isQVar(fst(b))) ) { /* Only allow function bindings */ ERRMSG(rhsLine(snd(body))) "Pattern binding illegal in %s declaration", where EEND; } + + /* Get at the unqualified name of the method */ + if (isVar(fst(b))) { + nm = textOf(fst(b)); + } else { + nm = qtextOf(fst(b)); + } ! if (isNull(mnm=memberName(c,nm))) { ERRMSG(rhsLine(snd(hd(body)))) "No member \"%s\" in class \"%s\"", ! textToStr(nm), textToStr(cclass(c).text) EEND; } snd(b) = body; nbs = numInsert(mfunOf(mnm)-1,b,nbs); *************** *** 5081,5089 **** Int line = rhsLine(rhs); Cell lhs = fst(snd(d)); Cell v = getHead(lhs); Cell newAlt = pair(getArgs(lhs),rhs); ! if (!isVar(v)) { internal("FUNBIND"); } if (nonNull(lastVar) && textOf(v)==textOf(lastVar)) { if (argCount!=lastArity) { --- 5089,5097 ---- Int line = rhsLine(rhs); Cell lhs = fst(snd(d)); Cell v = getHead(lhs); Cell newAlt = pair(getArgs(lhs),rhs); ! if ( !(isVar(v) || isQVar(v)) ) { internal("FUNBIND"); } if (nonNull(lastVar) && textOf(v)==textOf(lastVar)) { if (argCount!=lastArity) {