peggy: The Parser Generator for Haskell

[ bsd3, language, library ] [ Propose Tags ]

The Parser Generator for Haskell http://tanakh.github.com/Peggy


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
build-exampleDisabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.2.0.1, 0.2.1, 0.3.0, 0.3.1, 0.3.1.1, 0.3.2
Dependencies base (>=4 && <5), hashtables (>=1.0 && <1.1), haskell-src-meta (>=0.5), ListLike (>=3.1 && <3.2), monad-control (>=0.3 && <0.4), mtl (>=2.0), peggy, template-haskell (>=2.5 && <2.9) [details]
License BSD-3-Clause
Copyright Copyright (c)2011, Hideyuki Tanaka
Author Hideyuki Tanaka
Maintainer Hideyuki Tanaka <tanaka.hideyuki@gmail.com>
Category Language
Home page http://tanakh.github.com/Peggy
Source repo head: git clone git://github.com/tanakh/Peggy.git
Uploaded by HideyukiTanaka at 2013-01-30T04:52:54Z
Distributions
Reverse Dependencies 4 direct, 1 indirect [details]
Executables peggy-example
Downloads 9105 total (18 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for peggy-0.3.2

[back to package description]

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