ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.Json.Shape

Description

Retained-value shapes for the token walk, and the reader that builds each value once. A shape reads what the matching Ecluse.Core.Registry.JsonStream combinator reads, and interns keys and strings by the bytes the lexer read unless its mode keeps them as read. A Build says what the reader builds: aeson's tree, or the packed form a full read writes.

Synopsis

Documentation

data Shape Source #

What to retain of one value. Each budget is the structural depth left, and a value read with none left is skipped and fails the read.

Constructors

Scalar !Int

A scalar as read, or an empty array for a container.

Generic !Int

The whole value.

ObjectWith !Int Members Shape

An object's members, or the fallback shape for any other value.

ArrayWith !Int Shape Shape

An array's items, or the fallback shape for any other value.

StringOr !Int Shape

A string, or the other shape for any other value.

ObjectOr Value Members

An object's members, or the given value for any other value.

Checked !Int Shape

The shape, charged against a budget of its own.

data Members Source #

Which members of an object are retained, and with what shape.

namedMembers :: [(Text, Shape)] -> Members Source #

Retain only the named members. The first entry for a name wins.

everyMember :: Shape -> Members Source #

Retain every member with one shape.

knownMembers :: [Text] -> Shape -> Members Source #

Retain every member with one shape, sharing the key of each listed name.

data Mode Source #

Whether a value's keys and strings go through the document's table or keep their own copies.

Constructors

Share 
Keep 

data MemberKey Source #

A member's key: the table's entry, or a key with its own copy.

Constructors

SharedKey !Entry 
OwnKey !Key 

class Walk r => Build b r where Source #

What a read builds, one value at a time, each step handing its result to a continuation. An object's members arrive in source order, and a repeated key's value is read and then dropped.

Associated Types

type Built b Source #

A finished value.

type Fields b Source #

An object being read.

type Items b Source #

An array being read.

Methods

sharedString :: b -> Entry -> (Built b -> r) -> r Source #

A string the document's table shares.

ownString :: b -> Name -> (Built b -> r) -> r Source #

A string with a copy of its own.

integer :: b -> Int -> (Built b -> r) -> r Source #

An integer the lexer read whole.

whole :: b -> Value -> (Built b -> r) -> r Source #

A number, boolean, null or fallback value, taken whole.

emptyContainer :: b -> (Built b -> r) -> r Source #

The empty array a scalar shape keeps for a container it skips.

openObject :: b -> (Fields b -> r) -> r Source #

An object begins.

beginMember :: b -> MemberKey -> Fields b -> (Bool -> r) -> r Source #

A member under the key begins, and whether the object already holds the key.

addMember :: b -> MemberKey -> Built b -> Fields b -> (Fields b -> r) -> r Source #

The member begun last ends with its value.

dropValue :: b -> Built b -> r -> r Source #

Forget the member begun last, whose key the object already holds.

closeObject :: b -> Fields b -> (Built b -> r) -> r Source #

Finish an object.

openArray :: b -> (Items b -> r) -> r Source #

An array begins.

addItem :: b -> Built b -> Items b -> (Items b -> r) -> r Source #

An item of the array ends.

closeArray :: b -> Int -> Items b -> (Built b -> r) -> r Source #

Finish an array of the given item count.

Instances

Instances details
Walk r => Build Trees r Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

Associated Types

type Built Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Fields Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees = [Value]

Methods

sharedString :: Trees -> Entry -> (Built Trees -> r) -> r Source #

ownString :: Trees -> Name -> (Built Trees -> r) -> r Source #

integer :: Trees -> Int -> (Built Trees -> r) -> r Source #

whole :: Trees -> Value -> (Built Trees -> r) -> r Source #

emptyContainer :: Trees -> (Built Trees -> r) -> r Source #

openObject :: Trees -> (Fields Trees -> r) -> r Source #

beginMember :: Trees -> MemberKey -> Fields Trees -> (Bool -> r) -> r Source #

