Skip to content

Commit

Permalink
Merge pull request #3950 from JacquesCarette/expandREADME
Browse files Browse the repository at this point in the history
Implement Proposal #3948: Enhance README Generation
  • Loading branch information
JacquesCarette authored Oct 2, 2024
2 parents 89ffe66 + 10ae63b commit 8490ac2
Show file tree
Hide file tree
Showing 89 changed files with 917 additions and 290 deletions.
7 changes: 4 additions & 3 deletions code/drasil-code/lib/Language/Drasil/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module Language.Drasil.Code (
OptionalFeatures(..), makeOptFeats, ExtLib(..), ImplementationType(..), Logging(..),
Modularity(..), Structure(..), ConstantStructure(..), ConstantRepr(..),
CodeConcept(..), matchConcepts, SpaceMatch, matchSpaces, AuxFile(..),
getSampleData, Visibility(..), defaultChoices, CodeSpec(..), funcUID, asVC,
codeSpec, ($:=), Mod(Mod), StateVariable, Func, FuncStmt(..), pubStateVar,
getSampleData, Visibility(..), defaultChoices, CodeSpec(..), OldCodeSpec(..), codeSpec,
HasOldCodeSpec(..), funcUID, asVC, ($:=), Mod(Mod), StateVariable, Func, FuncStmt(..), pubStateVar,
privStateVar, fDecDef, ffor, fforRange, funcData, funcDef, packmod,
junkLine, multiLine, repeated, singleLine, singleton,
ExternalLibrary, Step, FunctionInterface, Argument, externalLib, choiceSteps,
Expand Down Expand Up @@ -93,7 +93,8 @@ import Language.Drasil.Choices (Choices(..), Comments(..), Verbosity(..),
makeDocConfig, makeLogConfig, LogConfig(..), OptionalFeatures(..),
makeOptFeats, ExtLib(..))

import Language.Drasil.CodeSpec (CodeSpec(..), funcUID, asVC, codeSpec)
import Language.Drasil.CodeSpec (CodeSpec(..), OldCodeSpec(..), HasOldCodeSpec(..),
codeSpec, funcUID, asVC)

import Language.Drasil.Mod (($:=), Mod(Mod), StateVariable, Func, FuncStmt(..),
pubStateVar, privStateVar, fDecDef, ffor, fforRange, funcData, funcDef, packmod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Language.Drasil.Code.Imperative.Comments (
import Language.Drasil
import Database.Drasil (defTable)
import Language.Drasil.Code.Imperative.DrasilState (GenState, DrasilState(..))
import Language.Drasil.CodeSpec (CodeSpec(..))
import Language.Drasil.CodeSpec (HasOldCodeSpec(..))
import Language.Drasil.Printers (SingleLine(OneLine), sentenceDoc, unitDoc)

import qualified Data.Map as Map (lookup)
Expand All @@ -18,7 +18,7 @@ import Text.PrettyPrint.HughesPJ (Doc, (<+>), colon, empty, parens, render)
getTermDoc :: (CodeIdea c) => c -> GenState Doc
getTermDoc c = do
g <- get
let db = sysinfodb $ codeSpec g
let db = codeSpec g ^. sysinfodbO
return $ sentenceDoc db Implementation OneLine $ phraseNP $ codeChunk c ^. term

-- | Gets a plain rendering of the definition of a chunk, preceded by a colon
Expand All @@ -27,7 +27,7 @@ getTermDoc c = do
getDefnDoc :: (CodeIdea c) => c -> GenState Doc
getDefnDoc c = do
g <- get
let db = sysinfodb $ codeSpec g
let db = codeSpec g ^. sysinfodbO
return $ maybe empty ((<+>) colon . sentenceDoc db Implementation OneLine .
(^. defn) . fst) (Map.lookup (codeChunk c ^. uid) $ defTable db)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Language.Drasil.Code.Imperative.DrasilState (GenState, DrasilState(..),
genICName)
import Language.Drasil.Choices (ImplementationType(..), Structure(..),
InternalConcept(..))
import Language.Drasil.CodeSpec (CodeSpec(..))
import Language.Drasil.CodeSpec (HasOldCodeSpec(..))
import Language.Drasil.Mod (Description)
import Language.Drasil.Printers (SingleLine(OneLine), sentenceDoc)

Expand All @@ -24,6 +24,7 @@ import qualified Data.Map as Map (filter, lookup, null)
import Data.Maybe (mapMaybe)
import Control.Lens ((^.))
import Control.Monad.State (get)
import SysInfo.Drasil hiding (sysinfodb)

-- | Returns a module description based on a list of descriptions of what is
-- contained in the module.
Expand All @@ -39,8 +40,8 @@ unmodularDesc = do
let spec = codeSpec g
implTypeStr Program = "program"
implTypeStr Library = "library"
return $ show $ sentenceDoc (sysinfodb spec) Implementation OneLine $ capSent $
foldlSent ([S "a", S (implTypeStr (implType g)), S "to"] ++ purpose spec)
return $ show $ sentenceDoc (spec ^. sysinfodbO) Implementation OneLine $ capSent $
foldlSent ([S "a", S (implTypeStr (implType g)), S "to"] ++ codeSpec g ^. purpose)

-- | Returns description of what is contained in the Input Parameters module.
-- If user chooses the 'Bundled' input parameter, this module will include the structure for holding the
Expand Down Expand Up @@ -121,7 +122,7 @@ constModDesc = do
let cDesc [] = ""
cDesc _ = "the structure for holding constant values"
return $ cDesc $ filter (flip member (Map.filter (cname ==)
(clsMap g)) . codeName) (constants $ codeSpec g)
(clsMap g)) . codeName) (codeSpec g ^. constantsO)

-- | Returns a description of what is contained in the Output Format module,
-- if it exists.
Expand All @@ -145,9 +146,9 @@ inputClassDesc = do
inIPMap = filter ((`member` ipMap) . codeName)
inClassD True = ""
inClassD _ = "Structure for holding the " ++ stringList [
inPs $ inIPMap $ extInputs $ codeSpec g,
dVs $ inIPMap $ map quantvar $ derivedInputs $ codeSpec g,
cVs $ inIPMap $ map quantvar $ constants $ codeSpec g]
inPs $ inIPMap $ codeSpec g ^. extInputsO,
dVs $ inIPMap $ map quantvar $ codeSpec g ^. derivedInputsO,
cVs $ inIPMap $ map quantvar $ codeSpec g ^. constantsO]
inPs [] = ""
inPs _ = "input values"
dVs [] = ""
Expand All @@ -166,7 +167,7 @@ constClassDesc = do
let ccDesc [] = ""
ccDesc _ = "Structure for holding the constant values"
return $ ccDesc $ filter (flip member (Map.filter (cname ==)
(clsMap g)) . codeName) (constants $ codeSpec g)
(clsMap g)) . codeName) (codeSpec g ^. constantsO)

