From af504350c79a68f3e36b3e9efdcd29a24ace5859 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 11 Sep 2024 10:01:30 +0100 Subject: [PATCH] further improvements to conv-words.sml, escaping chars when necessary, as we may generate an invalid .sml file otherwise --- bench/conv-words.sml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bench/conv-words.sml b/bench/conv-words.sml index 5bd2f6b..ae1ba68 100644 --- a/bench/conv-words.sml +++ b/bench/conv-words.sml @@ -6,7 +6,7 @@ val outIO = TextIO.openOut "words.sml" fun consWordChrs (wordChrs, acc) = case wordChrs of [] => acc - | _ => (String.implode wordChrs) :: acc + | _ => (String.concat wordChrs) :: acc fun helpTokeniseLine (pos, wordChrs, line, acc) = if pos < 0 then @@ -14,9 +14,13 @@ fun helpTokeniseLine (pos, wordChrs, line, acc) = else let val chr = String.sub (line, pos) + (* using Char.toString is necessary because it escapes double-quotes. + * Without escaping, there's a chance we will produce an invalid .sml file + * *) + val sChr = Char.toString chr in if Char.isPrint chr andalso not (Char.isSpace chr) then - helpTokeniseLine (pos - 1, chr :: wordChrs, line, acc) + helpTokeniseLine (pos - 1, sChr :: wordChrs, line, acc) else helpTokeniseLine (pos - 1, [], line, consWordChrs (wordChrs, acc)) end