Skip to content

Commit 02921f7

Browse files
committed
Implement HasChunkRefs for DQD, UnitalChunk, and CI
1 parent 092f539 commit 02921f7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

code/drasil-lang/lib/Language/Drasil/Chunk/CommonIdea.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Language.Drasil.Chunk.CommonIdea (
1414
import Control.Lens (makeLenses, (^.), view)
1515

1616
import Drasil.Database (UID, HasUID(uid), HasChunkRefs(..))
17+
import qualified Data.Set as Set
1718
import Utils.Drasil (repUnd)
1819

1920
import Language.Drasil.Chunk.NamedIdea (IdeaDict, nc)
@@ -31,7 +32,11 @@ data CI = CI { _nc' :: IdeaDict, _ab :: String, cdom' :: [UID]}
3132
makeLenses ''CI
3233

3334
instance HasChunkRefs CI where
34-
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
35+
chunkRefs c = Set.unions
36+
[ chunkRefs (c ^. nc')
37+
, Set.fromList (cdom c)
38+
]
39+
{-# INLINABLE chunkRefs #-}
3540

3641
-- | Finds 'UID' of the 'IdeaDict' used to make the 'CI'.
3742
instance HasUID CI where uid = nc' . uid

code/drasil-lang/lib/Language/Drasil/Chunk/DefinedQuantity.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Language.Drasil.Chunk.DefinedQuantity (
1313
import Control.Lens ((^.), makeLenses, view, Getter)
1414

1515
import Drasil.Database (HasChunkRefs(..), HasUID(..))
16+
import qualified Data.Set as Set
1617

1718
import Language.Drasil.Symbol (HasSymbol(symbol), Symbol (Empty))
1819
import Language.Drasil.Classes (NamedIdea(term), Idea(getA), Concept, Express(..),
@@ -42,7 +43,11 @@ class DefinesQuantity d where
4243
defLhs :: Getter d DefinedQuantityDict
4344

4445
instance HasChunkRefs DefinedQuantityDict where
45-
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
46+
chunkRefs d = Set.unions
47+
[ chunkRefs (d ^. con)
48+
, chunkRefs (d ^. unit')
49+
]
50+
{-# INLINABLE chunkRefs #-}
4651

4752
-- | Finds the 'UID' of the 'ConceptChunk' used to make the 'DefinedQuantityDict'.
4853
instance HasUID DefinedQuantityDict where uid = con . uid

code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Language.Drasil.Chunk.Unital (
99
import Control.Lens (makeLenses, view, (^.))
1010

1111
import Drasil.Database (HasUID(..), HasChunkRefs(..))
12+
import qualified Data.Set as Set
1213

1314
import Language.Drasil.Chunk.Concept (dccWDS,cw)
1415
import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr)
@@ -34,7 +35,11 @@ data UnitalChunk = UC { _defq' :: DefinedQuantityDict
3435
makeLenses ''UnitalChunk
3536

3637
instance HasChunkRefs UnitalChunk where
37-
chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.
38+
chunkRefs u = Set.unions
39+
[ chunkRefs (u ^. defq')
40+
, chunkRefs (u ^. uni)
41+
]
42+
{-# INLINABLE chunkRefs #-}
3843

3944
-- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'UnitalChunk'.
4045
instance HasUID UnitalChunk where uid = defq' . uid

0 commit comments

Comments
 (0)