The sexp package

[Tags: gpl, library, program]

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


[Skip to ReadMe]

Properties

Versions0.5, 0.6, 0.7
Change logNone available
Dependenciesattoparsec, base (>=4.4 && <5), bytestring, cmdargs, containers, dlist, ghc-prim, mtl, sexp, vector [details]
LicenseGPL-3
AuthorAlexandru Scvortov <scvalex@gmail.com>
Maintainerscvalex@gmail.com
Stabilityexperimental
CategoryLanguage, Parsing
Home pagehttps://github.com/scvalex/sexp
Source repositoryhead: git clone https://github.com/scvalex/sexp.git
Executablessexp
UploadedTue Feb 26 14:57:52 UTC 2013 by AlexandruScvortov
DistributionsNixOS:0.7
Downloads723 total (51 in last 30 days)
Votes
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for sexp-0.7

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