Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 FParsec 解析字符串文字。通过“字符串文字”,我的意思是开始和结束引号之间的东西(在我的例子中 - 单引号):
'Please, switch off your mobile phone'
我目前正在做的事情如下:
let string = between (pstring "'") (pstring "'") (manySatisfy isLetter)
但这在第一个字母被消耗后停止。有没有办法让它变得贪婪?
它已经很贪婪了;manySatisfy isLetter从输入流中解析一系列字母。
manySatisfy isLetter
问题是解析器因,or 空格而失败,因为它们不是字母。它可以通过使用来修复:
,
manyChars (noneOf "'")
或更明确地使用:
manySatisfy ((<>) '\'')
反而。