使用 FParsec 解析字符串文字?
我想使用 FParsec 解析字符串文字。我所说的“字符串文字”是指在开始和结束引号之间的东西(在我的例子中
'Please, switch off your mobile phone'
是单引号):我当前正在做的事情如下:
let string = between (pstring "'") (pstring "'") (manySatisfy isLetter)
但这在第一个字母被消耗后停止。有什么办法让它贪心吗?
I would like to parse string literals using FParsec. By "string literals" I mean something between opening and closing quote (in my case -- single quote):
'Please, switch off your mobile phone'
What I am currently doing is the following:
let string = between (pstring "'") (pstring "'") (manySatisfy isLetter)
But this stops after the first letter consumed. Is there any way to make it greedy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它已经很贪婪了;
manySatisfy isLetter
解析输入流中的字母序列。问题是解析器因
、
或空格而失败,因为它们不是字母。 来修复它可以通过使用:或更明确地使用:
。
It's already greedy;
manySatisfy isLetter
parses a sequence of letters from the input stream.The problem is that the parser fails with
,
or spaces since they are not letters. It could be fixed by using:or more explicitly using:
instead.