Coder Social home page Coder Social logo

parsec's Introduction

Parsec

A monadic parser combinator library, written by Daan Leijen. Parsec is designed from scratch as an industrial-strength parser library. It is simple, safe, well documented, has extensive libraries, good error messages, and is fast.

Some links:

By analyzing Parsec's reverse dependencies on Hackage we can find open source project that make use of Parsec. For example bibtex, ConfigFile, csv and hjson.

Getting started

This requires a working version of cabal and ghci, which are part of any modern installation of Haskell, such as Haskell Platform.

First install Parsec.

cabal install parsec

Below we show how a very simple parser that tests matching parentheses was made from GHCI (the interactive GHC environment), which we started with the ghci command).

Prelude> :m +Text.Parsec
Prelude Text.Parsec> let parenSet = char '(' >> many parenSet >> char ')'
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package mtl-2.1.3.1 ... linking ... done.
Loading package text-1.1.1.3 ... linking ... done.
Loading package parsec-3.1.5 ... linking ... done.
Prelude Text.Parsec> let parens = (many parenSet >> eof) <|> eof
Prelude Text.Parsec> parse parens "" "()"
Right ()
Prelude Text.Parsec> parse parens "" "()(())"
Right ()
Prelude Text.Parsec> parse parens "" "("
Left (line 1, column 2):
unexpected end of input
expecting "(" or ")"

The Right () results indicate successes: the parentheses matched. The Left [...] result indicates a parse failure, and is detailed with an error message.

For a more thorough introduction to Parsec we recommend the links at the top of this README file.

Contributing

Issues (bugs, feature requests or otherwise feedback) may be reported in the Github issue tracker for this project.

Pull-requests are also welcome.

License

See the LICENSE file in the repository.

parsec's People

Contributors

aslatter avatar bjornbm avatar bos avatar creswick avatar daniel-diaz avatar derekelkins avatar esg avatar redneb avatar ret avatar slava-sh avatar unkindpartition avatar

Watchers

 avatar  avatar  avatar

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.