Здравствуйте.
Написан один модуль примерно в таком стиле:
import Text.Parsec
import Text.Parsec.ByteString
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BS (pack, unpack, concat, singleton, append, cons)
import Control.Applicative ( (<$>), (<*), (*>), (<*>) )
import Data.Char (chr)
--------------
--- Syntax ---
--------------
-- Where any quoted-pair appears, it is to be interpreted as the
-- character alone. That is to say, the "\" character that appears as
-- part of a quoted-pair is semantically "invisible".
quotedPair :: Parser ByteString
quotedPair = BS.cons '\\' <$> (char '\\' *> (vchar <|> wsp <|> obsQp))
---------------------------
--- Folding White Space ---
--- and comments ---
---------------------------
-- Folding White Space
fws :: Parser ByteString
fws = try (optional (wspMany >> crlf) >> wspMany1) <|> obsFws
-- Printable US-ASCII
-- characters not including
-- "(", ")", or "\"
ctext :: Parser ByteString
ctext = BS.singleton <$> ranges [[33..39],[42..91],[93..126]] <|> obsCtext
ccontent :: Parser ByteString
ccontent = ctext <|> quotedPair <|> comment
comment :: Parser ByteString
comment = BS.concat <$> (between (char '(') (char ')') $
many (optional fws *> ccontent) <* optional fws) <?> "comment"
-- comments and folding white space
cfws :: Parser ByteString
cfws = BS.concat <$>
(try (many1 (optional fws *> comment)) <* optional fws) <|>
fws
-----------------------------
--- Simple Lexical Tokens ---
-----------------------------
-- white space
-- from RFC 5234
wsp :: Parser ByteString
wsp = BS.singleton <$> (char ' ' <|> char '\t') <?> "space or tab"
-- Internet standard newline
-- from RFC 5234
crlf :: Parser ByteString
crlf = (do
cr
lf
return $ BS.pack "\r\n") <?> "CRLF"
…and so on
Повсевместно приходится использовать преобразования типа singleton, pack и т.п. Есть мнение, что это добавляет оверхед.
Есть ли иной способ приготовить Parsec для получения максимальной производительности при обработке ByteString'ов?