bytezap-1.3.0: Bytestring builder with zero intermediate allocation
Safe HaskellSafe-Inferred
LanguageGHC2021

Bytezap.Parser.Struct

Description

Struct parser.

We do still have to do failure checking, because unlike C we check some types (e.g. bitfields). Hopefully inlining can remove those checks when unnecessary.

Synopsis

Documentation

type STMode s = State# s Source #

type ParserT# (st :: ZeroBitType) e a Source #

Arguments

 = ForeignPtrContents

pointer provenance

-> Addr#

base address

-> Int#

cursor offset from base

-> st

state token

-> Res# st e a 

newtype ParserT (st :: ZeroBitType) e a Source #

Constructors

ParserT 

Fields

Instances

Instances details
Functor (ParserT st e) Source # 
Instance details

Defined in Bytezap.Parser.Struct

Methods

fmap :: (a -> b) -> ParserT st e a -> ParserT st e b #

(<$) :: a -> ParserT st e b -> ParserT st e a #

type Parser = ParserT PureMode Source #

The type of pure parsers.

type ParserIO = ParserT IOMode Source #

The type of parsers which can embed IO actions.

type ParserST s = ParserT (STMode s) Source #

The type of parsers which can embed ST actions.

type Res# (st :: ZeroBitType) e a = (# st, ResI# e a #) Source #

Primitive parser result wrapped with a state token.

You should rarely need to manipulate values of this type directly. Use the provided bidirectional pattern synonyms OK#, Fail# and Err#.

type ResI# e a = (# (# a #) | (# #) | (# e #) #) Source #

Primitive parser result.

pattern OK# :: (st :: ZeroBitType) -> a -> Res# st e a Source #

Res# constructor for a successful parse. Contains the return value and a state token.

pattern Fail# :: (st :: ZeroBitType) -> Res# st e a Source #

Res# constructor for recoverable failure. Contains only a state token.

pattern Err# :: (st :: ZeroBitType) -> e -> Res# st e a Source #

Res# constructor for errors which are by default non-recoverable. Contains the error, plus a state token.

unsafeRunParserBs :: forall a e. ByteString -> Parser e a -> Result e a Source #

caller must guarantee that buffer is long enough for parser!!

unsafeRunParserPtr :: forall a e. Ptr Word8 -> Parser e a -> Result e a Source #

caller must guarantee that buffer is long enough for parser!!

unsafeRunParserFPtr :: forall a e. ForeignPtr Word8 -> Parser e a -> Result e a Source #

caller must guarantee that buffer is long enough for parser!!

unsafeRunParser' :: forall a e. Addr# -> ForeignPtrContents -> Parser e a -> Result e a Source #

caller must guarantee that buffer is long enough for parser!!

data Result e a Source #

Higher-level boxed data type for parsing results.

Constructors

OK a

Contains return value.

Fail

Recoverable-by-default failure.

Err !e

Unrecoverable-by-default error.

Instances

Instances details
(Show a, Show e) => Show (Result e a) Source # 
Instance details

Defined in Bytezap.Parser.Struct

Methods

showsPrec :: Int -> Result e a -> ShowS #

show :: Result e a -> String #

showList :: [Result e a] -> ShowS #

constParse :: a -> ParserT st e a Source #

can't provide via pure as no Applicative

sequenceParsers :: Int -> (a -> b -> c) -> ParserT st e a -> ParserT st e b -> ParserT st e c Source #

prim :: forall a st e. Prim' a => ParserT st e a Source #

lit :: Eq a => a -> ParserT st e a -> ParserT st e () Source #

parse literal

withLit :: Eq a => Int# -> a -> ParserT st e a -> ParserT st e r -> ParserT st e r Source #

parse literal (CPS)