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

Safe HaskellNone

Data.Sexp

Contents

Description

S-Expressions are represented by Sexp. Conversion to and from arbitrary types is done through Sexpable.

The encoding and decoding functions from Sexpable, toSexp, and fromSexp all have Generic default implementations. So, if your data-type has a Generic instance (which you can automatically get with the DeriveGeneric GHC extension), it also has a Sexpable instance:

 {--}

data MyType = Foo { unFoo :: Int }
             deriving ( Generic )

instance Sexpable MyType
   -- the default implementation uses the Generic representation of MyType

If you want a specific encoding for your type, just fill in the Sexpable instance methods:

 {--}

import Control.Applicative ( ($) )

data MyType = Foo { unFoo :: Int }

instance Sexpable MyType where
     toSexp (Foo x) = List [Atom this, Atom is, toSexp x]

fromSexp (List [Atom this, Atom is, s]) = Foo $ fromSexp s
     fromSexp _                                  = fail invalid MyType sexp

Thank you, aeson, for the model code for this module.

Synopsis

S-Expressions

data Sexp Source

A ByteString-based S-Expression. Conceptually, a Sexp is either an single atom represented by a ByteString, or a list of Sexp.

Constructors

List [Sexp] 
Atom ByteString 

Helpers