选择一个Haskell解析器 [英] Choosing a Haskell parser

查看:83
本文介绍了选择一个Haskell解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有许多开源解析器实现可用给我们Haskell。 Parsec 似乎是文本解析的标准, attoparsec 似乎是二进制解析的流行选择,但除此之外我不太了解。您选择解析器实现时是否遵循特定的决策树?你有没有对图书馆的长处或弱点有所了解?

$有几种不错的选择。 b
$ b

对于字符串类型的轻量级解析:



对于打包的字符串解析,例如 HTTP头





对于实际的二进制数据,大多数人使用以下两种方法之一:


  • 二进制 - 用于懒惰二进制解析

  • 麦片 - 用于严格的二进制解析



问自己的主要问题是底层字符串类型是什么?





该决定主要决定您将使用哪个解析器工具集。



问的第二个问题是:我是否已经有了数据类型的语法?如果是这样,我可以使用快乐





显然,对于自定义数据类型, :


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:

  • binary -- for lazy binary parsing
  • cereal -- for strict binary parsing

The main question to ask yourself is what is the underlying string type?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