具有自定义标记数据类型的 parsec-3.1.0
parsec-3.1.0 ( http://hackage.haskell.org/package/parsec- 3.1.0) 适用于任何令牌类型。但是,有一些组合器(例如 Text.Parsec.Char.satisfy)仅为 Char 数据类型定义。似乎没有更通用的对应物可用。
我应该定义自己的版本还是我错过了什么?
也许 Haskell 中有不同的解析器库允许:
- 自定义令牌类型
- 自定义解析器状态(我需要解析有状态格式 - Wavefront OBJ)
parsec-3.1.0 ( http://hackage.haskell.org/package/parsec-3.1.0 )
works with any token type. However there are combinators like Text.Parsec.Char.satisfy that are only defined for Char datatype. There doesn't seem to be any more general counterpart available.
Should I define my own versions or did I miss something?
Perhaps there are different parser libraries in Haskell that allows:
- custom token types
- custom parser state (I need to parse stateful format - Wavefront OBJ)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
oneOf
、noneOf
和anyChar
的通用版本可以根据通用的satisfy
构建,非常简单:可能看起来这些概括似乎缺失,但您会注意到这里的这些概括对类型
t
做出了某些假设,但对于某人的令牌类型来说可能并不正确。它被假定为Show
和Eq
的实例,但我可以想象它们以除show
之外的其他方式显示的令牌类型,并且令牌类中的成员资格可以通过==
和elem
之外的某些方法来实现。最后,一旦您的令牌类型不再是
Char
,您选择如何表示位置并因此更新它,在很大程度上取决于您对令牌和流的表示。因此,我可以理解为什么不存在更通用的形式。
Generalized versions of
oneOf
,noneOf
, andanyChar
can be built out of a generalizedsatisfy
, easily enough:It might seem that the generalization of these seems missing, but you'll notice that these generalizations here make certain assumptions about the type
t
that may not be true for someone's token type. It is assumed to be an instance ofShow
andEq
, yet I can imagine token types for which they are displayed some other way thanshow
, and that membership in a class of tokens might be achieved via some method other than==
andelem
.Lastly, once your token type is no longer a
Char
, how you choose to represent position, and thus updated it, is highly dependent on your representation of tokens and streams.Hence, I can see why a more generalized form doesn't exist.