-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
562 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Auto-generation of command attributes matrix. | ||
module Swarm.Doc.Wiki.Matrix where | ||
|
||
import Data.List.NonEmpty qualified as NE | ||
import Data.Text qualified as T | ||
import Swarm.Doc.Command | ||
import Text.Pandoc | ||
import Text.Pandoc.Builder | ||
|
||
commandsMatrix :: Pandoc | ||
commandsMatrix = | ||
setTitle (text "Commands matrix") $ | ||
doc (header 3 (text "Commands matrix")) | ||
<> doc (makePropsTable ["Command", "Effects", "Actor Target", "Type"]) | ||
|
||
makePropsTable :: | ||
[T.Text] -> | ||
Blocks | ||
makePropsTable headingsList = | ||
simpleTable headerRow $ map genPropsRow catalogEntries | ||
where | ||
CommandCatalog catalogEntries = getCatalog | ||
headerRow = map (plain . text) headingsList | ||
|
||
genPropsRow :: CommandEntry -> [Blocks] | ||
genPropsRow e = | ||
[ showCode (cmd e) | ||
, showCode (effects e) | ||
, showCode (hasActorTarget $ derivedAttrs e) | ||
] | ||
<> NE.toList completeTypeMembers | ||
where | ||
showCode :: Show a => a -> Blocks | ||
showCode = plain . code . T.pack . show | ||
completeTypeMembers = NE.map showCode $ argTypes e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Utilities for generating doc markup | ||
module Swarm.Doc.Wiki.Util where | ||
|
||
import Control.Arrow (left) | ||
import Data.Text (Text) | ||
import Text.Pandoc | ||
|
||
pandocToText :: Pandoc -> Either Text Text | ||
pandocToText = | ||
left renderError | ||
. runPure | ||
. writeMarkdown (def {writerExtensions = extensionsFromList [Ext_pipe_tables]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Auto-generation of command attributes matrix. | ||
module Swarm.Doc.Command where | ||
|
||
import Data.Aeson (ToJSON) | ||
import Data.List.NonEmpty qualified as NE | ||
import GHC.Generics (Generic) | ||
import Servant.Docs qualified as SD | ||
import Swarm.Doc.Util | ||
import Swarm.Language.Pretty (unchainFun) | ||
import Swarm.Language.Syntax | ||
import Swarm.Language.Syntax.CommandMetadata | ||
import Swarm.Language.Typecheck (inferConst) | ||
import Swarm.Language.Types | ||
|
||
data DerivedAttrs = DerivedAttrs | ||
{ hasActorTarget :: Bool | ||
, pureComputation :: Bool | ||
} | ||
deriving (Generic, ToJSON) | ||
|
||
data CommandEntry = CommandEntry | ||
{ cmd :: Const | ||
, effects :: CommandEffect | ||
, argTypes :: NE.NonEmpty Type | ||
, derivedAttrs :: DerivedAttrs | ||
} | ||
deriving (Generic, ToJSON) | ||
|
||
newtype CommandCatalog = CommandCatalog | ||
{ entries :: [CommandEntry] | ||
} | ||
deriving (Generic, ToJSON) | ||
|
||
instance SD.ToSample CommandCatalog where | ||
toSamples _ = SD.noSamples | ||
|
||
mkEntry :: Const -> CommandEntry | ||
mkEntry c = | ||
CommandEntry c cmdEffects rawArgs $ | ||
DerivedAttrs | ||
(operatesOnActor inputArgs) | ||
(cmdEffects == Computation) | ||
where | ||
cmdInfo = constInfo c | ||
cmdEffects = effectInfo $ constDoc cmdInfo | ||
|
||
getArgs ((Forall _ t)) = unchainFun t | ||
|
||
rawArgs = getArgs $ inferConst c | ||
|
||
inputArgs = NE.init rawArgs | ||
outputType = NE.last rawArgs | ||
|
||
operatesOnActor = elem TyActor | ||
|
||
getCatalog :: CommandCatalog | ||
getCatalog = CommandCatalog $ map mkEntry commands |
Oops, something went wrong.