使用 FParsec 解析方法参数
我正在尝试使用 FParsec 实现方法参数解析器。
我想知道 FParsec 本身是否有一些已经实现的功能可以帮助我实现此目的?我问这个问题是因为 FParsec 在处理运算符优先级时提供了工具,所以可能也有一些东西可以解决这个问题。
解析左大括号和右大括号非常简单。令人头痛的是处理以下可能发生的 3 种情况:
方法参数可以由:
- 无参数、
- 一个参数、
- 多个参数(所有参数均以逗号分隔)组成。请记住,最后一个参数前面不能有逗号!
我已经有了一些关于如何自己实现这一点的线索,以防没有任何内置功能,即使用 <|>运算符和流复制,但如果可能的话,我想远离那种低级的东西。
I am trying to implement a method arguments parser with FParsec.
I was wondering if there is some already implemented feature in FParsec itself that'd aid me on this purpose? I ask this as FParsec provides tooling when dealing with operator precedence, so there might be something for this too.
Parsing the opening and closing braces is pretty straight-forward. The headache lies in dealing with the following 3 cases that can happen:
Method arguments can consist of:
- no arguments,
- one argument,
- several arguments (all comma separated). keep in mind the last argument cannot be preceded by a comma!
I already have some clues on how to implement this by myself in case there is not any built-in feature, namely with the <|> operator and stream copying, but I'd like to stay away from that kind of low level stuff if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您想使用
sepBy
。由 devoured_elysium 编辑:
上面的代码虽然不能编译,但是正确的。我将在这里发布我的编译版本,这样如果有人只是想尝试一下代码,他们就可以做到。
I believe you want to use
sepBy
.Edited by devoured_elysium:
The above code is correct although it doesn't compile. I'll post here my compiling version, so that if anyone just wants to try out the code without further ado, they can do it.