| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Ecluse.Core.Registry.Json.Walk
Contents
Description
A resumable walk over immutable native lexer cursors, with a body-bounded driver.
The primitives preserve json-stream's lenient token and skip rules. Tree reads stay pure.
Packed writers use ST while consuming the same cursor interface.
Synopsis
- data Steps (m :: Type -> Type) s
- = NeedData (ByteString -> m (Steps m s))
- | Failed Text
- | Refused LimitError
- | Finished s
- type Step = Steps Identity
- class Walk r where
- type Result r
- needData :: (ByteString -> r) -> r
- failWith :: Text -> r
- refuse :: LimitError -> r
- finish :: Result r -> r
- readJsonWalk :: Monad m => BodyLimit -> (Cursor -> Step s) -> m ByteString -> m (Either LimitError (StreamResult s))
- readJsonWalkST :: Monad m => (forall a. ST st a -> m a) -> BodyLimit -> (Cursor -> ST st (Steps (ST st) s)) -> m ByteString -> m (Either LimitError (StreamResult s))
- nestingLimit :: Text
- data Walked s = Walked !InternTable s
- type FieldStep s field r = s -> field -> (Either LimitError s -> r) -> r
- pureStep :: (s -> field -> Either LimitError s) -> FieldStep s field r
- emit :: Walk r => FieldStep s field r -> s -> field -> (s -> r) -> r
- withElement :: Walk r => Cursor -> (Element -> Cursor -> r) -> r
- withScanned :: Walk r => Scanned -> (Element -> Cursor -> r) -> r
- skipFrom :: Walk r => Element -> Cursor -> (Cursor -> r) -> r
- skipRest :: Walk r => Int -> Cursor -> (Cursor -> r) -> r
- tooDeep :: Walk r => Element -> Cursor -> r
- isString :: Element -> Bool
- readString :: Walk r => Element -> Cursor -> (Name -> Cursor -> r) -> r
- eachMember :: Walk r => (st -> Name -> Cursor -> (st -> Cursor -> r) -> r) -> (st -> Cursor -> r) -> st -> Cursor -> r
- memberName :: Walk r => Element -> Cursor -> (Name -> Cursor -> r) -> (Cursor -> r) -> r
- eachItem :: Walk r => (st -> Int -> Element -> Cursor -> (st -> Cursor -> r) -> r) -> (st -> Cursor -> r) -> st -> Cursor -> r
Driving a walk
data Steps (m :: Type -> Type) s Source #
A suspended, failed, refused or finished read. Writing reads resume in their own effect.
Constructors
| NeedData (ByteString -> m (Steps m s)) | |
| Failed Text | |
| Refused LimitError | |
| Finished s |
Instances
What a walk's continuations return: a read that needs input, has failed or been refused, or is done.
Methods
needData :: (ByteString -> r) -> r Source #
Suspend until the next chunk of input.
failWith :: Text -> r Source #
Stop on a parse error.
refuse :: LimitError -> r Source #
Stop on a refused field.
finish :: Result r -> r Source #
Finish with the walk's result.
Instances
| Walk (Steps Identity s) Source # | |||||
Defined in Ecluse.Core.Registry.Json.Walk Associated Types
| |||||
| Walk (ST st (Steps (ST st) s)) Source # | |||||
Defined in Ecluse.Core.Registry.Json.Walk Associated Types
| |||||
readJsonWalk :: Monad m => BodyLimit -> (Cursor -> Step s) -> m ByteString -> m (Either LimitError (StreamResult s)) Source #
Walk a body as readJsonStream reads one, from the lexer's first token.
readJsonWalkST :: Monad m => (forall a. ST st a -> m a) -> BodyLimit -> (Cursor -> ST st (Steps (ST st) s)) -> m ByteString -> m (Either LimitError (StreamResult s)) Source #
readJsonWalk for a walk that writes in ST as it reads, run in the reader's effect.
nestingLimit :: Text Source #
The parse error that marks a retained value past its structural budget.
A walk's state between tokens: the read's table and the consumer's accumulator.
Constructors
| Walked !InternTable s |
type FieldStep s field r = s -> field -> (Either LimitError s -> r) -> r Source #
How a consumer takes each field: it continues with its next state, or refuses the field.
pureStep :: (s -> field -> Either LimitError s) -> FieldStep s field r Source #
A consumer that takes each field without an effect of its own.
emit :: Walk r => FieldStep s field r -> s -> field -> (s -> r) -> r Source #
Pass a field to the consumer's step. A refused field ends the walk.
Tokens
withElement :: Walk r => Cursor -> (Element -> Cursor -> r) -> r Source #
The next element, suspending for input at a chunk boundary. The continuation runs once.
withScanned :: Walk r => Scanned -> (Element -> Cursor -> r) -> r Source #
Continue a scan result without scanning its input again.
skipFrom :: Walk r => Element -> Cursor -> (Cursor -> r) -> r Source #
Skip the value starting at the element without decoding it, as json-stream's ignoreVal does.
skipRest :: Walk r => Int -> Cursor -> (Cursor -> r) -> r Source #
Skip to the end of the container the given number of levels up. Any closing token closes a level.
tooDeep :: Walk r => Element -> Cursor -> r Source #
Skip the value, then fail: a retained value with no structural budget left.
readString :: Walk r => Element -> Cursor -> (Name -> Cursor -> r) -> r Source #
Decode the string starting at the element, failing where json-stream's string fails.
eachMember :: Walk r => (st -> Name -> Cursor -> (st -> Cursor -> r) -> r) -> (st -> Cursor -> r) -> st -> Cursor -> r Source #
Visit each member of an object whose opening brace was read, as json-stream's objectKeyValues
does: every key is decoded, and a key longer than 64 KiB across pieces drops its member unread.
memberName :: Walk r => Element -> Cursor -> (Name -> Cursor -> r) -> (Cursor -> r) -> r Source #
Decode the object key at the element, or skip its member when json-stream drops it unread.