hedn-0.1.5.2: EDN parsing and encoding

Safe HaskellNone

Data.EDN

Contents

Synopsis

Core EDN types

data Value Source

A "raw" EDN value represented as a Haskell value.

Instances

Eq Value 
Ord Value 
Show Value 
IsString Value

Strings starting with ":" will become keywords.

FromEDN Value 
FromEDN TaggedValue 
ToEDN Value 
ToEDN TaggedValue 
IsString (Tagged Value)

Strings will become an tagless EDN strings.

data Tagged a Source

Abstract namespaced tag.

Constructors

NoTag !a 
Tagged !a !ByteString !ByteString 

Instances

Functor Tagged 
FromEDN TaggedValue 
ToEDN TaggedValue 
Eq a => Eq (Tagged a) 
(Eq (Tagged a), Ord a) => Ord (Tagged a) 
Show a => Show (Tagged a) 
IsString (Tagged Value)

Strings will become an tagless EDN strings.

FromEDN a => FromEDN (Tagged a) 
ToEDN a => ToEDN (Tagged a) 

Type conversion

class ToEDN a whereSource

Methods

toEDN :: a -> TaggedValueSource

Instances

fromEDN :: FromEDN a => TaggedValue -> Result aSource

Convert a value from TaggedValue, failing if the types do not match.

fromEDNv :: FromEDN a => Value -> Result aSource

Convert a value from Value, failing if the types do not match.

(.:) :: (Show k, ToEDN k, FromEDN a) => EDNMap -> k -> Parser aSource

Retrieve the value associated with the given key of an EDNMap. The result is empty if the key is not present or the value cannot be converted to the desired type.

This accessor is appropriate if the key and value must be present in an object for it to be valid. If the key and value are optional, use '(.:?)' instead.

(.:?) :: (ToEDN k, FromEDN a) => EDNMap -> k -> Parser (Maybe a)Source

Retrieve the value associated with the given key of an EDNMap. The result is Nothing if the key is not present, or empty if the value cannot be converted to the desired type.

This accessor is most useful if the key and value can be absent from an object without affecting its validity. If the key and value are mandatory, use '(.:)' instead.

Tag manipulation

setTag :: ByteString -> ByteString -> Tagged a -> Tagged aSource

Replace a tag on a Tagged value.

getTag :: TaggedValue -> (ByteString, ByteString)Source

Extract namespace and tag from a tagged container. Will be a pair of empty for tagless containers.

stripTag :: Tagged a -> aSource

Extract bare value from a tagged or tagless container.

Constructors

tag :: ByteString -> ByteString -> a -> Tagged aSource

Attach a namespaced tag to a value.

notag :: a -> Tagged aSource

Wrap a value into tagless container.

Basic values

nil :: TaggedValueSource

Basic EDN nil.

bool :: Bool -> TaggedValueSource

Basic EDN boolean.

true :: TaggedValueSource

Const EDN True.

false :: TaggedValueSource

Const EDN False.

char :: Char -> TaggedValueSource

Basic EDN character.

string :: Text -> TaggedValueSource

Basic EDN string.

symbol :: ByteString -> TaggedValueSource

"Bare" symbol.

symbolNS :: ByteString -> ByteString -> TaggedValueSource

A namespaced symbol.

keyword :: ByteString -> TaggedValueSource

Basic EDN keyword.

integer :: Integer -> TaggedValueSource

Basic EDN integer.

floating :: Double -> TaggedValueSource

Basic EDN fp number.

Containers

makeList :: [TaggedValue] -> ValueSource

Create an EDN List from a Value list wrapping them into empty tags.

makeVec :: [TaggedValue] -> ValueSource

Create an EDN Vector from a TaggedValue list.

makeSet :: [TaggedValue] -> ValueSource

Create an EDN Set from a TaggedValue list.

makeMap :: [Pair] -> ValueSource

Create an EDN Map from a assoc list with untagged keys and tagged values.

(.=) :: ByteString -> TaggedValue -> PairSource

Construct a Pair from a key (as EDN keyword) and a value.

Encoding

encode :: TaggedValue -> ByteStringSource

Serialize a EDN value as a lazy ByteString.

fromValue :: Value -> BuilderSource

Encode a raw EDN value to a Builder.

fromTagged :: TaggedValue -> BuilderSource

Encode a Tagged EDN value to a Builder.

Parsing

decode :: ByteString -> Maybe TaggedValueSource

Decode a lazy ByteString into a TaggedValue. If fails due to incomplete or invalid input, Nothing is returned.

parseValue :: Parser ValueSource

Parse a "raw" EDN value into a Value.

parseTagged :: Parser TaggedValueSource

Parse a probably tagged EDN value into a TaggedValue.

data Result a Source

The result of running a Parser.

Constructors

Error String 
Success a