djot-0.1.4: Parser and renderer for djot light markup syntax.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Djot.Parse

Synopsis

- data Parser s a
- data Chunk = Chunk {
  - chunkLine :: Int
  - chunkColumn :: Int
  - chunkBytes :: ByteString
  }
- parse :: Parser s a -> s -> [Chunk] -> Maybe a
- asciiChar :: Char -> Parser s ()
- satisfyByte :: (Char -> Bool) -> Parser s Char
- skipSatisfyByte :: (Char -> Bool) -> Parser s ()
- satisfy :: (Char -> Bool) -> Parser s Char
- anyChar :: Parser s Char
- skipMany :: Parser s a -> Parser s ()
- skipSome :: Parser s a -> Parser s ()
- eof :: Parser s ()
- getState :: Parser s s
- updateState :: (s -> s) -> Parser s ()
- lookahead :: Parser s a -> Parser s a
- peek :: Parser s (Maybe Char)
- peekBack :: Parser s (Maybe Char)
- fails :: Parser s a -> Parser s ()
- failed :: Parser s a
- withByteString :: Parser s a -> Parser s (a, ByteString)
- byteStringOf :: Parser s a -> Parser s ByteString
- notFollowedBy :: Parser s a -> Parser s b -> Parser s a
- optional_ :: Parser s a -> Parser s ()
- byteString :: ByteString -> Parser s ()
- getOffset :: Parser s Int
- sourceLine :: Parser s Int
- sourceColumn :: Parser st Int
- branch :: Parser s b -> Parser s a -> Parser s a -> Parser s a
- endline :: Parser s ()
- restOfLine :: Parser s ByteString
- ws :: Parser s ()
- followedByWhitespace :: Parser s ()
- followedByBlankLine :: Parser s ()
- spaceOrTab :: Parser s ()
- isWs :: Char -> Bool
- strToUtf8 :: String -> ByteString
- utf8ToStr :: ByteString -> String

# Documentation

data Parser s a Source #

#### Instances

Instances details

Alternative (Parser s) Source # |
Instance details Defined in Djot.Parse Methods empty :: Parser s a Source # (<|>) :: Parser s a -> Parser s a -> Parser s a Source # some :: Parser s a -> Parser s [a] Source # many :: Parser s a -> Parser s [a] Source #
Applicative (Parser s) Source # |
Instance details Defined in Djot.Parse Methods pure :: a -> Parser s a Source # (<*>) :: Parser s (a -> b) -> Parser s a -> Parser s b Source # liftA2 :: (a -> b -> c) -> Parser s a -> Parser s b -> Parser s c Source # (*>) :: Parser s a -> Parser s b -> Parser s b Source # (<*) :: Parser s a -> Parser s b -> Parser s a Source #
Functor (Parser s) Source # |
Instance details Defined in Djot.Parse Methods fmap :: (a -> b) -> Parser s a -> Parser s b Source # (<$) :: a -> Parser s b -> Parser s a Source #
Monad (Parser s) Source # |
Instance details Defined in Djot.Parse Methods (>>=) :: Parser s a -> (a -> Parser s b) -> Parser s b Source # (>>) :: Parser s a -> Parser s b -> Parser s b Source # return :: a -> Parser s a Source #
MonadPlus (Parser s) Source # |
Instance details Defined in Djot.Parse Methods mzero :: Parser s a Source # mplus :: Parser s a -> Parser s a -> Parser s a Source #

data Chunk Source #

Constructors

Chunk |

Fields

- chunkLine :: Int
- chunkColumn :: Int
- chunkBytes :: ByteString

#### Instances

Instances details

Show Chunk Source # |
Instance details Defined in Djot.Parse Methods showsPrec :: Int -> Chunk -> ShowS Source # show :: Chunk -> String Source # showList :: [Chunk] -> ShowS Source #
Eq Chunk Source # |
Instance details Defined in Djot.Parse Methods (==) :: Chunk -> Chunk -> Bool Source # (/=) :: Chunk -> Chunk -> Bool Source #
Ord Chunk Source # |
Instance details Defined in Djot.Parse Methods compare :: Chunk -> Chunk -> Ordering Source # (<) :: Chunk -> Chunk -> Bool Source # (<=) :: Chunk -> Chunk -> Bool Source # (>) :: Chunk -> Chunk -> Bool Source # (>=) :: Chunk -> Chunk -> Bool Source # max :: Chunk -> Chunk -> Chunk Source # min :: Chunk -> Chunk -> Chunk Source #

parse :: Parser s a -> s -> [Chunk] -> Maybe a Source #

Apply a parser to a bytestring with a given user state. Returns `Nothing` on failure, `Just result` on success.

asciiChar :: Char -> Parser s () Source #

Parse an ASCII character.

satisfyByte :: (Char -> Bool) -> Parser s Char Source #

Parse a byte satisfying a predicate.

skipSatisfyByte :: (Char -> Bool) -> Parser s () Source #

Skip byte satisfying a predicate.

satisfy :: (Char -> Bool) -> Parser s Char Source #

Parse a (possibly multibyte) Char satisfying a predicate. Assumes UTF-8 encoding.

anyChar :: Parser s Char Source #

Parse any character. Assumes UTF-8 encoding.

skipMany :: Parser s a -> Parser s () Source #

Apply parser 0 or more times, discarding result.

skipSome :: Parser s a -> Parser s () Source #

Apply parser 1 or more times, discarding result.

eof :: Parser s () Source #

Succeeds if no more input.

getState :: Parser s s Source #

Returns current user state.

updateState :: (s -> s) -> Parser s () Source #

Updates user state.

lookahead :: Parser s a -> Parser s a Source #

Apply a parser, returning its result but not changing state or advancing.

peek :: Parser s (Maybe Char) Source #

Returns current byte as Char.

peekBack :: Parser s (Maybe Char) Source #

Returns previous byte as Char. Doesn't cross chunk boundaries.

fails :: Parser s a -> Parser s () Source #

Succeeds if parser fails.

failed :: Parser s a Source #

Always fails.

withByteString :: Parser s a -> Parser s (a, ByteString) Source #

Returns result of parse together with the bytestring consumed.

byteStringOf :: Parser s a -> Parser s ByteString Source #

Returns bytestring consumed by parse.

notFollowedBy :: Parser s a -> Parser s b -> Parser s a Source #

Succeeds if first parser succeeds and second fails, returning first parser's value.

optional_ :: Parser s a -> Parser s () Source #

Apply parser but still succeed if it doesn't succeed.

byteString :: ByteString -> Parser s () Source #

Parse a bytestring.

getOffset :: Parser s Int Source #

Returns byte offset in input.

sourceLine :: Parser s Int Source #

Returns the line number.

sourceColumn :: Parser st Int Source #

Returns the source column number. (Tab stop is computed at 4.)

branch :: Parser s b -> Parser s a -> Parser s a -> Parser s a Source #

Try the first parser: if it succeeds, apply the second, returning its result, otherwise the third.

endline :: Parser s () Source #

Parse an end of line sequence.

restOfLine :: Parser s ByteString Source #

Return the rest of line (including the end of line).

ws :: Parser s () Source #

Skip 1 or more ASCII whitespace.

followedByWhitespace :: Parser s () Source #

Next character is ASCII whitespace.

followedByBlankLine :: Parser s () Source #

Followed by 0 or more spaces/tabs and endline or eof.

spaceOrTab :: Parser s () Source #

Skip one space or tab.

isWs :: Char -> Bool Source #

Is space, tab, `r`, or `n`.

strToUtf8 :: String -> ByteString Source #

utf8ToStr :: ByteString -> String Source #