mdoc-0.1.0.0: src/Mdoc/Gen/Config.hs
-- |
--
-- Module : Mdoc.Gen.Config
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Gen.Config
( Config (..)
, renderConfig
-- * Schema
, Schema (..)
) where
import Mdoc.Prelude
import Data.List (intercalate)
import Mdoc.MacroArg
import Mdoc.MacroName
data Config = Config
{ name :: String
, schema :: Schema
, exampleLines :: Maybe (NonEmpty String)
}
deriving stock (Eq, Show)
renderConfig :: Config -> [MacroArg]
renderConfig c =
[ Callable Cm
, Bare $ esc $ pack c.name
, Callable Ns
, ":"
]
<> schemaArgs c.schema
data Schema
= Simple Text
| AnyOf [Schema]
| ListOf Schema
| Object Text Schema
deriving stock (Eq, Show)
instance IsString Schema where
fromString = Simple . pack
schemaArgs :: Schema -> [MacroArg]
schemaArgs = \case
Simple t -> [Callable Ar, Bare $ esc t]
AnyOf ss -> intercalate [Callable Ns, "|", Callable Ns] $ map schemaArgs ss
ListOf s@(AnyOf {}) -> ["("] <> schemaArgs s <> [")", Callable Ns, "[]"]
ListOf s -> schemaArgs s <> [Callable Ns, "[]"]
Object k s -> ["{", Callable Ar, Bare $ esc k, ","] <> schemaArgs s <> ["}"]