Skip to content

Commit 93e183a

Browse files
wip better quoted parse
1 parent 4bd1ac6 commit 93e183a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

language-nix/src/Language/Nix/Identifier.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,20 @@ parseQuotedIdentifier = Identifier <$> qstring
109109
where
110110
qstring :: CharParser st tok m String
111111
qstring = do txt <- between (P.char '"') (P.char '"') (many qtext)
112-
return (read ('"' : concat txt ++ ['"']))
112+
return txt
113113

114-
qtext :: CharParser st tok m String
115-
qtext = quotedPair <|> many1 (P.noneOf "\\\"")
114+
qtext :: CharParser st tok m Char
115+
qtext = quotedPair <|> P.noneOf "\\\""
116116

117-
quotedPair :: CharParser st tok m String
117+
quotedPair :: CharParser st tok m Char
118118
quotedPair = do
119-
c1 <- P.char '\\'
120-
c2 <- anyChar
121-
return [c1,c2]
119+
_ <- P.char '\\'
120+
c <- anyChar
121+
return $ case c of
122+
'n' -> '\n'
123+
't' -> '\t'
124+
'r' -> '\r'
125+
_ -> c
122126

123127
-- | Checks whether a given string needs quoting when interpreted as an
124128
-- 'Identifier'.

0 commit comments

Comments
 (0)