{-# LANGUAGE OverloadedStrings #-}

module Language.Lsd.AST.Type.AppendixSection
    ( AppendixSectionFormat (..)
    , AppendixSectionTitle (..)
    , AppendixElementFormat (..)
    , AppendixSectionType (..)
    )
where

import Data.Text (Text)
import Language.Lsd.AST.Format
    ( IdentifierFormat
    , InnerHeadingFormat
    , TocKeyFormat
    )
import Language.Lsd.AST.SimpleRegex (Disjunction, Star (Star))
import Language.Lsd.AST.Type
    ( ChildrenOrder (StarOrder)
    , HasEditableHeader (HasEditableHeader)
    , NamedType
    , RawProperNodeKind (..)
    , TreeSyntax (TreeSyntax)
    )
import Language.Lsd.AST.Type.Document (DocumentType)

data AppendixSectionFormat
    = AppendixSectionFormat
        AppendixSectionTitle
        AppendixElementFormat
    deriving (Int -> AppendixSectionFormat -> ShowS
[AppendixSectionFormat] -> ShowS
AppendixSectionFormat -> String
(Int -> AppendixSectionFormat -> ShowS)
-> (AppendixSectionFormat -> String)
-> ([AppendixSectionFormat] -> ShowS)
-> Show AppendixSectionFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppendixSectionFormat -> ShowS
showsPrec :: Int -> AppendixSectionFormat -> ShowS
$cshow :: AppendixSectionFormat -> String
show :: AppendixSectionFormat -> String
$cshowList :: [AppendixSectionFormat] -> ShowS
showList :: [AppendixSectionFormat] -> ShowS
Show)

-- | Title of an appendix section.
--   This is not a heading; it only occurs in the TOC, if any.
newtype AppendixSectionTitle = AppendixSectionTitle Text
    deriving (Int -> AppendixSectionTitle -> ShowS
[AppendixSectionTitle] -> ShowS
AppendixSectionTitle -> String
(Int -> AppendixSectionTitle -> ShowS)
-> (AppendixSectionTitle -> String)
-> ([AppendixSectionTitle] -> ShowS)
-> Show AppendixSectionTitle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppendixSectionTitle -> ShowS
showsPrec :: Int -> AppendixSectionTitle -> ShowS
$cshow :: AppendixSectionTitle -> String
show :: AppendixSectionTitle -> String
$cshowList :: [AppendixSectionTitle] -> ShowS
showList :: [AppendixSectionTitle] -> ShowS
Show)

data AppendixElementFormat
    = AppendixElementFormat
        IdentifierFormat
        TocKeyFormat
        InnerHeadingFormat
    deriving (Int -> AppendixElementFormat -> ShowS
[AppendixElementFormat] -> ShowS
AppendixElementFormat -> String
(Int -> AppendixElementFormat -> ShowS)
-> (AppendixElementFormat -> String)
-> ([AppendixElementFormat] -> ShowS)
-> Show AppendixElementFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppendixElementFormat -> ShowS
showsPrec :: Int -> AppendixElementFormat -> ShowS
$cshow :: AppendixElementFormat -> String
show :: AppendixElementFormat -> String
$cshowList :: [AppendixElementFormat] -> ShowS
showList :: [AppendixElementFormat] -> ShowS
Show)

data AppendixSectionType
    = AppendixSectionType
        AppendixSectionFormat
        (Star (Disjunction (NamedType DocumentType)))

instance RawProperNodeKind AppendixSectionType where
    kindNameOfRaw :: Proxy AppendixSectionType -> KindName
kindNameOfRaw Proxy AppendixSectionType
_ = KindName
"appendix-section"

    treeSyntaxMapRaw :: forall a.
(forall t'. ProperNodeKind t' => t' -> a)
-> AppendixSectionType -> TreeSyntax a
treeSyntaxMapRaw forall t'. ProperNodeKind t' => t' -> a
f (AppendixSectionType AppendixSectionFormat
_ (Star Disjunction (NamedType DocumentType)
t)) =
        HasEditableHeader -> ChildrenOrder a -> TreeSyntax a
forall a. HasEditableHeader -> ChildrenOrder a -> TreeSyntax a
TreeSyntax (Bool -> HasEditableHeader
HasEditableHeader Bool
False) (ChildrenOrder a -> TreeSyntax a)
-> ChildrenOrder a -> TreeSyntax a
forall a b. (a -> b) -> a -> b
$ Disjunction a -> ChildrenOrder a
forall a. Disjunction a -> ChildrenOrder a
StarOrder (Disjunction a -> ChildrenOrder a)
-> Disjunction a -> ChildrenOrder a
forall a b. (a -> b) -> a -> b
$ (NamedType DocumentType -> a)
-> Disjunction (NamedType DocumentType) -> Disjunction a
forall a b. (a -> b) -> Disjunction a -> Disjunction b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedType DocumentType -> a
forall t'. ProperNodeKind t' => t' -> a
f Disjunction (NamedType DocumentType)
t