1

为已创建的 Attoparsec 解析器的所有匹配项解析大型文本内容(300K+)的最有效方法是什么?

我写了这样一个性能缓慢的代码:

import Data.Either (rights)

findAll :: Parser a -> String -> [a]
findAll parser = rights . map (parseOnly parser . pack) . oneLess where
                        oneLess []           = []
                        oneLess (whole@(_:xs)) = whole : oneLess xs

它适用于字符串,但我认为最好的方法是使用 ByteStrings。

在 "abbabba" 中解析 "abba" 应该只返回一个匹配项 ["abba"],即在匹配项之后继续执行。

4

0 回答 0