Skip to content

Commit d7d252f

Browse files
committed
Merge branch 'main' into cleanup-main
2 parents 0d60621 + 2dbd704 commit d7d252f

File tree

99 files changed

+820
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+820
-273
lines changed

.github/workflows/Build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
stack-version: 'latest'
6666

6767
- name: "Cache dependencies"
68-
uses: actions/[email protected].2
68+
uses: actions/[email protected].3
6969
with:
7070
path: |
7171
~/.stack

code/drasil-code/lib/Language/Drasil/Chunk/CodeDefinition.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Language.Drasil.Chunk.CodeDefinition (
55

66
import Control.Lens ((^.), makeLenses, view)
77

8-
import Drasil.Database (HasUID (..))
8+
import Drasil.Database (HasUID(..), HasChunkRefs(..))
99
import Language.Drasil
1010

1111
import Drasil.Code.CodeExpr.Development (CodeExpr, expr, CanGenCode(..))
@@ -23,6 +23,9 @@ data CodeDefinition = CD { _cchunk :: CodeChunk
2323
}
2424
makeLenses ''CodeDefinition
2525

26+
instance HasChunkRefs CodeDefinition where
27+
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
28+
2629
-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeDefinition'.
2730
instance HasUID CodeDefinition where uid = cchunk . uid
2831
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeDefinition'.

code/drasil-code/lib/Language/Drasil/Chunk/NamedArgument.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ module Language.Drasil.Chunk.NamedArgument (
88

99
import Control.Lens ((^.), makeLenses, view)
1010

11-
import Drasil.Database (HasUID(..))
11+
import Drasil.Database (HasUID(..), HasChunkRefs(..))
1212
import Language.Drasil (HasSpace(..), HasSymbol(..),
1313
Idea(..), MayHaveUnit(..), NamedIdea(..), Quantity,
1414
DefinedQuantityDict, Concept, dqdWr, Definition (defn), ConceptDomain (cdom))
1515

1616
import Drasil.Code.Classes (IsArgumentName)
17+
1718
-- | Any quantity can be a named argument (wrapper for 'DefinedQuantityDict'),
1819
-- but with more of a focus on generating code arguments.
1920
newtype NamedArgument = NA {_qtd :: DefinedQuantityDict}
2021
makeLenses ''NamedArgument
2122

23+
instance HasChunkRefs NamedArgument where
24+
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
25+
2226
-- | Finds the 'UID' of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
2327
instance HasUID NamedArgument where uid = qtd . uid
2428
-- | Finds the term ('NP') of the 'DefinedQuantityDict' used to make the 'NamedArgument'.

code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Language.Drasil.Chunk.Parameter (
55

66
import Control.Lens ((^.), makeLenses, view)
77

8-
import Drasil.Database (HasUID(..))
8+
import Drasil.Database (HasUID(..), HasChunkRefs(..))
99
import Language.Drasil hiding (Ref)
1010

1111
import Language.Drasil.Chunk.Code (CodeIdea(..), CodeChunk)
@@ -18,6 +18,9 @@ data ParameterChunk = PC {_pcc :: CodeChunk
1818
, passBy :: PassBy}
1919
makeLenses ''ParameterChunk
2020

21+
instance HasChunkRefs ParameterChunk where
22+
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
23+
2124
-- | Finds the 'UID' of the 'CodeChunk' used to make the 'ParameterChunk'.
2225
instance HasUID ParameterChunk where uid = pcc . uid
2326
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'ParameterChunk'.

code/drasil-code/lib/Language/Drasil/Code/FileData.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{-# LANGUAGE PatternSynonyms #-}
2-
2+
{-# LANGUAGE MultiParamTypeClasses #-}
3+
{-# LANGUAGE FlexibleContexts #-}
34
-- | Defines the underlying data types used in the package extension.
45
module Language.Drasil.Code.FileData (FileAndContents(filePath, fileDoc),
5-
fileAndContents, fileDataToFileAndContents,
6+
fileAndContents, hasPathAndDocToFileAndContents,
67
PackageData(packageProg, packageAux), pattern PackageData
78
) where
89

910
import Text.PrettyPrint.HughesPJ (Doc, isEmpty)
10-
import qualified Drasil.GOOL as G (FileData(..), ModData(..))
11+
import Utils.Drasil (HasPathAndDoc(..))
1112

1213
-- | The underlying data type for auxiliary files in all renderers.
1314
data FileAndContents = FileAndContents {filePath :: FilePath, fileDoc :: Doc}
@@ -16,8 +17,12 @@ data FileAndContents = FileAndContents {filePath :: FilePath, fileDoc :: Doc}
1617
fileAndContents :: FilePath -> Doc -> FileAndContents
1718
fileAndContents = FileAndContents
1819

19-
fileDataToFileAndContents :: G.FileData -> FileAndContents
20-
fileDataToFileAndContents file = fileAndContents (G.filePath file) ((G.modDoc . G.fileMod) file)
20+
instance HasPathAndDoc FileAndContents Doc where
21+
getPath = filePath
22+
getDoc = fileDoc
23+
24+
hasPathAndDocToFileAndContents :: (HasPathAndDoc a Doc) => a -> FileAndContents
25+
hasPathAndDocToFileAndContents file = fileAndContents (getPath file) (getDoc file)
2126

2227
-- | The underlying data type for packages in all renderers.
2328
data PackageData a = PackD {packageProg :: a, packageAux :: [FileAndContents]}

code/drasil-code/lib/Language/Drasil/Code/Imperative/Generator.hs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import Data.Map (fromList, member, keys, elems)
1010
import Data.Maybe (maybeToList, catMaybes)
1111
import Data.Foldable (traverse_)
1212
import System.Directory (setCurrentDirectory, getCurrentDirectory)
13-
import System.FilePath.Posix (takeDirectory)
14-
import System.IO (hPutStrLn, hClose, openFile, IOMode(WriteMode))
1513
import Text.PrettyPrint.HughesPJ (isEmpty, vcat, render)
1614

1715
import Language.Drasil
@@ -23,7 +21,7 @@ import qualified Drasil.GProc as Proc (GSProgram, SFile, ProgramSym(..), unCI)
2321
import Language.Drasil.Printers (SingleLine(OneLine), sentenceDoc, piSys, plainConfiguration)
2422
import Language.Drasil.Printing.Import (spec)
2523
import Drasil.System
26-
import Utils.Drasil (createDirIfMissing)
24+
import Utils.Drasil (createDirIfMissing, createFile)
2725

2826
import Language.Drasil.Code.Imperative.ConceptMatch (chooseConcept)
2927
import Language.Drasil.Code.Imperative.Descriptions (unmodularDesc)
@@ -47,7 +45,7 @@ import Language.Drasil.Code.Imperative.GOOL.ClassInterface (
4745
makeSds, AuxiliarySym(..), package)
4846
import Language.Drasil.Code.Imperative.README (ReadMeInfo(..))
4947
import Language.Drasil.Code.FileData (PackageData(..), FileAndContents(..),
50-
fileAndContents, fileDataToFileAndContents)
48+
fileAndContents, hasPathAndDocToFileAndContents)
5149
import Language.Drasil.Code.FileNames(sampleInputName)
5250
import Language.Drasil.Code.ExtLibImport (auxMods, imports, modExports)
5351
import Language.Drasil.Code.Lang (Lang(..))
@@ -131,8 +129,10 @@ generateCode l unReprProg unReprPack g = do
131129
aux
132130
| l == Python = fileAndContents "__init__.py" mempty : baseAux
133131
| otherwise = baseAux
134-
packageFiles = map fileDataToFileAndContents (progMods $ packageProg $ unReprPack pckg) ++ aux
135-
traverse_ createFile packageFiles
132+
packageFiles = map
133+
hasPathAndDocToFileAndContents (progMods $ packageProg $ unReprPack pckg)
134+
++ aux
135+
traverse_ (\file -> createFile (filePath file) (render $ fileDoc file)) packageFiles
136136
setCurrentDirectory workingDir
137137

138138
-- | Generates a package, including a Makefile, sample input file, and Doxygen
@@ -243,8 +243,10 @@ generateCodeProc l unReprProg unReprPack g = do
243243
let (pckg, ds) = runState (genPackageProc unReprProg) g
244244
baseAux = [fileAndContents "designLog.txt" (ds ^. designLog) |
245245
not $ isEmpty $ ds ^. designLog] ++ packageAux (unReprPack pckg)
246-
packageFiles = map fileDataToFileAndContents (progMods (packageProg $ unReprPack pckg)) ++ baseAux
247-
traverse_ createFile packageFiles
246+
packageFiles = map
247+
hasPathAndDocToFileAndContents (progMods (packageProg $ unReprPack pckg))
248+
++ baseAux
249+
traverse_ (\file -> createFile (filePath file) (render $ fileDoc file)) packageFiles
248250
setCurrentDirectory workingDir
249251

250252
-- | Generates a package, including a Makefile, sample input file, and Doxygen
@@ -338,17 +340,6 @@ genModulesProc = do
338340
if con then error "genModulesProc: Procedural renderers do not support classes"
339341
else return $ mn : inp ++ cal : out ++ moddef
340342

341-
-- | Helper to convert a FileAndContents into a real file with the given document
342-
-- at the given FilePath
343-
createFile :: FileAndContents -> IO ()
344-
createFile file = do
345-
let path = filePath file
346-
contents = fileDoc file
347-
createDirIfMissing True (takeDirectory path)
348-
h <- openFile path WriteMode
349-
hPutStrLn h (render contents)
350-
hClose h
351-
352343
-- | Private utilities used in 'generateCode'.
353344
getDir :: Lang -> String
354345
getDir Cpp = "cpp"

code/drasil-code/lib/Language/Drasil/GOOL.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
-- | Re-export code-related smart constructors for external code writing and generation.
44
module Language.Drasil.GOOL (
55
AuxiliarySym(..), package,
6-
FileAndContents(..), fileDataToFileAndContents,
6+
FileAndContents(..), hasPathAndDocToFileAndContents,
77
PackageData(..), pattern PackageData,
88
unPP, unJP, unCSP, unCPPP, unSP, unJLP
99
) where
1010

1111
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (AuxiliarySym(..),
1212
package)
1313
import Language.Drasil.Code.FileData (FileAndContents(..),
14-
fileDataToFileAndContents, PackageData(..), pattern PackageData)
14+
hasPathAndDocToFileAndContents, PackageData(..), pattern PackageData)
1515

1616
import Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.PythonRenderer (unPP)
1717
import Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.JavaRenderer (unJP)

code/drasil-code/test/Main.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import qualified Drasil.GProc as Proc (unCI, ProgramSym(..))
1111

1212
import Language.Drasil.Code (ImplementationType(..), makeSds)
1313
import Language.Drasil.GOOL (AuxiliarySym(..), package,
14-
fileDataToFileAndContents, PackageData(..), pattern PackageData, unPP, unJP,
15-
unCSP, unCPPP, unSP, unJLP)
14+
hasPathAndDocToFileAndContents, PackageData(..), pattern PackageData,
15+
unPP, unJP, unCSP, unCPPP, unSP, unJLP)
1616
import qualified Language.Drasil.GOOL as D (filePath, FileAndContents(..))
1717

1818
import Utils.Drasil (createDirIfMissing)
@@ -68,7 +68,8 @@ genCode :: [PackageData ProgData] -> IO()
6868
genCode files =
6969
createCodeFiles $ files >>= \(PackageData prog aux) ->
7070
let label = progName prog
71-
modCode = progMods prog <&> \modFileData -> (label, fileDataToFileAndContents modFileData)
71+
modCode = progMods prog <&> \modFileData ->
72+
(label, hasPathAndDocToFileAndContents modFileData)
7273
auxCode = aux <&> (label,)
7374
in modCode ++ auxCode
7475

code/drasil-data/lib/Data/Drasil/Theories/Physics.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Utils.Drasil (weave)
66
import Theory.Drasil
77
import qualified Language.Drasil.Sentence.Combinators as S
88

9-
import Data.Drasil.Citations (velocityWiki, accelerationWiki)
9+
import Data.Drasil.Citations (velocityWiki, accelerationWiki, hibbeler2004)
1010
import Data.Drasil.Concepts.Documentation (component, material_, value, constant)
1111
import Data.Drasil.Concepts.Math (cartesian, equation, vector)
1212
import Data.Drasil.Concepts.Physics (gravity, twoD, rigidBody)
@@ -25,9 +25,9 @@ physicsTMs = [newtonSL]
2525
-- * Newton's Second Law of Motion
2626

2727
newtonSL :: TheoryModel
28-
newtonSL = tmNoRefs (equationalModelU "newtonSL" newtonSLQD)
28+
newtonSL = tm (equationalModelU "newtonSL" newtonSLQD)
2929
[dqdWr QP.force, dqdWr QPP.mass, dqdWr QP.acceleration] ([] :: [ConceptChunk])
30-
[newtonSLQD] [] [] "NewtonSecLawMot" [newtonSLDesc]
30+
[newtonSLQD] [] [] [dRef hibbeler2004] "NewtonSecLawMot" [newtonSLDesc]
3131

3232
-- * Weight
3333

@@ -123,9 +123,10 @@ vecMag = ddENoRefs vecMagQD Nothing "vecMag" [magNote]
123123
-- * Newton's Second Law of Rotational Motion
124124

125125
newtonSLR :: TheoryModel
126-
newtonSLR = tmNoRefs (equationalModelU "newtonSLR" newtonSLRQD)
126+
newtonSLR = tm (equationalModelU "newtonSLR" newtonSLRQD)
127127
[dqdWr QP.torque, dqdWr QP.momentOfInertia, dqdWr QP.angularAccel]
128-
([] :: [ConceptChunk]) [newtonSLRQD] [] [] "NewtonSecLawRotMot" newtonSLRNotes
128+
([] :: [ConceptChunk]) [newtonSLRQD] [] [] [dRef hibbeler2004]
129+
"NewtonSecLawRotMot" newtonSLRNotes
129130

130131
newtonSLRQD :: ModelQDef
131132
newtonSLRQD = mkQuantDef' QP.torque (nounPhraseSP "Newton's second law for rotational motion") newtonSLRExpr

code/drasil-database/lib/Drasil/Database/Chunk.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
module Drasil.Database.Chunk (
1010
Chunk,
1111
IsChunk,
12+
TypeableChunk,
1213
HasChunkRefs(..),
1314
mkChunk, -- FIXME: mkChunk should not be exported but is temporarily because this module is NOT in `drasil-database`
1415
unChunk,
@@ -24,11 +25,21 @@ import GHC.Generics (Generic (Rep, from), M1 (..), K1 (..), type (:*:) (..),
2425
import Drasil.Database.UID (HasUID (..), UID)
2526

2627
-- | Constraint for anything that may be considered a valid chunk type.
27-
type IsChunk a = (HasUID a, HasChunkRefs a, Typeable a)
28+
type IsChunk a = (HasUID a, HasChunkRefs a)
29+
30+
-- | Constraint for anything that may be considered a valid chunk type, and is
31+
-- also 'Typeable'. Type-ability is necessary for storing/retrieving chunks
32+
-- in/from the 'ChunkDB'.
33+
--
34+
-- 'TypeableChunk' is meant to be a purely /internal/ concept; users of Drasil
35+
-- should only ever need to use 'IsChunk'. 'Typeable' is automatically derived
36+
-- by GHC, but can cause issues with type inference if used directly in user
37+
-- code, especially when involving parameterized chunk types.
38+
type TypeableChunk a = (IsChunk a, Typeable a)
2839

2940
-- | A piece of reusable knowledge, with an internal identifier ('UID'),
3041
-- possibly dependant on other chunks.
31-
data Chunk = forall a. IsChunk a => Chunk a
42+
data Chunk = forall a. TypeableChunk a => Chunk a
3243

3344
instance Eq Chunk where
3445
(==) :: Chunk -> Chunk -> Bool
@@ -43,7 +54,7 @@ instance HasChunkRefs Chunk where
4354
chunkRefs (Chunk c) = chunkRefs c
4455

4556
-- | Create a 'Chunk', ensuring that 'Chunk's are never placed within 'Chunk's.
46-
mkChunk :: IsChunk a => a -> Chunk
57+
mkChunk :: TypeableChunk a => a -> Chunk
4758
mkChunk a
4859
| typeOf a == typeRep (Proxy @Chunk) = error "Cannot place a Chunk inside of a Chunk"
4960
| otherwise = Chunk a

0 commit comments

Comments
 (0)