unparse String/AltString: escape quotes;
authorwenzelm
Tue, 03 Jan 2006 00:06:29 +0100
changeset 18547 d1978038b945
parent 18546 d9b026de8333
child 18548 cb8e8fb9e52d
unparse String/AltString: escape quotes;
src/Pure/Isar/outer_lex.ML
--- a/src/Pure/Isar/outer_lex.ML	Tue Jan 03 00:06:28 2006 +0100
+++ b/src/Pure/Isar/outer_lex.ML	Tue Jan 03 00:06:29 2006 +0100
@@ -150,10 +150,13 @@
   else if x = "" then str_of_kind k
   else str_of_kind k ^ " " ^ quote x;
 
+fun escape q =
+  implode o map (fn s => if s = q orelse s = "\\" then "\\" ^ s else s) o Symbol.explode;
+
 fun unparse (Token (_, (kind, x))) =
   (case kind of
-    String => x |> quote
-  | AltString => x |> enclose "`" "`"
+    String => x |> quote o escape "\""
+  | AltString => x |> enclose "`" "`" o escape "`"
   | Verbatim => x |> enclose "{*" "*}"
   | Comment => x |> enclose "(*" "*)"
   | _ => x);