module Language.Ltml.Parser.SimpleBlock
    ( simpleBlockP
    )
where

import Control.Applicative ((<|>))
import Language.Lsd.AST.Type (unwrapNT)
import Language.Lsd.AST.Type.SimpleBlock (SimpleBlockType (SimpleBlockType))
import Language.Ltml.AST.SimpleBlock (SimpleBlock (..))
import Language.Ltml.Parser (Parser)
import Language.Ltml.Parser.Module (moduleBlockP)
import Language.Ltml.Parser.SimpleParagraph (simpleParagraphP)
import Language.Ltml.Parser.Table (tableP)

simpleBlockP :: SimpleBlockType -> Parser SimpleBlock
simpleBlockP :: SimpleBlockType -> Parser SimpleBlock
simpleBlockP (SimpleBlockType NamedType SimpleParagraphType
parT NamedType TableType
tableT NamedType ModuleBlockType
moduleBT) =
    -- Parsing a paragraph must be attempted last, for it does not have a
    -- keyword; i.e., generally treats a keyword as plain text.
    Table -> SimpleBlock
TableBlock (Table -> SimpleBlock)
-> ParsecT Void Text Identity Table -> Parser SimpleBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableType -> ParsecT Void Text Identity Table
tableP (NamedType TableType -> TableType
forall t. NamedType t -> t
unwrapNT NamedType TableType
tableT)
        Parser SimpleBlock -> Parser SimpleBlock -> Parser SimpleBlock
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Table -> SimpleBlock
TableBlock (Table -> SimpleBlock)
-> ParsecT Void Text Identity Table -> Parser SimpleBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModuleBlockType -> ParsecT Void Text Identity Table
moduleBlockP (NamedType ModuleBlockType -> ModuleBlockType
forall t. NamedType t -> t
unwrapNT NamedType ModuleBlockType
moduleBT)
        Parser SimpleBlock -> Parser SimpleBlock -> Parser SimpleBlock
forall a.
ParsecT Void Text Identity a
-> ParsecT Void Text Identity a -> ParsecT Void Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SimpleParagraph -> SimpleBlock
SimpleParagraphBlock (SimpleParagraph -> SimpleBlock)
-> ParsecT Void Text Identity SimpleParagraph -> Parser SimpleBlock
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleParagraphType -> ParsecT Void Text Identity SimpleParagraph
simpleParagraphP (NamedType SimpleParagraphType -> SimpleParagraphType
forall t. NamedType t -> t
unwrapNT NamedType SimpleParagraphType
parT)