Subscribed unsubscribe Subscribe Subscribe

quoteされた文字列用lexer

Haskell

quoteされた文字列(文字列リテラル)用のlexerメモ。Parsec 3で。

tQuoted :: Stream s m Char => ParsecT s u m TokenType
tQuoted = lexeme $ Quoted <$> between (char '"') (char '"') (many quotedChar)
  where quotedChar = try escapedQ <|> C.satisfy (/= '"')
        escapedQ   = string "\\\"" >> return '"'
> parseTest tQuoted "\"hoge \\\"fuga\\\"\""                                                      
Quoted "hoge \"fuga\""