Text.ParserCombinators.Parsec 和 Text.Parsec 有什么区别 [英] What's the difference between Text.ParserCombinators.Parsec and Text.Parsec

查看:33
本文介绍了Text.ParserCombinators.Parsec 和 Text.Parsec 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Text
    Text.Parsec
        Text.Parsec.ByteString
            Text.Parsec.ByteString.Lazy
        Text.Parsec.Char
        Text.Parsec.Combinator
        Text.Parsec.Error
        Text.Parsec.Expr
        Text.Parsec.Language
        Text.Parsec.Perm
        Text.Parsec.Pos
        Text.Parsec.Prim
        Text.Parsec.String
        Text.Parsec.Token
    ParserCombinators
        Text.ParserCombinators.Parsec
            Text.ParserCombinators.Parsec.Char
            Text.ParserCombinators.Parsec.Combinator
            Text.ParserCombinators.Parsec.Error
            Text.ParserCombinators.Parsec.Expr
            Text.ParserCombinators.Parsec.Language
            Text.ParserCombinators.Parsec.Perm
            Text.ParserCombinators.Parsec.Pos
            Text.ParserCombinators.Parsec.Prim
            Text.ParserCombinators.Parsec.Token

它们是一样的吗?

推荐答案

目前 Parsec 有两个广泛使用的主要版本:Parsec 2 和秒差距 3.

At the moment there are two widely used major versions of Parsec: Parsec 2 and Parsec 3.

我的建议是简单地使用 Parsec 3 的最新版本.但是如果你想做出认真的选择,继续阅读.

My advice is simply to use the latest release of Parsec 3. But if you want to make a conscientious choice, read on.

Parsec 3 引入了一个 monad 转换器,ParsecT,它可以用来组合与其他一元效应解析.

Parsec 3 introduces a monad transformer, ParsecT, which can be used to combine parsing with other monadic effects.

虽然 Parsec 2 允许您选择令牌类型(这在您想要将词法分析与解析分开),标记总是排列成列表.列表可能不是最有效的存储数据结构大文本.

Although Parsec 2 lets you to choose the token type (which is useful when you want to separate lexical analysis from the parsing), the tokens are always arranged into lists. List may be not the most efficient data structure in which to store large texts.

Parsec 3 可以处理任意——具有类似列表的数据结构界面.您可以定义自己的流,但 Parsec 3 还包括一个流行的基于 ByteString (for Char-based) 的高效流实现解析),通过模块 Text.Parsec.ByteStringText.Parsec.ByteString.Lazy.

Parsec 3 can work with arbitrary streams -- data structures with a list-like interface. You can define your own streams, but Parsec 3 also includes a popular and efficient Stream implementation based on ByteString (for Char-based parsing), exposed through the modules Text.Parsec.ByteString and Text.Parsec.ByteString.Lazy.

Parsec 3 提供的高级功能不是免费的;实施它们需要多种语言扩展.

Advanced features provided by Parsec 3 do not come for free; to implement them several language extensions are required.

两个版本都不是 Haskell-2010(即都使用扩展),但是Parsec 2 使用的扩展比 Parsec 3 少,所以任何给定的编译器都有可能可以编译 Parsec 2 高于 Parsec 3.

Neither of the two versions is Haskell-2010 (i.e. both use extensions), but Parsec 2 uses fewer extensions than Parsec 3, so chances that any given compiler can compile Parsec 2 are higher than those for Parsec 3.

此时两个版本都可以使用 GHC,而 Parsec 2 也是 报告使用 JHC 构建,并作为 JHC 的标准库之一包含在内.

By this time both versions work with GHC, while Parsec 2 is also reported to build with JHC and is included as one of the JHC's standard libraries.

最初(即从 3.0 版本开始)Parsec 3 比Parsec 2. 但是,改进 Parsec 3 性能的工作已经完成,从 3.1 版开始,Parsec 3 仅比 Parsec 2 慢一点(基准:1, 2).

Originally (i.e. as of 3.0 version) Parsec 3 was considerably slower than Parsec 2. However, work on improving Parsec 3 performance has been done, and as of version 3.1 Parsec 3 is only slightly slower than Parsec 2 (benchmarks: 1, 2).

可以重新实现"Parsec 3 中的所有 Parsec 2 API.这兼容层由模块层次结构下的 Parsec 3 包提供Text.ParserCombinators.Parsec(与 Parsec 2 使用的层次结构相同),而新的 Parsec 3 API 在 Text.Parsec 层次结构下可用.

It has been possible to "reimplement" all of the Parsec 2 API in Parsec 3. This compatibility layer is provided by the Parsec 3 package under the module hierarchy Text.ParserCombinators.Parsec (the same hierarchy which is used by Parsec 2), while the new Parsec 3 API is available under the Text.Parsec hierarchy.

这意味着您可以使用 Parsec 3 作为 Parsec 2 的直接替代品.

This means that you can use Parsec 3 as a drop-in replacement for Parsec 2.

这篇关于Text.ParserCombinators.Parsec 和 Text.Parsec 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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