-- | Returns a description for the generated function that reads input from a
-- file, if it exists.
Expand Down Expand Up @@ -220,8 +221,8 @@ woFuncDesc = do
physAndSfwrCons :: GenState Description
physAndSfwrCons = do
g <- get
let cns = concat $ mapMaybe ((`Map.lookup` (cMap $ codeSpec g)) . (^. uid))
(inputs $ codeSpec g)
let cns = concat $ mapMaybe ((`Map.lookup` (codeSpec g ^. cMapO)) . (^. uid))
(codeSpec g ^. inputsO)
return $ stringList [
if not (any isPhysC cns) then "" else "physical constraints",
if not (any isSfwrC cns) then "" else "software constraints"]
36 changes: 18 additions & 18 deletions code/drasil-code/lib/Language/Drasil/Code/Imperative/DrasilState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Language.Drasil.Choices (Choices(..), Architecture (..), DataInfo(..),
MatchedConceptMap, ConstantRepr, ConstantStructure(..), ConstraintBehaviour, Logging,
Structure(..), InternalConcept(..))
import Language.Drasil.CodeSpec (Input, Const, Derived, Output, Def,
CodeSpec(..), getConstraints)
CodeSpec(..), OldCodeSpec(..), getConstraints)
import Language.Drasil.Mod (Mod(..), Name, Version, Class(..),
StateVariable(..), fname)

Expand Down Expand Up @@ -100,23 +100,23 @@ addLoggedSpace s t = over loggedSpaces ((s,t):)

