jordan-0.1.0.0: JSON with Structure
Safe HaskellSafe-Inferred
LanguageHaskell2010

Jordan.FromJSON.ParseInternal

Description

Module containing internal helpers for our parsers.

Synopsis

Documentation

data Permutation parser a Source #

A parser for permutations.

Based on the paper Parsing Permutation Phrases by Arthur Baars, Andres Loh, and S. Doaitse Swierstra.

The source code for Permutations really helped in writing this, although this type is structured differently (and closer to the actual paper). Thank you very much to Alex Washburn!

Constructors

Choice [Branch parser a]

We have multiple options for how to parse further.

Empty a

We have reached the end and only have a single value.

Instances

Instances details
Functor m => Functor (Permutation m) Source # 
Instance details

Defined in Jordan.FromJSON.ParseInternal

Methods

fmap :: (a -> b) -> Permutation m a -> Permutation m b #

(<$) :: a -> Permutation m b -> Permutation m a #

Alternative m => Applicative (Permutation m) Source # 
Instance details

Defined in Jordan.FromJSON.ParseInternal

Methods

pure :: a -> Permutation m a #

(<*>) :: Permutation m (a -> b) -> Permutation m a -> Permutation m b #

liftA2 :: (a -> b -> c) -> Permutation m a -> Permutation m b -> Permutation m c #

(*>) :: Permutation m a -> Permutation m b -> Permutation m b #

(<*) :: Permutation m a -> Permutation m b -> Permutation m a #

data Branch parser a Source #

A branch of a permutation. Permutation parsers work by building up the entire tree of possible parsers, which is efficient in Haskell due to laziness.

Constructors

forall arg. Branch (Permutation parser (arg -> a)) (parser arg) 

Instances

Instances details
Functor m => Functor (Branch m) Source # 
Instance details

Defined in Jordan.FromJSON.ParseInternal

Methods

fmap :: (a -> b) -> Branch m a -> Branch m b #

(<$) :: a -> Branch m b -> Branch m a #

Alternative m => Applicative (Branch m) Source # 
Instance details

Defined in Jordan.FromJSON.ParseInternal

Methods

pure :: a -> Branch m a #

(<*>) :: Branch m (a -> b) -> Branch m a -> Branch m b #

liftA2 :: (a -> b -> c) -> Branch m a -> Branch m b -> Branch m c #

(*>) :: Branch m a -> Branch m b -> Branch m b #

(<*) :: Branch m a -> Branch m b -> Branch m a #

wrapEffect Source #

Arguments

:: forall m a b. Alternative m 
=> m b

Consume a single, "junk" field. Used to ignore JSON keys that we do not care about.

-> m b

Consume a "separator" between items in the permutation. This consumption is not done at the front of the permutation or after the end of it. This is used to parse commas between JSON fields.

-> Permutation m a

The permutation parser to run.

-> m a

The final parser.

Wrap up a permutation parser with two effects:

It will first interleave an infinite number of some effects, which represent parsing "junk" or unwanted fields. At every stage of the permutation, we will first try to run the effect we want, and if it fails we will try to run the "junk" effect instead, then try again.

We attempt to *intersperse* the second effect afterwards. It adds a new effect between every effect. This is used in parsing JSON to add commas.