Code Monkey home page Code Monkey logo

peggy's 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

peggy's People

Contributors

tanakh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peggy's Issues

Allow rule identifiers to begin with underscore

I'm attempting to automatically convert a large PEG grammar and it has rules that begin with upper case characters. As a work-around I'd like to prefix them with an underscore, but Peggy doesn't currently permit this.

Allow semantically defined/custom predicates

Maybe there is already a better way to do this, but it would be useful to be able to be able to make a rule not match in the semantic expression; that is, to force a rule failure based on running some Haskell code.

Can't install the library

Hi there I'm trying to install the library but I can't find it. here is the result:

`cabal install Peggy
cabal.exe: Unknown package "Peggy". Did you mean any of the following?

  • peggy
    `

After changing it:

cabal install peggy Resolving dependencies... cabal.exe: Could not resolve dependencies: [__0] trying: peggy-0.3.2 (user goal) [__1] next goal: template-haskell (dependency of peggy) [__1] rejecting: template-haskell-2.17.0.0/installed-2.17.0.0 (conflict: peggy => template-haskell>=2.5 && <2.9) [__1] skipping: template-haskell-2.17.0.0, template-haskell-2.16.0.0, template-haskell-2.15.0.0, template-haskell-2.14.0.0, template-haskell-2.13.0.0, template-haskell-2.12.0.0, template-haskell-2.11.1.0, template-haskell-2.11.0.0, template-haskell-2.10.0.0, template-haskell-2.9.0.0 (has the same characteristics that caused the previous version to fail: excluded by constraint '>=2.5 && <2.9' from 'peggy') [__1] rejecting: template-haskell-2.8.0.0, template-haskell-2.7.0.0, template-haskell-2.6.0.0, template-haskell-2.5.0.0, template-haskell-2.4.0.1, template-haskell-2.4.0.0, template-haskell-2.3.0.1, template-haskell-2.3.0.0, template-haskell-2.2.0.0 (constraint from non-upgradeable package requires installed instance) [__1] fail (backjumping, conflict set: peggy, template-haskell) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: template-haskell, peggy

I'm using Windows 10 and here is my cabal version:
cabal --version cabal-install version 3.4.0.0 compiled using version 3.4.0.0 of the Cabal library

Adaptation of new GHC version

I'd like to use Peggy very much. But GHC 7.10.x or 8.x doesn't seem to be supported. I was wondering if you would adapt Peggy to GHC 7.10.x or 8.x.

Allow more customization of tokens

This looks like a terrific library, and I am curious to explore using it to speed up the kind of textual parsing I do in pandoc. (I already have a peg grammar for markdown, from my peg-markdown and lunamark projects.)

However, the implicit tokenization (ignoring whitespace) makes this impossible.

Is it possible to provide more flexibility in defining tokens? For example, to allow treating each character as a token? A markdown parser, for example, needs to keep track of whitespace. I tried defining space as &., but that caused a stack overflow, of course.

It would be great if we could pass a custom tokenizer to the peggy function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.