Attoparsec efficient parser for multiple char

53 views Asked by At

If I define

charToText :: Char -> Text
charToText c = pack [c]

anyCharParser :: Parser Text
anyCharParser = mconcat <$> manyTill (charToText <$> anyChar) endOfInput

it seems to me that lifting charToText is inefficient, because for each character matched charToText creates a singleton list to pack it as a Text.

Is there or more efficient way to do it ? For example a Parser Text that matches any single character ?

1

There are 1 answers

0
Li-yao Xia On BEST ANSWER
anyCharParser :: Parser Text
anyCharParser = pack <$> manyTill anyChar endOfInput