addMember :: Trees -> MemberKey -> Built Trees -> Fields Trees -> (Fields Trees -> r) -> r Source #

dropValue :: Trees -> Built Trees -> r -> r Source #

closeObject :: Trees -> Fields Trees -> (Built Trees -> r) -> r Source #

openArray :: Trees -> (Items Trees -> r) -> r Source #

addItem :: Trees -> Built Trees -> Items Trees -> (Items Trees -> r) -> r Source #

closeArray :: Trees -> Int -> Items Trees -> (Built Trees -> r) -> r Source #

Build (Writer st) (ST st (Steps (ST st) s)) Source #

A value the writer holds in its scratch, which a read passes on as a mark only. Each step runs out of line, so a read's continuations hold the writer as one pointer.

Instance details

Defined in Ecluse.Core.Registry.Json.Writer

Associated Types

type Built (Writer st) 
Instance details

Defined in Ecluse.Core.Registry.Json.Writer

type Built (Writer st) = ()
type Fields (Writer st) 
Instance details

Defined in Ecluse.Core.Registry.Json.Writer

type Fields (Writer st) = Frame
type Items (Writer st) 
Instance details

Defined in Ecluse.Core.Registry.Json.Writer

type Items (Writer st) = Int

Methods

sharedString :: Writer st -> Entry -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

ownString :: Writer st -> Name -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

integer :: Writer st -> Int -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

whole :: Writer st -> Value -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

emptyContainer :: Writer st -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

openObject :: Writer st -> (Fields (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

beginMember :: Writer st -> MemberKey -> Fields (Writer st) -> (Bool -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

addMember :: Writer st -> MemberKey -> Built (Writer st) -> Fields (Writer st) -> (Fields (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

dropValue :: Writer st -> Built (Writer st) -> ST st (Steps (ST st) s) -> ST st (Steps (ST st) s) Source #

closeObject :: Writer st -> Fields (Writer st) -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

openArray :: Writer st -> (Items (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

addItem :: Writer st -> Built (Writer st) -> Items (Writer st) -> (Items (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

closeArray :: Writer st -> Int -> Items (Writer st) -> (Built (Writer st) -> ST st (Steps (ST st) s)) -> ST st (Steps (ST st) s) Source #

data Trees Source #

Build aeson's tree.

Constructors

Trees 

Instances

Instances details
Walk r => Build Trees r Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

Associated Types

type Built Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Fields Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees = [Value]

Methods

sharedString :: Trees -> Entry -> (Built Trees -> r) -> r Source #

ownString :: Trees -> Name -> (Built Trees -> r) -> r Source #

integer :: Trees -> Int -> (Built Trees -> r) -> r Source #

whole :: Trees -> Value -> (Built Trees -> r) -> r Source #

emptyContainer :: Trees -> (Built Trees -> r) -> r Source #

openObject :: Trees -> (Fields Trees -> r) -> r Source #

beginMember :: Trees -> MemberKey -> Fields Trees -> (Bool -> r) -> r Source #

addMember :: Trees -> MemberKey -> Built Trees -> Fields Trees -> (Fields Trees -> r) -> r Source #

dropValue :: Trees -> Built Trees -> r -> r Source #

closeObject :: Trees -> Fields Trees -> (Built Trees -> r) -> r Source #

openArray :: Trees -> (Items Trees -> r) -> r Source #

addItem :: Trees -> Built Trees -> Items Trees -> (Items Trees -> r) -> r Source #

closeArray :: Trees -> Int -> Items Trees -> (Built Trees -> r) -> r Source #

type Built Trees Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Fields Trees Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees Source # 
Instance details

Defined in Ecluse.Core.Registry.Json.Shape

type Items Trees = [Value]

readShape :: Build b r => b -> Shape -> Mode -> InternTable -> Element -> TokenResult -> (Built b -> InternTable -> TokenResult -> r) -> r Source #

Read the value starting at the element and build it once.