| Safe Haskell | None |
|---|
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.
- data Sexp
- = List [Sexp]
- | Atom ByteString
- class Sexpable a where
- escape :: ByteString -> ByteString
- unescape :: ByteString -> ByteString
S-Expressions
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 |
Instances
| Sexpable Bool | |
| Sexpable Char | |
| Sexpable Double | |
| Sexpable Float | |
| Sexpable Int | |
| Sexpable Integer | |
| Sexpable String | |
| Sexpable () | |
| Sexpable ByteString | |
| Sexpable ByteString | |
| Sexpable Sexp | |
| Sexpable a => Sexpable [a] | |
| Sexpable a => Sexpable (Maybe a) | |
| Sexpable v => Sexpable (IntMap v) | |
| (Sexpable a, Ord a) => Sexpable (Set a) | |
| (Sexpable a, Sexpable b) => Sexpable (Either a b) | |
| (Sexpable a, Sexpable b) => Sexpable (a, b) | |
| (Sexpable k, Sexpable v, Ord k) => Sexpable (Map k v) | |
| (Sexpable a, Sexpable b, Sexpable c) => Sexpable (a, b, c) | |
| (Sexpable a, Sexpable b, Sexpable c, Sexpable d) => Sexpable (a, b, c, d) | |
| (Sexpable a, Sexpable b, Sexpable c, Sexpable d, Sexpable e) => Sexpable (a, b, c, d, e) |
Helpers
escape :: ByteString -> ByteStringSource
unescape :: ByteString -> ByteStringSource
The inverse of escape.