Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- data PNode
- data Token
- transform :: [Token] -> [PNode]
- ast :: [PNode] -> [Token] -> [PNode]
- popNodes :: [PNode] -> (PNode, [PNode], [PNode])
- popNodes_ :: [PNode] -> [PNode] -> (PNode, [PNode], [PNode])
- renderNodes :: [PNode] -> Text
- renderNode :: PNode -> Text
- renderTokens :: [Token] -> Text
- renderToken :: Token -> Text
- parseText :: Text -> Either ParseError [PNode]
- parseEverything :: Parser [Token]
- parseVar :: Parser Token
- parsePreamble :: Parser Token
- parsePreambleStart :: Parser String
- parsePartial :: Parser Token
- parseContent :: Parser Token
- parseFor :: Parser Token
- parseIf :: Parser Token
- parseFunction :: String -> (Text -> Token) -> Parser Token
- parseEnd :: Parser Token
- parseFakeVar :: Parser Token
- many1Till :: Stream s m t => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
- findPreambleText :: [PNode] -> Maybe Text
- isPreamble :: PNode -> Bool
- preambleText :: PNode -> Maybe Text
Documentation
>>>
:set -XOverloadedStrings
>>>
import Data.Either (isLeft)
Pencil's Page
AST.
Pencil's tokens for content.
ast :: [PNode] -> [Token] -> [PNode] Source #
Converts Tokens, which is just the raw list of parsed tokens, into PNodes which are the tree-structure expressions (i.e. if/for nesting)
This function works by using a stack to keep track of where we are for nested expressions such as if and for statements. When a token that starts a nesting is found (like a TokIf), a "meta" expression (PMetaIf) is pushed into the stack. When we finally see an end token (TokEnd), we pop all the expressions off the stack until the first meta tag (e.g PMetaIf) is reached. All the expressions popped off are now known to be nested inside that if statement.
popNodes :: [PNode] -> (PNode, [PNode], [PNode]) Source #
Pop nodes until we hit a If/For statement. Return pair (constructor found, nodes popped, remaining stack)
renderNodes :: [PNode] -> Text Source #
Render nodes as string.
renderNode :: PNode -> Text Source #
Render node as string.
renderTokens :: [Token] -> Text Source #
Render tokens.
renderToken :: Token -> Text Source #
Render token.
parseEverything :: Parser [Token] Source #
Parse everything.
parsePreamble :: Parser Token Source #
Parse preamble.
parsePreambleStart :: Parser String Source #
Parse the start of a PREAMBLE.
parsePartial :: Parser Token Source #
Parse partial commands.
parseContent :: Parser Token Source #
Parse boring, boring text.
parseFunction :: String -> (Text -> Token) -> Parser Token Source #
General parse template functions.
parseFakeVar :: Parser Token Source #
A hack to capture strings that "almost" are templates. I couldn't figure out another way.
many1Till :: Stream s m t => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a] Source #
many1Till p end
will parse one or more p
until @end.
From https://hackage.haskell.org/package/pandoc-1.10.0.4/docs/Text-Pandoc-Parsing.html
isPreamble :: PNode -> Bool Source #
Returns True
if the PNode
is a PPreamble
.