jordan-0.2.0.0: JSON with Structure
Safe HaskellNone
LanguageHaskell2010

Jordan.FromJSON.Internal.Permutation

Description

Module containing internal helpers for our parsers.

Synopsis

Documentation

data FailingParser parser Source #

Constructors

FailingParser (forall a. parser a) 
NoFailingParser 

Instances

Instances details
Applicative parser => Semigroup (FailingParser parser) Source # 
Instance details

Defined in Jordan.FromJSON.Internal.Permutation

Methods

(<>) :: FailingParser parser -> FailingParser parser -> FailingParser parser #

sconcat :: NonEmpty (FailingParser parser) -> FailingParser parser #

stimes :: Integral b => b -> FailingParser parser -> FailingParser parser #

eliminateFailing :: Alternative parser => FailingParser parser -> parser a Source #

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

Permutation !(Maybe a) !(FailingParser parser) [Branch parser a] 

Instances

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

Defined in Jordan.FromJSON.Internal.Permutation

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.Internal.Permutation

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.Internal.Permutation

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.Internal.Permutation

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.

asPermutationWithFailing :: Alternative f => f a -> (forall b. f b) -> Permutation f a Source #

asPermutationWithDefaultFailing :: Alternative f => f a -> (forall b. f b) -> a -> Permutation f a Source #