# HG changeset patch # User Adam Chlipala # Date 1253983519 14400 # Node ID 815afd323d86a66b42b3b23e7c7a660f81dde4bd # Parent 2cd8c1aa0d3a6bfabda25a07a51230b912a66eaf Whitelisting tags that may be self-closed diff -r 2cd8c1aa0d3a -r 815afd323d86 src/monoize.sml --- a/src/monoize.sml Thu Sep 24 15:45:37 2009 -0400 +++ b/src/monoize.sml Sat Sep 26 12:45:19 2009 -0400 @@ -36,6 +36,19 @@ structure IM = IntBinaryMap structure IS = IntBinarySet +structure SS = BinarySetFn(struct + type ord_key = string + val compare = String.compare + end) + +val singletons = SS.addList (SS.empty, + ["link", + "br", + "p", + "hr", + "input", + "button"]) + val dummyTyp = (L'.TDatatype (0, ref (L'.Enum, [])), E.dummySpan) structure U = MonoUtil @@ -2603,6 +2616,16 @@ loc), fm) end + + fun isSingleton () = + let + val (bef, aft) = Substring.splitl (not o Char.isSpace) (Substring.full tag) + in + SS.member (singletons, if Substring.isEmpty aft then + tag + else + Substring.string bef) + end in case xml of (L.EApp ((L.ECApp ( @@ -2610,7 +2633,7 @@ _), _), _), _), (L.EPrim (Prim.String s), _)), _) => - if CharVector.all Char.isSpace s then + if CharVector.all Char.isSpace s andalso isSingleton () then ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String " />"), loc)), loc), fm) else normal () diff -r 2cd8c1aa0d3a -r 815afd323d86 tests/empties.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/empties.ur Sat Sep 26 12:45:19 2009 -0400 @@ -0,0 +1,4 @@ +fun main () = return +

+
+
diff -r 2cd8c1aa0d3a -r 815afd323d86 tests/empties.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/empties.urp Sat Sep 26 12:45:19 2009 -0400 @@ -0,0 +1,3 @@ +debug + +empties diff -r 2cd8c1aa0d3a -r 815afd323d86 tests/empties.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/empties.urs Sat Sep 26 12:45:19 2009 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page