55-- Over time, we'll want to have a cleaner separation, but doing that
66-- all at once would break too much for too long. So we start here
77-- instead.
8- module Drasil.DocumentLanguage where
8+ module Drasil.DocumentLanguage ( mkDoc , fillcdbSRS , findAllRefs ) where
99
1010import Control.Lens ((^.) , set )
1111import Data.Function (on )
@@ -16,6 +16,7 @@ import qualified Data.Map as Map (elems, assocs, keys)
1616import Utils.Drasil (invert )
1717
1818import Drasil.DocDecl (SRSDecl , mkDocDesc )
19+ import qualified Drasil.DocDecl as DD
1920import Drasil.DocumentLanguage.Core (AppndxSec (.. ), AuxConstntSec (.. ),
2021 DerivationDisplay (.. ), DocDesc , DocSection (.. ), OffShelfSolnsSec (.. ), GSDSec (.. ),
2122 GSDSub (.. ), IntroSec (.. ), IntroSub (.. ), LCsSec (.. ), LFunc (.. ),
@@ -39,7 +40,7 @@ import Drasil.System
3940import Drasil.GetChunks (ccss , ccss' , citeDB )
4041
4142import Drasil.Sections.TableOfAbbAndAcronyms (tableAbbAccGen )
42- import Drasil.Sections.TableOfContents (toToC , findToC )
43+ import Drasil.Sections.TableOfContents (toToC )
4344import Drasil.Sections.TableOfSymbols (table , tsIntro )
4445import Drasil.Sections.TableOfUnits (tOfUnitSIName , tuIntro , defaultTUI )
4546import qualified Drasil.DocLang.SRS as SRS (appendix ,
@@ -72,12 +73,10 @@ import qualified Data.Drasil.Concepts.Documentation as Doc (likelyChg, section_,
7273-- * Main Function
7374
7475-- | Creates a document from a document description, a title combinator function, and system information.
75- mkDoc :: SRSDecl -> (IdeaDict -> IdeaDict -> Sentence ) -> System -> Document
76- mkDoc dd comb si@ SI {_sys = sys, _authors = docauthors} =
77- Document (whatsTheBigIdea si `comb` nw sys) (foldlList Comma List $ map (S . name) docauthors) (findToC l) $
78- mkSections si l
79- where
80- l = mkDocDesc si dd
76+ mkDoc :: SRSDecl -> (IdeaDict -> IdeaDict -> Sentence ) -> (System , DocDesc ) -> Document
77+ mkDoc srs comb (si@ SI {_sys = sys, _authors = docauthors}, dd) =
78+ Document (whatsTheBigIdea si `comb` nw sys) (foldlList Comma List $ map (S . name) docauthors)
79+ (findToC srs) $ mkSections si dd
8180
8281-- * Functions to Fill 'ChunkDB'
8382
@@ -90,17 +89,23 @@ mkDoc dd comb si@SI {_sys = sys, _authors = docauthors} =
9089-- | Assuming a given 'ChunkDB' with no traces and minimal/no references, fill
9190-- in for rest of system information. Currently fills in references,
9291-- traceability matrix information and 'IdeaDict's.
93- fillcdbSRS :: SRSDecl -> System -> System
94- fillcdbSRS srsDec si = fillSecAndLC srsDec $ fillReferences srsDec $ fillTraceSI srsDec si
92+ fillcdbSRS :: SRSDecl -> System -> (System , DocDesc )
93+ fillcdbSRS srsDec si =
94+ (fillSecAndLC dd $ fillReferences sections $ fillTraceSI dd si , dd)
95+ where
96+ dd :: DocDesc
97+ dd = mkDocDesc si srsDec
98+ sections :: [Section ]
99+ sections = mkSections si dd
95100
96101-- | Fill in the 'Section's and 'LabelledContent' maps of the 'ChunkDB' from the 'SRSDecl'.
97- fillSecAndLC :: SRSDecl -> System -> System
102+ fillSecAndLC :: DocDesc -> System -> System
98103fillSecAndLC dd si = si2
99104 where
100105 -- Get current contents of si
101106 chkdb = si ^. systemdb
102107 -- extract sections and labelledcontent
103- allSections = concatMap findAllSec $ mkSections si $ mkDocDesc si dd -- FIXME: `mkSections` on something particularly large that is immediately discarded is a sign that we're doing something wrong. That's in addition to `mkDocDesc`.. .
108+ allSections = concatMap findAllSec $ mkSections si dd -- FIXME: `mkSections` on something particularly large that is immediately discarded is a sign that we're doing something wrong.
104109 allLC = concatMap findAllLC allSections
105110 existingLC = map (fst . snd ) $ Map. assocs $ labelledcontentTable chkdb
106111 -- fill in the appropriate chunkdb fields
@@ -125,14 +130,12 @@ fillSecAndLC dd si = si2
125130 findLCSecCons _ = []
126131
127132-- | Takes in existing information from the Chunk database to construct a database of references.
128- fillReferences :: SRSDecl -> System -> System
129- fillReferences dd si@ SI {_sys = sys} = si2
133+ fillReferences :: [ Section ] -> System -> System
134+ fillReferences allSections si@ SI {_sys = sys} = si2
130135 where
131136 -- get old chunk database + ref database
132137 chkdb = si ^. systemdb
133138 cites = citeDB si
134- -- convert SRSDecl into a list of sections (to easily get at all the references used in the SRS)
135- allSections = mkSections si $ mkDocDesc si dd
136139 -- get refs from SRSDecl. Should include all section labels and labelled content.
137140 refsFromSRS = concatMap findAllRefs allSections
138141 -- get refs from the stuff already inside the chunk database
@@ -155,10 +158,6 @@ fillReferences dd si@SI{_sys = sys} = si2
155158 -- set new chunk database into system information
156159 si2 = set systemdb chkdb2 si
157160
158- -- | Helper that gets references from definitions and models.
159- dRefToRef :: HasDecRef a => a -> [Reference ]
160- dRefToRef r = map ref $ r ^. getDecRefs
161-
162161-- | Recursively find all references in a section (meant for getting at 'LabelledContent').
163162findAllRefs :: Section -> [Reference ]
164163findAllRefs (Section _ cs r) = r: concatMap findRefSecCons cs
@@ -169,10 +168,8 @@ findAllRefs (Section _ cs r) = r: concatMap findRefSecCons cs
169168 findRefSecCons _ = []
170169
171170-- | Helper for filling in the traceability matrix and graph information into the system.
172- fillTraceSI :: SRSDecl -> System -> System
173- fillTraceSI dd si = fillTraceMaps l $ fillReqs l si
174- where
175- l = mkDocDesc si dd
171+ fillTraceSI :: DocDesc -> System -> System
172+ fillTraceSI dd si = fillTraceMaps dd $ fillReqs dd si
176173
177174-- | Fills in the traceabiliy matrix and graphs section of the system information using the document description.
178175fillTraceMaps :: DocDesc -> System -> System
@@ -447,3 +444,12 @@ mkBib bib = SRS.reference [UlC $ ulcc (Bib bib)] []
447444-- | Helper for making the Appendix section.
448445mkAppndxSec :: AppndxSec -> Section
449446mkAppndxSec (AppndxProg cs) = SRS. appendix cs []
447+
448+ -- ** Find Table of Contents
449+
450+ -- Find more concise way to do this
451+ -- | Finds whether the Table of Contents is in a SRSDecl.
452+ findToC :: SRSDecl -> ShowTableOfContents
453+ findToC [] = NoToC
454+ findToC (DD. TableOfContents: _) = ToC
455+ findToC (_: dds) = findToC dds
0 commit comments