-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parse arrays of tokens -- -- This library is similar in spirit to bytesmith. While -- bytesmith parses byte sequences, smith parses token -- sequences. The most common way to use them together is to lex with -- bytesmith and then parse the token sequence with smith. @package smith @version 0.1.1.0 -- | Everything in this module is unsafe and can lead to nondeterministic -- output or segfaults if used incorrectly. module Data.Parser.Unsafe -- | A non-resumable toke parser. newtype Parser :: Type -> Type -> Type -> Type -> Type [Parser] :: {runParser :: SmallVector# a -> ST# s (Result# e b)} -> Parser a e s b -- | Move the cursor back by n tokens. Precondition: you must have -- previously consumed at least n tokens. unconsume :: Int -> Parser a e s () instance GHC.Base.Functor (Data.Parser.Unsafe.Parser a e s) instance GHC.Base.Applicative (Data.Parser.Unsafe.Parser a e s) instance GHC.Base.Monad (Data.Parser.Unsafe.Parser a e s) -- | Parse token sequences. module Data.Parser -- | A non-resumable toke parser. data Parser :: Type -> Type -> Type -> Type -> Type -- | The result of running a parser. data Result e a -- | An error message indicating what went wrong. Failure :: e -> Result e a -- | The parsed value and the number of bytes remaining in parsed slice. Success :: {-# UNPACK #-} !Slice a -> Result e a -- | Slicing metadata (an offset and a length) accompanied by a value. This -- does not represent a slice into the value. This type is intended to be -- used as the result of an executed parser. In this context the slicing -- metadata describe a slice into to the array (or byte array) that from -- which the value was parsed. -- -- It is often useful to check the length when a parser succeeds -- since a non-zero length indicates that there was additional unconsumed -- input. The offset is only ever needed to construct a new -- slice (via Bytes or SmallVector) from the remaining -- input. data Slice a Slice :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> a -> Slice a parseSmallArray :: forall a e b. (forall s. Parser a e s b) -> SmallArray a -> Result e b parseSmallArrayEffectfully :: Parser a e s b -> SmallArray a -> ST s (Result e b) -- | Consumes and returns the next token from the input. Fails if no tokens -- are left. any :: e -> Parser a e s a -- | Consume a token from the input or return Nothing if end of -- the stream has been reached. This parser never fails. opt :: Parser a e s (Maybe a) -- | Returns the next token from the input without consuming it. Fails if -- no tokens are left. peek :: e -> Parser a e s a -- | Consumes the next token from the input. Fails if it is not equal to -- the expected value. token :: Eq a => e -> a -> Parser a e s () -- | Lift an effect into a parser. effect :: ST s b -> Parser a e s b -- | Consumes and returns the next token from the input. Fails if no tokens -- are left. fail :: e -> Parser a e s b -- | Looks at the next token from the input. If the token matches the -- predicate, consume the token and return True. Otherwise, do -- not consume the token and return False. If no tokens remain -- in the input, return False. This parser never fails. trySatisfy :: (a -> Bool) -> Parser a e s Bool -- | Fold over the tokens, repeatedly running step followed by -- separator until separator returns False. This -- is strict in the accumulator and always runs step at least -- once. There is no backtracking; any failure causes the whole -- combinator to fail. foldSepBy1 :: Parser a e s Bool -> (b -> Parser a e s b) -> b -> Parser a e s b -- | Fold over the tokens, repeatedly running step followed by -- separator until separator returns False. The -- results of step are discarded, but in conjunction with -- effect, this can be used to populate an array or a builder. -- This always runs step at least once. -- --
--   sepBy1 sep step === step *> (sep >>= bool (pure ()) (step *> (sep >>= bool (pure ()) (...))))
--   
sepBy1 :: Parser a e s Bool -> Parser a e s b -> Parser a e s () -- | Skip tokens for which the predicate is true. skipWhile :: (a -> Bool) -> Parser a e s ()