下面的代码输出Right ["1<!>2<!>3"],但我需要Right ["1", "2", "3"]。
import Text.ParserCombinators.Parsec
response = contents :: CharParser () [String]
where
contents = sepBy content contentDelimiter
contentDelimiter = string "<!>"
content = many anyChar
main = do
putStrLn $ show $ parse response "Response" "1<!>2<!>3"
我想这里的问题是解析器在测试分隔符content之前消耗了所有输入。sepBy所以,我的问题是:
我的假设是否正确?如果没有,我犯了什么错误?
对于这样的问题,您会推荐什么解决方案?(使用秒差)
* content必须匹配任何不包含分隔符的字符串。这1<!>2<!>3只是一个例子,它可以是dslkf\n><!>dsf<!>3什么