packages feed

expand-0.0.1: src/Toc/Semantics/Toc.hs

{-# LANGUAGE TemplateHaskell, EmptyDataDecls, NoMonomorphismRestriction #-}
module Toc.Semantics.Toc where

import Data.HList.Label4
import Data.HList.TypeEqGeneric1
import Data.HList.TypeCastGeneric1

import Language.Grammars.AspectAG
import Language.Grammars.AspectAG.Derive

import Document.Decl
import Document.Semantics.NumberedHeaders


$(attLabels ["sToc", "toc", "sInlStr"])


-- Inline string (ignores bold/italics formatting)

sInlStr_NTs = nt_InlineL .*. nt_Inline .*. HNil


default_sInlStr = use sInlStr sInlStr_NTs (++) ""

plain_sInlStr = syn sInlStr $
                    do str <- at ch_str_plainInl
                       return $ str

bold_sInlStr = syn sInlStr $
                    do inl <- at ch_inlines_boldInl
                       return (inl # sInlStr)

italics_sInlStr = syn sInlStr $
                    do inl <- at ch_inlines_italInl
                       return (inl # sInlStr)




-- Synthesized TOC

sToc_NTs = nt_Block .*. nt_BlockL .*. HNil

default_sToc = use sToc sToc_NTs (++) []

header_sToc = syn sToc $
    do loc  <- at loc
       inls <- at ch_inlines_header
       return [(loc # headerNum, inls # sInlStr)]




-- Inherited TOC


toc_NTs = nt_Block .*. nt_BlockL .*. HNil

document_toc = inh toc toc_NTs $
                do bls <- at ch_blocks
                   return $ (ch_blocks .=. bls # sToc) .*. emptyRecord

default_toc = copy toc toc_NTs