| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Yamlet.Internal.Parser.Monad
Description
A backtracking parser over the bytes of UTF-8 encoded text.
This module is intended for internal use only, and may change without warning in subsequent releases.
Synopsis
- data P a
- data Env = Env {}
- data ParseError
- = ParseError !Int !String
- | UnexpectedParseError !Env !Int
- runParser :: Env -> Int -> P a -> Either ParseError (Maybe a, Int, Int)
- (<|>) :: P a -> P a -> P a
- many :: P a -> P [a]
- many_ :: P a -> P ()
- optional :: P a -> P (Maybe a)
- optional_ :: P a -> P ()
- option :: a -> P a -> P a
- notFollowedBy :: P a -> P ()
- env :: P Env
- pos :: P Int
- setPos :: Int -> P ()
- furthest :: P Int
- advance :: Int -> P ()
- addTagBytes :: Int -> P Int
- peek :: P Word8
- peekAt :: Int -> P Word8
- failure :: P a
- guardP :: Bool -> P ()
- throwAt :: Int -> String -> P a
- throwUnexpected :: Int -> P a
- withEnd :: Int -> P a -> P a
- withHandles :: Map Text Text -> P a -> P a
- char :: Word8 -> P ()
- skipWhile :: (Word8 -> Bool) -> P ()
- scan :: (Env -> Int -> Int) -> P ()
- data Scanned a
- withScan :: (Env -> Int -> Scanned a) -> P a
- byteAt :: Env -> Int -> Word8
- byteBefore :: Env -> Int -> Word8
- slice :: Env -> Int -> Int -> Text
- toOffset :: Env -> Int -> Offset
Parser
The input of the parser.
Constructors
| Env | |
Fields
| |
data ParseError Source #
An error that no backtracking can recover from: an error at the index with the message, or a failure at the index in the environment, whose message the caller of the parser finds.
Constructors
| ParseError !Int !String | |
| UnexpectedParseError !Env !Int |
runParser :: Env -> Int -> P a -> Either ParseError (Maybe a, Int, Int) Source #
Run a parser from the given index. Return the result, the index after it and the furthest failure.
Combinators
(<|>) :: P a -> P a -> P a infixl 3 Source #
Ordered choice. Try the second parser if the first one fails.
notFollowedBy :: P a -> P () Source #
Succeed without input if the parser fails. An error of the parser stays
an error, as in <|>.
Primitives
addTagBytes :: Int -> P Int Source #
Add the bytes that the prefix of a %TAG directive adds to a tag, and
return the bytes that such prefixes added so far. A parser that fails
drops its bytes, so only the tags of the result count.
throwUnexpected :: Int -> P a Source #
Stop at the index, with an error whose message the caller of the parser finds.
withHandles :: Map Text Text -> P a -> P a Source #
scan :: (Env -> Int -> Int) -> P () Source #
Move to the index that the function computes from the current one.
The result of a scanning loop.
withScan :: (Env -> Int -> Scanned a) -> P a Source #
Run a pure loop over the input from the current position.
Input access
byteBefore :: Env -> Int -> Word8 Source #
The byte before the index, 0 at the start of the input.