lit
fileTypes defines container types for storing a parsed lit
file.
An overview of the file:
<< * >>=
<< module definition >>
<< datatypes >>
<< access methods for types >>
Types is a module imported by most the other modules in lit
, because it defines
most of the core data types used.
<< module definition >>=
module Types where
import Data.Text
In Parse.hs, lit
transforms files into a [Chunk]
. Each
output module (Html, Code, and Markdown)
accepts a [Chunk]
before writing their respective output.
The Def
constructor represents the code chunk, storing the line no. and chunk name.
Each code chunk stores a [Part]
, which represent lines of code or macro references
of the form << name >>
.
<< datatypes >>=
data Chunk = Def Int Text [Part] | Prose Text deriving (Show, Eq)
data Part = Code Text | Ref Text Text deriving (Show, Eq)
type Program = [Chunk]
A boolean check to differentiate between a Prose
or Def
chunk.
<< access methods for types >>=
isDef chunk =
case chunk of
Def _ _ _ -> True
Prose _ -> False
A boolean check to differentiate between a Ref
or Code
part.
<< access methods for types >>=
isRef part =
case part of
Ref _ _ -> True
_ -> False
Retrieve the macro name.
<< access methods for types >>=
getName chunk =
case chunk of
Def _ name _ -> name
_ -> error "cannot retrieve name, not a def"
Retrieve the text of the code part (the non macro references in a chunk).
<< access methods for types >>=
getCodeText part =
case part of
Code txt -> txt
_ -> error "cannot retrieve text, not a code part"
Retrieve the list of code lines and macro references.
<< access methods for types >>=
getParts chunk =
case chunk of
Def _ _ parts -> parts
_ -> error "cannot retrieve parts, not a def"
Retrieve the line number where the Def
was defined
in the lit
file.
<< access methods for types >>=
getLineNo chunk =
case chunk of
Def line _ _ -> line
_ -> error "cannot retrieve line number, not a def"
Retrieve the text stored in a Prose
.
<< access methods for types >>=
getProseText chunk =
case chunk of
Prose txt -> txt
_ -> error "cannot retrieve text, not a prose"