尝试解析{asdc,456,ghji,abc}
并运行
run specialListParser "{asdc,456,ghji,abc}"
解析器失败并带有
错误发生在输入流的末尾 期待:任何不在',',','或'}'中的字符
我根据此answer:
定义了我的解析器let str : Parser<_> = many1Chars (noneOf ",")
let comma = pstring ","
let listParser = sepBy str comma
let specialListParser = between (pstring "{") (pstring "}") listParser
我错过了什么?
答案 0 :(得分:5)
您的str
解析器看起来正在消耗最终}
,因此between
永远不会看到它。将您的str
解析器更改为many1Chars (noneOf ",}")
,它应该可以正常工作。
或者,noneOf [','; '}']
也可以使用,并且可能更明确地表达您的意图。