-- | Builds the module export map, mapping each function and state variable name
-- in the generated code to the name of the generated module that exports it.
modExportMap :: CodeSpec -> Choices -> [Mod] -> ModExportMap
modExportMap cs@CodeSpec {
pName = prn,
inputs = ins,
extInputs = extIns,
derivedInputs = ds,
constants = cns
modExportMap :: OldCodeSpec -> Choices -> [Mod] -> ModExportMap
modExportMap cs@OldCodeSpec {
_pName = prn,
_inputs = ins,
_extInputs = extIns,
_derivedInputs = ds,
_constants = cns
} chs@Choices {
architecture = m
} ms = fromList $ nubOrd $ concatMap mpair ms
++ getExpInput prn chs ins
++ getExpConstants prn chs cns
++ getExpDerived prn chs ds
++ getExpConstraints prn chs (getConstraints (cMap cs) ins)
++ getExpConstraints prn chs (getConstraints (_cMap cs) ins)
++ getExpInputFormat prn chs extIns
++ getExpCalcs prn chs (execOrder cs)
++ getExpOutput prn chs (outputs cs)
++ getExpCalcs prn chs (_execOrder cs)
++ getExpOutput prn chs (_outputs cs)
where mpair (Mod n _ _ cls fs) = map
(, defModName (modularity m) n)
(map className cls
Expand All @@ -127,17 +127,17 @@ modExportMap cs@CodeSpec {

-- | Builds the class definition map, mapping each generated method and state
-- variable name to the name of the generated class where it is defined.
clsDefMap :: CodeSpec -> Choices -> [Mod] -> ClassDefinitionMap
clsDefMap cs@CodeSpec {
inputs = ins,
extInputs = extIns,
derivedInputs = ds,
constants = cns
clsDefMap :: OldCodeSpec -> Choices -> [Mod] -> ClassDefinitionMap
clsDefMap cs@OldCodeSpec {
_inputs = ins,
_extInputs = extIns,
_derivedInputs = ds,
_constants = cns
} chs ms = fromList $ nub $ concatMap modClasses ms
++ getInputCls chs ins
++ getConstantsCls chs cns
++ getDerivedCls chs ds
++ getConstraintsCls chs (getConstraints (cMap cs) ins)
++ getConstraintsCls chs (getConstraints (_cMap cs) ins)
++ getInputFormatCls chs extIns
where modClasses (Mod _ _ _ cls _) = concatMap (\cl ->
let cln = className cl in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
-- | Defines a package extension for GOOL, with functions for pairing a GOOL
-- program with auxiliary, non-source-code files.
module Language.Drasil.Code.Imperative.GOOL.ClassInterface (
ReadMeInfo(..),
-- Typeclasses
PackageSym(..), AuxiliarySym(..)
) where

import Language.Drasil (Expr)
import Database.Drasil (ChunkDB)
import Language.Drasil.Code.DataDesc (DataDesc)
import Language.Drasil.Mod (Name, Version)
import Language.Drasil.Choices (Comments, ImplementationType, Verbosity)
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))

import Drasil.GOOL (ProgData, GOOLState)

Expand Down Expand Up @@ -41,36 +40,3 @@ class AuxiliarySym r where

auxHelperDoc :: r (AuxHelper r) -> Doc
auxFromData :: FilePath -> Doc -> r (Auxiliary r)

-- | Language name.
type LangAbbrev = String
-- | Programming language version.
type LangVers = String
-- | Case name.
type CaseName = String
-- | Purpose of example
type ExamplePurpose = String
-- | Description of example
type ExampleDescr = String
-- | File contributors
type Contributor = String
-- | Input File
type InFile = String -- TODO: There may not always be an Input/Output File
-- | Output File
type OutFile = String
-- | Holds all information needed to create a README file.
data ReadMeInfo = ReadMeInfo {
langName :: LangAbbrev,
langVersion :: LangVers,
invalidOS :: Maybe String,
implementType :: ImplementationType,
extLibNV :: [(Name,Version)],
extLibFP :: [FilePath],
contributors :: [Contributor],
configFP :: [FilePath],
caseName :: CaseName,
examplePurpose :: ExamplePurpose,
exampleDescr :: ExampleDescr,
folderNum :: Int,
inputOutput :: (InFile, OutFile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.CSharpRenderer (
) where

import Language.Drasil.Choices (ImplementationType(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (doxConfig, readMe, sampleInput, makefile, noRunIfLib, doxDocConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.CppRenderer (
) where

import Language.Drasil.Choices (ImplementationType(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (doxConfig, readMe, sampleInput, makefile, noRunIfLib, doxDocConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.JavaRenderer (
) where

import Language.Drasil.Choices (ImplementationType(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (doxConfig, readMe, sampleInput, makefile, noRunIfLib, doxDocConfig, docIfEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.JuliaRenderer (
JuliaProject(..)
) where

import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (sampleInput, readMe, makefile, noRunIfLib, docIfEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import Language.Drasil.Code.Imperative.WriteReadMe (makeReadMe)
import Language.Drasil.Code.Imperative.GOOL.LanguageRenderer (doxConfigName,
makefileName, sampleInputName, readMeName)

import Language.Drasil.Code.Imperative.GOOL.ClassInterface ( ReadMeInfo(..),
AuxiliarySym(Auxiliary, AuxHelper, auxHelperDoc, auxFromData))

import Language.Drasil.Code.Imperative.GOOL.ClassInterface (AuxiliarySym(Auxiliary, AuxHelper, auxHelperDoc, auxFromData))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
-- | Defines a Doxygen configuration file.
doxConfig :: (AuxiliarySym r) => r (AuxHelper r) -> String ->
GOOLState -> Verbosity -> r (Auxiliary r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.PythonRenderer (
PythonProject(..)
) where

import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),PackageSym(..),
AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))

import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (doxConfig, readMe, sampleInput, makefile, noRunIfLib, doxDocConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.SwiftRenderer (
) where

import Language.Drasil.Choices (ImplementationType(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))

import qualified
Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
G (sampleInput, readMe, makefile, noRunIfLib, docIfEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Language.Drasil.Code.Imperative.GenerateGOOL (ClassType(..),

import Language.Drasil hiding (List)
import Language.Drasil.Code.Imperative.DrasilState (GenState, DrasilState(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),
AuxiliarySym(..))
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
import Language.Drasil.Choices (Comments(..), AuxFile(..))
import Language.Drasil.CodeSpec (CodeSpec(..))
import Language.Drasil.CodeSpec (HasOldCodeSpec(..))
import Language.Drasil.Mod (Name, Description, Import)

import Drasil.GOOL (VSType, SVariable, SValue, MSStatement, SMethod,
Expand All @@ -26,6 +26,7 @@ import Data.Bifunctor (second)
import qualified Data.Map as Map (lookup)
import Data.Maybe (catMaybes)
import Control.Monad.State (get, modify)
import Control.Lens ((^.))

-- | Defines a GOOL module. If the user chose 'CommentMod', the module will have
-- Doxygen comments. If the user did not choose 'CommentMod' but did choose
Expand All @@ -38,8 +39,7 @@ genModuleWithImports :: (OOProg r) => Name -> Description -> [Import] ->
genModuleWithImports n desc is maybeMs maybeCs = do
g <- get
modify (\s -> s { currentModule = n })
-- Below line of code cannot be simplified because authors has a generic type
let as = case codeSpec g of CodeSpec {authors = a} -> map name a
let as = map name (codeSpec g ^. authorsO )
cs <- sequence maybeCs
ms <- sequence maybeMs
let commMod | CommentMod `elem` commented g = OO.docMod desc
Expand All @@ -59,7 +59,7 @@ genModule n desc = genModuleWithImports n desc []
genDoxConfig :: (AuxiliarySym r) => GOOLState -> GenState (Maybe (r (Auxiliary r)))
genDoxConfig s = do
g <- get
let n = pName $ codeSpec g
let n = codeSpec g ^. pNameO
cms = commented g
v = doxOutput g
return $ if not (null cms) then Just (doxConfig n s v) else Nothing
Expand All @@ -68,7 +68,7 @@ genDoxConfig s = do
genReadMe :: (AuxiliarySym r) => ReadMeInfo -> GenState (Maybe (r (Auxiliary r)))
genReadMe rmi = do
g <- get
let n = pName $ codeSpec g
let n = codeSpec g ^. pNameO
return $ getReadMe (auxiliaries g) rmi {caseName = n}

-- | Helper for generating a README file.
Expand Down Expand Up @@ -179,8 +179,7 @@ genModuleWithImportsProc :: (ProcProg r) => Name -> Description -> [Import] ->
genModuleWithImportsProc n desc is maybeMs = do
g <- get
modify (\s -> s { currentModule = n })
-- Below line of code cannot be simplified because authors has a generic type
let as = case codeSpec g of CodeSpec {authors = a} -> map name a
let as = map name (codeSpec g ^. authorsO )
ms <- sequence maybeMs
let commMod | CommentMod `elem` commented g = Proc.docMod desc
as (date g)
Expand Down
Loading

0 comments on commit 8490ac2

Please sign in to comment.