sexp: S-Expression parsing/printing made fun and easy

[ gpl, language, library, parsing, program ] [ Propose Tags ]

See the README.md file and the homepage for details.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.5, 0.6, 0.7
Dependencies attoparsec, base (>=4.4 && <5), bytestring, cmdargs, containers, dlist, ghc-prim, mtl, sexp, vector [details]
License GPL-3.0-only
Author Alexandru Scvortov <scvalex@gmail.com>
Maintainer scvalex@gmail.com
Category Language, Parsing
Home page https://github.com/scvalex/sexp
Source repo head: git clone https://github.com/scvalex/sexp.git
Uploaded by AlexandruScvortov at 2013-02-26T14:57:52Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables sexp
Downloads 2739 total (10 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 sexp-0.7

[back to package description]

sexp

S-Expression parsing/printing made fun and easy

Usage

sexp provides an S-expression data-type, and printers and parsers that work on all data-types that have Generic instances (so, everything you're ever likely to define yourself).

In order to encode/decode a custom data-type with sexp, 1) add a Generic instance for it, and 2) add an empty Sexpable instance for it. The default implementation of Sexpable's toSexp and fromSexp uses the Generic representation of the data-type to encode and decode it.

In order to print a Sexp, use printHum (for human-friendly output), or printMach (for human-unfriendly output). In order to parse a Sexp, use parse and friends.

See the documentation on Hackage for details.

% ghci
GHCi, version 7.6.2: http://www.haskell.org/ghc/  :? for help

λ > :set -XDeriveGeneric

λ > import Language.Sexp

λ > import GHC.Generics

λ > data MyType = Foo { unFoo :: Int, getBar :: Double } deriving ( Show, Generic )

λ > instance Sexpable MyType

λ > toSexp (Foo 23 42.0)
List [Atom "Foo",List [List [Atom "unFoo",Atom "23"],List [Atom "getBar",Atom "42.0"]]]

λ > printMach (toSexp (Foo 23 42.0))
"(Foo ((unFoo 23) (getBar \"42.0\")))"

λ > parseExn (printMach (toSexp (Foo 23 42.0)))
[List [Atom "Foo",List [List [Atom "unFoo",Atom "23"],List [Atom "getBar",Atom "42.0"]]]]

λ > fromSexp (head (parseExn (printMach (toSexp (Foo 23 42.0))))) :: Maybe MyType
Just (Foo {unFoo = 23, getBar = 42.0})

Installation

This package is on Hackage. To install it, run:

cabal update
cabal install sexp