• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

tanakh/Peggy: The Parser Generator for Haskell

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

tanakh/Peggy

开源软件地址(OpenSource Url):

https://github.com/tanakh/Peggy

开源编程语言(OpenSource Language):

Haskell 100.0%

开源软件介绍(OpenSource Introduction):

Peggy: A Parser Generator of Parsing Expression Grammer (PEG)

About

This is an yet another parser generator of Parsing Expression Grammer (PEG) which is:

  • Simple
  • Concise
  • Fast
  • Modern

Usage

You can find a recent stable release in Hackage DB. You can install this as following instruction:

$ cabal update
$ cabal install Peggy

Why should you use Peggy?

Haskell has commonly used parser generators, one of them are Alex/Happy. But I think Alex/Happy are not good in these points:

  • Generates regacy codes

Alex uses only too basic libraries. It does not use monad-transformers, iteratee, ListLike, Text, and so on.

  • Tradisional Regexp/CFG based parser

Parsec has no good error recovery.

unnun, kannun...

...

Quick Start

Here is an example of parsing arithmetic expressions.

{-# QuasiQuotes #-}
{-# Language FlexibleContexts #-}

import Text.Peggy

[peggy|
exp :: Double
  = exp "+" fact  { $1 + $2 }
  / exp "-" fact  { $1 - $2 }
  / fact
fact :: Double
  = fact "*" term { $1 * $2 }
  / fact "/" term { $1 / $2 }
  / term
term :: Double
  = "(" exp ")"
  / number
number ::: Double
  = ([1-9][0-9]*) { read $1 }
|]

main :: IO ()
main =
  print . parse exp =<< getContents



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
mrkkrp/req: An HTTP client library发布时间:2022-06-22
下一篇:
sol/markdown-unlit: Literate Haskell support for Markdown发布时间:2022-06-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap