From 51954c60eadbd919695ab3566ee6730f8d1663f5 Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 5 Oct 2021 13:36:54 +0200 Subject: [PATCH] fix the printer for strings with escape characters --- src/compiler/GF/Grammar/Printer.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/GF/Grammar/Printer.hs b/src/compiler/GF/Grammar/Printer.hs index 475d77f72..18a68dab9 100644 --- a/src/compiler/GF/Grammar/Printer.hs +++ b/src/compiler/GF/Grammar/Printer.hs @@ -35,9 +35,8 @@ import GF.Text.Pretty import Data.Maybe (isNothing) import Data.List (intersperse) import qualified Data.Map as Map ---import qualified Data.IntMap as IntMap ---import qualified Data.Set as Set import qualified Data.Array.IArray as Array +import qualified GHC.Show data TermPrintQual = Terse | Unqualified | Qualified | Internal @@ -289,7 +288,12 @@ ppConstrs = map (\(v,w) -> braces (ppValue Unqualified 0 v <+> "<>" <+> ppValue ppEnv :: Env -> Doc ppEnv e = hcat (map (\(x,t) -> braces (x <> ":=" <> ppValue Unqualified 0 t)) e) -str s = doubleQuotes s +str s = doubleQuotes (pp (foldr showLitChar "" s)) + where + showLitChar c + | c == '"' = showString "\\\"" + | c > '\DEL' = showChar c + | otherwise = GHC.Show.showLitChar c ppDecl q (_,id,typ) | id == identW = ppTerm q 3 typ