Fix pretty printing of EscapedNewline

This commit is contained in:
Matthew Pickering 2018-05-06 10:27:10 +00:00
parent b0ed29b3df
commit 34d0552517
2 changed files with 3 additions and 3 deletions

View file

@ -221,7 +221,7 @@ nixString = lexeme (doubleQuoted <+> indented <?> "string")
(Plain <$> ("''" <$ char '\'' <+> "$" <$ char '$')) <+> do
_ <- char '\\'
c <- escapeCode
pure $ if c == '\n'
pure $ if c == 'n'
then EscapedNewline
else Plain $ singleton c

View file

@ -89,7 +89,7 @@ wrapParens op sub
prettyString :: NString NixDoc -> Doc
prettyString (DoubleQuoted parts) = dquotes . hcat . map prettyPart $ parts
where prettyPart (Plain t) = text . concatMap escape . unpack $ t
prettyPart EscapedNewline = text "\n"
prettyPart EscapedNewline = text "''\\n"
prettyPart (Antiquoted r) = text "$" <> braces (withoutParens r)
escape '"' = "\\\""
escape x = maybe [x] (('\\':) . (:[])) $ toEscapeCode x
@ -102,7 +102,7 @@ prettyString (Indented _ parts)
f xs = xs
prettyLine = hcat . map prettyPart
prettyPart (Plain t) = text . unpack . replace "${" "''${" . replace "''" "'''" $ t
prettyPart EscapedNewline = text "\n"
prettyPart EscapedNewline = text "\\n"
prettyPart (Antiquoted r) = text "$" <> braces (withoutParens r)
prettyParams :: Params NixDoc -> Doc