From 87e2e610a69b268d10a22a7142a44a2c0afd4799 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 3 Dec 2011 17:25:51 -0500 Subject: Don't crash on invalid URL head terms during Tag --- src/tag.sml | 61 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/tag.sml b/src/tag.sml index a313e0a6..dc648739 100644 --- a/src/tag.sml +++ b/src/tag.sml @@ -65,38 +65,43 @@ fun exp env (e, s) = | _ => (ErrorMsg.errorAt loc ("Invalid " ^ newAttr ^ " expression"); Print.epreface ("Expression", - CorePrint.p_exp CoreEnv.empty eOrig); + CorePrint.p_exp env eOrig); (0, [])) val (f, args) = unravel e - - val (cn, count, tags, newTags) = - case IM.find (tags, f) of - NONE => - (count, count + 1, IM.insert (tags, f, count), - (ek, f, count) :: newTags) - | SOME cn => (cn, count, tags, newTags) - - val (_, _, _, s) = E.lookupENamed env f - - val byTag = case SM.find (byTag, s) of - NONE => SM.insert (byTag, s, (ek, f)) - | SOME (ek', f') => - (if f = f' then - () - else - ErrorMsg.errorAt loc - ("Duplicate HTTP tag " - ^ s); - if ek = ek' then - () - else - both (loc, s); - byTag) - - val e = (EClosure (cn, args), loc) in - (e, (count, tags, byTag, newTags)) + if f = 0 then + (e, (count, tags, byTag, newTags)) + else + let + val (cn, count, tags, newTags) = + case IM.find (tags, f) of + NONE => + (count, count + 1, IM.insert (tags, f, count), + (ek, f, count) :: newTags) + | SOME cn => (cn, count, tags, newTags) + + val (_, _, _, s) = E.lookupENamed env f + + val byTag = case SM.find (byTag, s) of + NONE => SM.insert (byTag, s, (ek, f)) + | SOME (ek', f') => + (if f = f' then + () + else + ErrorMsg.errorAt loc + ("Duplicate HTTP tag " + ^ s); + if ek = ek' then + () + else + both (loc, s); + byTag) + + val e = (EClosure (cn, args), loc) + in + (e, (count, tags, byTag, newTags)) + end end in case e of -- cgit v1.2.3