From 86cca77cf5f50e7b996949351dc004611ed9518c Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Thu, 24 Nov 2016 20:08:54 +0300 Subject: [PATCH] =?UTF-8?q?Update=20docs=20for=20=E2=80=98charLiteral?= =?UTF-8?q?=E2=80=99=20to=20mention=20=E2=80=98\&=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #154. --- Text/Megaparsec/Lexer.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Text/Megaparsec/Lexer.hs b/Text/Megaparsec/Lexer.hs index e54cc09..ff383d0 100644 --- a/Text/Megaparsec/Lexer.hs +++ b/Text/Megaparsec/Lexer.hs @@ -361,6 +361,14 @@ lineFold sc action = -- string literals: -- -- > stringLiteral = char '"' >> manyTill L.charLiteral (char '"') +-- +-- If you want to write @stringLiteral@ that adheres to the Haskell report +-- though, you'll need to take care of the @\\&@ combination which is not a +-- character, but can be used to separate characters (as in @\"\\291\\&4\"@ +-- which is two characters long): +-- +-- > stringLiteral = catMaybes <$> (char '"' >> manyTill ch (char '"')) +-- > where ch = (Just <$> L.charLiteral) <|> (Nothing <$ string "\\&") charLiteral :: (MonadParsec e s m, Token s ~ Char) => m Char charLiteral = label "literal character" $ do