我想在我的 attoparsec 解析器中进行一些跟踪/调试。这是最小的 [not] 工作示例:
import Data.Text as T
import Data.Attoparsec.Text
import Data.Attoparsec.Combinator
import Control.Applicative ((<*), (*>))
parseSentences :: Parser [T.Text]
parseSentences = many1 $ takeWhile1 (/= '.') <* char '.' <* skipSpace
parser :: Parser [T.Text]
parser = do
stuff <- parseSentences
-- putStrLn $ "Got stuff: " ++ show stuff
tail <- takeText
-- putStrLn $ "Got tail: " ++ show tail
return $ stuff ++ [tail, T.pack "more stuff"]
main = do
let input = T.pack "sample. example. bang"
print $ parseOnly parser input
为了在解析器中使用 IO 操作,我必须做什么?