djot-0.1.2.2: 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 #

#### Instances

Instances details

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

data Chunk #

Constructors

Chunk |

Fields

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

#### Instances

Instances details

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

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

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

asciiChar :: Char -> Parser s () #

Parse an ASCII character.

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

Parse a byte satisfying a predicate.

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

Skip byte satisfying a predicate.

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

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

anyChar :: Parser s Char #

Parse any character. Assumes UTF-8 encoding.

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

Apply parser 0 or more times, discarding result.

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

Apply parser 1 or more times, discarding result.

eof :: Parser s () #

Succeeds if no more input.

getState :: Parser s s #

Returns current user state.

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

Updates user state.

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

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

peek :: Parser s (Maybe Char) #

Returns current byte as Char.

peekBack :: Parser s (Maybe Char) #

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

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

Succeeds if parser fails.

failed :: Parser s a #

Always fails.

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

Returns result of parse together with the bytestring consumed.

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

Returns bytestring consumed by parse.

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

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

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

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

byteString :: ByteString -> Parser s () #

Parse a bytestring.

getOffset :: Parser s Int #

Returns byte offset in input.

sourceLine :: Parser s Int #

Returns the line number.

sourceColumn :: Parser st Int #

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

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

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

endline :: Parser s () #

Parse an end of line sequence.

restOfLine :: Parser s ByteString #

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

ws :: Parser s () #

Skip 1 or more ASCII whitespace.

followedByWhitespace :: Parser s () #

Next character is ASCII whitespace.

followedByBlankLine :: Parser s () #

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

spaceOrTab :: Parser s () #

Skip one space or tab.

isWs :: Char -> Bool #

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

strToUtf8 :: String -> ByteString #

utf8ToStr :: ByteString -> String #