descriptive-0.9.4: Self-describing consumers/parsers; forms, cmd-line args, JSON, etc.

Safe Haskell | None
Language | Haskell98

Descriptive.JSON

Contents

- Consumers
- Annotations
- Description

Description

A JSON API which describes itself.

Synopsis

- parse :: Monad m => d -> (a -> StateT s m (Maybe b)) -> Consumer s d m a -> Consumer s d m b
- object :: Monad m => Text -> Consumer Object (Doc d) m a -> Consumer Value (Doc d) m a
- key :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Object (Doc d) m a
- keyMaybe :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Object (Doc d) m (Maybe a)
- array :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Value (Doc d) m (Vector a)
- string :: Monad m => Text -> Consumer Value (Doc d) m Text
- integer :: Monad m => Text -> Consumer Value (Doc d) m Integer
- double :: Monad m => Text -> Consumer Value (Doc d) m Double
- bool :: Monad m => Text -> Consumer Value (Doc d) m Bool
- null :: Monad m => Text -> Consumer Value (Doc d) m ()
- label :: Monad m => d -> Consumer s (Doc d) m a -> Consumer s (Doc d) m a
- data Doc a
  - = Integer !Text
  - | Double !Text
  - | Text !Text
  - | Boolean !Text
  - | Null !Text
  - | Object !Text
  - | Key !Text
  - | Array !Text
  - | Label !a

# Consumers

parse #

Arguments

:: Monad m |
=> d | Description of what it expects.
-> (a -> StateT s m (Maybe b)) | Attempt to parse the value.
-> Consumer s d m a | Consumer to add validation to.
-> Consumer s d m b | A new validating consumer.

Parse from a consumer.

object #

Arguments

:: Monad m |
=> Text | Description of what the object is.
-> Consumer Object (Doc d) m a | An object consumer.
-> Consumer Value (Doc d) m a |

Consume an object.

key #

Arguments

:: Monad m |
=> Text | The key to lookup.
-> Consumer Value (Doc d) m a | A value consumer of the object at the key.
-> Consumer Object (Doc d) m a |

Consume from object at the given key.

keyMaybe #

Arguments

:: Monad m |
=> Text | The key to lookup.
-> Consumer Value (Doc d) m a | A value consumer of the object at the key.
-> Consumer Object (Doc d) m (Maybe a) |

Optionally consume from object at the given key, only if it exists.

array #

Arguments

:: Monad m |
=> Text | Description of this array.
-> Consumer Value (Doc d) m a | Consumer for each element in the array.
-> Consumer Value (Doc d) m (Vector a) |

Consume an array.

string #

Arguments

:: Monad m |
=> Text | Description of what the string is for.
-> Consumer Value (Doc d) m Text |

Consume a string.

integer #

Arguments

:: Monad m |
=> Text | Description of what the integer is for.
-> Consumer Value (Doc d) m Integer |

Consume an integer.

double #

Arguments

:: Monad m |
=> Text | Description of what the double is for.
-> Consumer Value (Doc d) m Double |

Consume an double.

bool #

Arguments

:: Monad m |
=> Text | Description of what the bool is for.
-> Consumer Value (Doc d) m Bool |

Parse a boolean.

null #

Arguments

:: Monad m |
=> Text | What the null is for.
-> Consumer Value (Doc d) m () |

Expect null.

# Annotations

label #

Arguments

:: Monad m |
=> d | Some label.
-> Consumer s (Doc d) m a | A value consumer.
-> Consumer s (Doc d) m a |

Wrap a consumer with a label e.g. a type tag.

# Description

data Doc a #

Description of parseable things.

Constructors

Integer !Text |
Double !Text |
Text !Text |
Boolean !Text |
Null !Text |
Object !Text |
Key !Text |
Array !Text |
Label !a |

Instances

Eq a => Eq (Doc a) # |
Methods (==) :: Doc a -> Doc a -> Bool # (/=) :: Doc a -> Doc a -> Bool #
Data a => Data (Doc a) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Doc a -> c (Doc a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Doc a) # toConstr :: Doc a -> Constr # dataTypeOf :: Doc a -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Doc a)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Doc a)) # gmapT :: (forall b. Data b => b -> b) -> Doc a -> Doc a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Doc a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Doc a -> r # gmapQ :: (forall d. Data d => d -> u) -> Doc a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Doc a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Doc a -> m (Doc a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Doc a -> m (Doc a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Doc a -> m (Doc a) #
Show a => Show (Doc a) # |
Methods showsPrec :: Int -> Doc a -> ShowS # show :: Doc a -> String # showList :: [Doc a] -> ShowS #