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,7 +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 ( DocSection ( TraceabilitySec ))
19+ import qualified Drasil.DocDecl as DD
2020import Drasil.DocumentLanguage.Core (AppndxSec (.. ), AuxConstntSec (.. ),
2121 DerivationDisplay (.. ), DocDesc , DocSection (.. ), OffShelfSolnsSec (.. ), GSDSec (.. ),
2222 GSDSub (.. ), IntroSec (.. ), IntroSub (.. ), LCsSec (.. ), LFunc (.. ),
@@ -40,7 +40,7 @@ import Drasil.System
4040import Drasil.GetChunks (ccss , ccss' , citeDB )
4141
4242import Drasil.Sections.TableOfAbbAndAcronyms (tableAbbAccGen )
43- import Drasil.Sections.TableOfContents (toToC , findToC )
43+ import Drasil.Sections.TableOfContents (toToC )
4444import Drasil.Sections.TableOfSymbols (table , tsIntro )
4545import Drasil.Sections.TableOfUnits (tOfUnitSIName , tuIntro , defaultTUI )
4646import qualified Drasil.DocLang.SRS as SRS (appendix ,
@@ -73,12 +73,10 @@ import qualified Data.Drasil.Concepts.Documentation as Doc (likelyChg, section_,
7373-- * Main Function
7474
7575-- | Creates a document from a document description, a title combinator function, and system information.
76- mkDoc :: SRSDecl -> (IdeaDict -> IdeaDict -> Sentence ) -> System -> Document
77- mkDoc dd comb si@ SI {_sys = sys, _authors = docauthors} =
78- Document (whatsTheBigIdea si `comb` nw sys) (foldlList Comma List $ map (S . name) docauthors) (findToC l) $
79- mkSections si l
80- where
81- 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
8280
8381-- * Functions to Fill 'ChunkDB'
8482
@@ -91,12 +89,17 @@ mkDoc dd comb si@SI {_sys = sys, _authors = docauthors} =
9189-- | Assuming a given 'ChunkDB' with no traces and minimal/no references, fill
9290-- in for rest of system information. Currently fills in references,
9391-- traceability matrix information and 'IdeaDict's.
94- fillcdbSRS :: SRSDecl -> System -> System
95- fillcdbSRS srsDec si = fillLC srsDec $ fillReferences srsDec $ fillTraceSI srsDec si
92+ fillcdbSRS :: SRSDecl -> System -> (System , DocDesc )
93+ fillcdbSRS srsDec si =
94+ (fillLC 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
96100
97- -- | Input the to-be-created 'LabelledContent's into the 'ChunkDB' (to be
98- -- created by the final SRS artifact renderer).
99- fillLC :: SRSDecl -> System -> System
101+ -- | Fill in the 'Section's and 'LabelledContent' maps of the 'ChunkDB' from the 'SRSDecl'.
102+ fillLC :: DocDesc -> System -> System
100103fillLC sd si@ SI { _sys = sn }
101104 | containsTraceSec sd = si2
102105 | otherwise = si
@@ -111,20 +114,18 @@ fillLC sd si@SI{ _sys = sn }
111114 chkdb2 = chkdb { labelledcontentTable = idMap $ nub $ existingLC ++ createdLCs }
112115 si2 = set systemdb chkdb2 si
113116
114- containsTraceSec :: SRSDecl -> Bool
115- containsTraceSec ((DD. TraceabilitySec _): _) = True
117+ containsTraceSec :: DocDesc -> Bool
118+ containsTraceSec ((TraceabilitySec _): _) = True
116119 containsTraceSec (_: ss) = containsTraceSec ss
117120 containsTraceSec [] = False
118121
119122-- | Takes in existing information from the Chunk database to construct a database of references.
120- fillReferences :: SRSDecl -> System -> System
121- fillReferences dd si@ SI {_sys = sys} = si2
123+ fillReferences :: [ Section ] -> System -> System
124+ fillReferences allSections si@ SI {_sys = sys} = si2
122125 where
123126 -- get old chunk database + ref database
124127 chkdb = si ^. systemdb
125128 cites = citeDB si
126- -- convert SRSDecl into a list of sections (to easily get at all the references used in the SRS)
127- allSections = mkSections si $ mkDocDesc si dd
128129 -- get refs from SRSDecl. Should include all section labels and labelled content.
129130 refsFromSRS = concatMap findAllRefs allSections
130131 -- get refs from the stuff already inside the chunk database
@@ -147,10 +148,6 @@ fillReferences dd si@SI{_sys = sys} = si2
147148 -- set new chunk database into system information
148149 si2 = set systemdb chkdb2 si
149150
150- -- | Helper that gets references from definitions and models.
151- dRefToRef :: HasDecRef a => a -> [Reference ]
152- dRefToRef r = map ref $ r ^. getDecRefs
153-
154151-- | Recursively find all references in a section (meant for getting at 'LabelledContent').
155152findAllRefs :: Section -> [Reference ]
156153findAllRefs (Section _ cs r) = r: concatMap findRefSecCons cs
@@ -161,10 +158,8 @@ findAllRefs (Section _ cs r) = r: concatMap findRefSecCons cs
161158 findRefSecCons _ = []
162159
163160-- | Helper for filling in the traceability matrix and graph information into the system.
164- fillTraceSI :: SRSDecl -> System -> System
165- fillTraceSI dd si = fillTraceMaps l $ fillReqs l si
166- where
167- l = mkDocDesc si dd
161+ fillTraceSI :: DocDesc -> System -> System
162+ fillTraceSI dd si = fillTraceMaps dd $ fillReqs dd si
168163
169164-- | Fills in the traceabiliy matrix and graphs section of the system information using the document description.
170165fillTraceMaps :: DocDesc -> System -> System
@@ -439,3 +434,12 @@ mkBib bib = SRS.reference [UlC $ ulcc (Bib bib)] []
439434-- | Helper for making the Appendix section.
440435mkAppndxSec :: AppndxSec -> Section
441436mkAppndxSec (AppndxProg cs) = SRS. appendix cs []
437+
438+ -- ** Find Table of Contents
439+
440+ -- Find more concise way to do this
441+ -- | Finds whether the Table of Contents is in a SRSDecl.
442+ findToC :: SRSDecl -> ShowTableOfContents
443+ findToC [] = NoToC
444+ findToC (DD. TableOfContents: _) = ToC
445+ findToC (_: dds) = findToC dds
0 commit comments