选择一个Haskell解析器 [英] Choosing a Haskell parser
问题描述
有许多开源解析器实现可用给我们Haskell。 Parsec 似乎是文本解析的标准, attoparsec 似乎是二进制解析的流行选择,但除此之外我不太了解。您选择解析器实现时是否遵循特定的决策树?你有没有对图书馆的长处或弱点有所了解?
$有几种不错的选择。 b$ b
对于字符串类型的轻量级解析:
对于打包的字符串解析,例如 HTTP头。
对于实际的二进制数据,大多数人使用以下两种方法之一:
问自己的主要问题是底层字符串类型是什么?
- 字符串?
- bytestring (strict)?
- bytestring (lazy)?
- unicode text
该决定主要决定您将使用哪个解析器工具集。
问的第二个问题是:我是否已经有了数据类型的语法?如果是这样,我可以使用快乐
显然,对于自定义数据类型, :
There are many open sourced parser implementations available to us in Haskell. Parsec seems to be the standard for text parsing and attoparsec seems to be a popular choice for binary parsing but I don't know much beyond that. Is there a particular decision tree that you follow for choosing a parser implementation? Have you learned anything interesting about the strengths or weaknesses of the libraries?
You have several good options.
For lightweight parsing of String types:
For packed bytestring parsing, e.g. of HTTP headers.
For actual binary data most people use either:
The main question to ask yourself is what is the underlying string type?
- String?
- bytestring (strict)?
- bytestring (lazy)?
- unicode text
That decision largely determines which parser toolset you'll use.
The second question to ask is: do I already have a grammar for the data type? If so, I can just use happy
And obviously for custom data types there are a variety of good existing parsers:
这篇关于选择一个Haskell解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!