pencil-0.1.1: Static site generator

Safe HaskellSafe
LanguageHaskell2010

Pencil.Internal.Parser

Synopsis

Documentation

>>> :set -XOverloadedStrings
>>> import Data.Either (isLeft)

data PNode Source #

Pencil's Page AST.

Instances

Eq PNode Source # 

Methods

(==) :: PNode -> PNode -> Bool #

(/=) :: PNode -> PNode -> Bool #

Show PNode Source # 

Methods

showsPrec :: Int -> PNode -> ShowS #

show :: PNode -> String #

showList :: [PNode] -> ShowS #

data Token Source #

Pencil's tokens for content.

Instances

Eq Token Source # 

Methods

(==) :: Token -> Token -> Bool #

(/=) :: Token -> Token -> Bool #

Show Token Source # 

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

transform :: [Token] -> [PNode] Source #

Convert Tokens to PNode AST.

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)

popNodes_ :: [PNode] -> [PNode] -> (PNode, [PNode], [PNode]) Source #

Helper for popNodes.

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.

parseVar :: Parser Token Source #

Parse variables.

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.

parseFor :: Parser Token Source #

Parse for loop declaration.

parseIf :: Parser Token Source #

Parse if directive.

parseFunction :: String -> (Text -> Token) -> Parser Token Source #

General parse template functions.

parseEnd :: Parser Token Source #

Parse end keyword.

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

findPreambleText :: [PNode] -> Maybe Text Source #

Find the preamble content from the given PNodes.

isPreamble :: PNode -> Bool Source #

Returns True if the PNode is a PPreamble.

preambleText :: PNode -> Maybe Text Source #

Gets the content of the PPreamble