{-# Language TupleSections #-}
---------------------------------------------------------------------------
-- | Start the process of moving away from Document as the main internal
-- representation of information, to something more informative.
-- Over time, we'll want to have a cleaner separation, but doing that
-- all at once would break too much for too long.  So we start here
-- instead.
module Drasil.DocumentLanguage (mkDoc, findAllRefs) where

-- General Haskell
import Control.Lens ((^.), set)
import Data.Either (rights)
import Data.Function (on)
import Data.List (nub, sortBy, (\\))
import Data.Maybe (maybeToList, mapMaybe, isJust, fromMaybe)
import qualified Data.Map as Map (keys)
import qualified Data.Set as Set
import qualified Data.Map.Strict as M

-- General Drasil
import Language.Drasil
import Language.Drasil.Display (compsy)
import Language.Drasil.Development (shortdep)

import Drasil.Database (findOrErr, ChunkDB, insertAll, UID, HasUID(..), invert)
import Drasil.Database.SearchTools (findAllConcInsts,
  TermAbbr, shortForm, termResolve')

import Drasil.System (SmithEtAlSRS, HasSmithEtAlSRS(..), HasSystemMeta(..))
import Drasil.GetChunks (ccss, ccss')

-- Vocabulary
import Drasil.Metadata.Documentation (likelyChg, section_, software, srs,
  unlikelyChg, requirement, software, assumption, goalStmt, refBy, refName)
import Drasil.Metadata.TheoryConcepts (dataDefn, genDefn, inModel, thModel)

-- Other docLang
import Drasil.DocDecl (SRSDecl, mkDocDesc)
import qualified Drasil.DocDecl as DD
import Drasil.DocumentLanguage.Core (AppndxSec(..), AuxConstntSec(..),
  DerivationDisplay(..), DocDesc, DocSection(..), OffShelfSolnsSec(..), GSDSec(..),
  GSDSub(..), IntroSec(..), IntroSub(..), LCsSec(..), LFunc(..),
  PDSub(..), ProblemDescription(..), RefSec(..), RefTab(..), ReqrmntSec(..),
  ReqsSub(..), SCSSub(..), StkhldrSec(..), StkhldrSub(..), SolChSpec(..),
  SSDSec(..), SSDSub(..), TraceabilitySec(..), TraceConfig(..),
  TSIntro(..), UCsSec(..), getTraceConfigUID)
import Drasil.DocumentLanguage.Definitions (ddefn, derivation, instanceModel,
  gdefn, tmodel)
import Drasil.Document.Contents(mkEnumSimpleD, foldlSP)
import Drasil.ExtractDocDesc (getDocDesc, egetDocDesc, getSec, extractDocBib)
import Drasil.TraceTable (generateTraceMap)

import Drasil.Sections.TableOfAbbAndAcronyms (tableAbbAccGen)
import Drasil.Sections.TableOfContents (toToC)
import Drasil.Sections.TableOfSymbols (table, tsIntro)
import Drasil.Sections.TableOfUnits (tOfUnitSIName, tuIntro, defaultTUI)
import qualified Drasil.DocLang.SRS as SRS (appendix,
  genSysDes, likeChg, unlikeChg, reference, solCharSpec,
  stakeholder, tOfCont, tOfSymb, tOfUnit, userChar, offShelfSol, refMat,
  tOfAbbAcc)
import Drasil.DocLang.References (secRefs)
import qualified Drasil.Sections.AuxiliaryConstants as AC (valsOfAuxConstantsF)
import qualified Drasil.Sections.GeneralSystDesc as GSD (genSysIntro,
  systCon, usrCharsF, sysContxt)
import qualified Drasil.Sections.Introduction as Intro (charIntRdrF,
  introductionSection, orgSec, purposeOfDoc, scopeOfRequirements)
import qualified Drasil.Sections.Requirements as R (reqF, fReqF, nfReqF)
import qualified Drasil.Sections.SpecificSystemDescription as SSD (assumpF,
  datConF, dataDefnF, genDefnF, goalStmtF, inModelF, physSystDesc, probDescF,
  propCorSolF, solutionCharSpecIntro, specSysDescr, termDefnF, thModF, helperCI,
  tmStub, ddStub, gdStub, imStub, pdStub)
import qualified Drasil.Sections.Stakeholders as Stk (stakeholderIntro,
  tClientF, tCustomerF)
import qualified Drasil.DocumentLanguage.TraceabilityMatrix as TM (
  generateTraceTableView, traceMHeader, layoutUIDs)
import qualified Drasil.DocumentLanguage.TraceabilityGraph as TG (traceMGF)
import Drasil.DocumentLanguage.TraceabilityGraph (traceyGraphGetRefs, genTraceGraphLabCons)
import Drasil.Sections.TraceabilityMandGs (traceMatStandard)
import Drasil.Sections.ReferenceMaterial (emptySectSentPlu)

-- * Main Function

-- | Creates a document from a 'System', a document description ('SRSDecl'), and
-- a title combinator.
mkDoc :: SmithEtAlSRS -> SRSDecl -> (CI -> CI -> Sentence) -> (Document, SmithEtAlSRS)
mkDoc :: SmithEtAlSRS
-> SRSDecl -> (CI -> CI -> Sentence) -> (Document, SmithEtAlSRS)
mkDoc SmithEtAlSRS
si SRSDecl
srsDecl CI -> CI -> Sentence
headingComb =
  let dd :: DocDesc
dd = SmithEtAlSRS -> SRSDecl -> DocDesc
mkDocDesc SmithEtAlSRS
si SRSDecl
srsDecl
      -- /Pre-generate/ the SRS artifact. It is missing content involving
      -- 'Reference's and 'LabelledContent' for potential traceability graphs as
      -- well as 'Citation's.
      sections :: [Section]
sections = SmithEtAlSRS -> DocDesc -> Maybe BibRef -> [Section]
mkSections SmithEtAlSRS
si DocDesc
dd Maybe BibRef
forall a. Maybe a
Nothing
      -- Extract all referenced 'Citations' from the pre-generated artifact.
      refdCites :: BibRef
refdCites = SmithEtAlSRS -> [Section] -> BibRef
extractDocBib SmithEtAlSRS
si [Section]
sections
      -- Injects "traceability" maps into the 'ChunkDB' and adds missing
      -- 'LabelledContent' (the generated traceability-related tables).
      si' :: SmithEtAlSRS
si' = DocDesc -> SmithEtAlSRS -> SmithEtAlSRS
buildTraceMaps DocDesc
dd (SmithEtAlSRS -> SmithEtAlSRS) -> SmithEtAlSRS -> SmithEtAlSRS
forall a b. (a -> b) -> a -> b
$ [Section] -> BibRef -> SmithEtAlSRS -> SmithEtAlSRS
fillReferences [Section]
sections BibRef
refdCites SmithEtAlSRS
si
      -- Now, the /real generation/ of the SRS artifact can begin, with the
      -- 'Reference' map now full (so 'Reference' references can resolve to
      -- 'Reference's) and the true list of bibliography entries known.
      heading :: Sentence
heading = CI
srs CI -> CI -> Sentence
`headingComb` (SmithEtAlSRS
si' SmithEtAlSRS -> Getting CI SmithEtAlSRS CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI SmithEtAlSRS CI
forall c. HasSystemMeta c => Lens' c CI
Lens' SmithEtAlSRS CI
sysName)
      authorsList :: Sentence
authorsList = SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List ([Sentence] -> Sentence) -> [Sentence] -> Sentence
forall a b. (a -> b) -> a -> b
$ (Person -> Sentence) -> [Person] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S (String -> Sentence) -> (Person -> String) -> Person -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Person -> String
forall n. HasName n => n -> String
fullName) ([Person] -> [Sentence]) -> [Person] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ SmithEtAlSRS
si SmithEtAlSRS -> Getting [Person] SmithEtAlSRS [Person] -> [Person]
forall s a. s -> Getting a s a -> a
^. Getting [Person] SmithEtAlSRS [Person]
forall c. HasSystemMeta c => Lens' c [Person]
Lens' SmithEtAlSRS [Person]
authors
      toc :: ShowTableOfContents
toc = SRSDecl -> ShowTableOfContents
findToC SRSDecl
srsDecl
      dd' :: DocDesc
dd' = SmithEtAlSRS -> SRSDecl -> DocDesc
mkDocDesc SmithEtAlSRS
si' SRSDecl
srsDecl
      sections' :: [Section]
sections' = SmithEtAlSRS -> DocDesc -> Maybe BibRef -> [Section]
mkSections SmithEtAlSRS
si' DocDesc
dd' (BibRef -> Maybe BibRef
forall a. a -> Maybe a
Just BibRef
refdCites)
  in (Sentence
-> Sentence -> ShowTableOfContents -> [Section] -> Document
Document Sentence
heading Sentence
authorsList ShowTableOfContents
toc [Section]
sections', SmithEtAlSRS
si')

-- * Functions to Fill 'ChunkDB'

-- FIXME: None of these 'fill$x$InTheCDB' should exist here. Generating new
-- chunks and inserting them into the ChunkDB is not an issue, but:
-- - The traceability-stuff should be internal to ChunkDB.
-- - The References and LabelledContent entirely need to be rebuilt. Some will
--   be chunks that are manually written, others will not be chunks.

-- | If a traceability section is present in the document description, builds
-- the "trace" (refers to) and "refBy" (referenced by) maps, placing them in the
-- output 'System', and generating corresponding 'LabelledContent' chunks for
-- the traceability graphs to be used in the SRS.
buildTraceMaps :: DocDesc -> SmithEtAlSRS -> SmithEtAlSRS
buildTraceMaps :: DocDesc -> SmithEtAlSRS -> SmithEtAlSRS
buildTraceMaps DocDesc
sd SmithEtAlSRS
si
  | DocDesc -> Bool
containsTraceSec DocDesc
sd =
    let db :: ChunkDB
db = SmithEtAlSRS
si SmithEtAlSRS -> Getting ChunkDB SmithEtAlSRS ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB SmithEtAlSRS ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' SmithEtAlSRS ChunkDB
systemdb
        -- Generate a copy to the /future/ SVG-based 'LabelledContent's
        -- containing the traceability graphs.
        tglcs :: [LabelledContent]
tglcs = String -> [LabelledContent]
genTraceGraphLabCons (String -> [LabelledContent]) -> String -> [LabelledContent]
forall a b. (a -> b) -> a -> b
$ SmithEtAlSRS
si SmithEtAlSRS -> Getting String SmithEtAlSRS String -> String
forall s a. s -> Getting a s a -> a
^. Getting String SmithEtAlSRS String
forall c. HasSmithEtAlSRS c => Lens' c String
Lens' SmithEtAlSRS String
programName
        -- Generates the traceability map from the 'DocDesc' for use in the
        -- later generation pipeline that produces the ".dot" files for which
        -- the main Drasil Makefile converts to SVGs (via `make tracegraphs`).
        tdb :: Map UID [UID]
tdb = DocDesc -> Map UID [UID]
generateTraceMap DocDesc
sd
    in ASetter
  SmithEtAlSRS SmithEtAlSRS [LabelledContent] [LabelledContent]
-> [LabelledContent] -> SmithEtAlSRS -> SmithEtAlSRS
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
  SmithEtAlSRS SmithEtAlSRS [LabelledContent] [LabelledContent]
forall c. HasSmithEtAlSRS c => Lens' c [LabelledContent]
Lens' SmithEtAlSRS [LabelledContent]
lbldCntnt (SmithEtAlSRS
si SmithEtAlSRS
-> Getting [LabelledContent] SmithEtAlSRS [LabelledContent]
-> [LabelledContent]
forall s a. s -> Getting a s a -> a
^. Getting [LabelledContent] SmithEtAlSRS [LabelledContent]
forall c. HasSmithEtAlSRS c => Lens' c [LabelledContent]
Lens' SmithEtAlSRS [LabelledContent]
lbldCntnt [LabelledContent] -> [LabelledContent] -> [LabelledContent]
forall a. [a] -> [a] -> [a]
++ [LabelledContent]
tglcs)
     (SmithEtAlSRS -> SmithEtAlSRS) -> SmithEtAlSRS -> SmithEtAlSRS
forall a b. (a -> b) -> a -> b
$ ASetter SmithEtAlSRS SmithEtAlSRS ChunkDB ChunkDB
-> ChunkDB -> SmithEtAlSRS -> SmithEtAlSRS
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter SmithEtAlSRS SmithEtAlSRS ChunkDB ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' SmithEtAlSRS ChunkDB
systemdb ([LabelledContent] -> ChunkDB -> ChunkDB
forall a. TypeableChunk a => [a] -> ChunkDB -> ChunkDB
insertAll [LabelledContent]
tglcs ChunkDB
db)
     (SmithEtAlSRS -> SmithEtAlSRS) -> SmithEtAlSRS -> SmithEtAlSRS
forall a b. (a -> b) -> a -> b
$ ASetter SmithEtAlSRS SmithEtAlSRS (Map UID [UID]) (Map UID [UID])
-> Map UID [UID] -> SmithEtAlSRS -> SmithEtAlSRS
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter SmithEtAlSRS SmithEtAlSRS (Map UID [UID]) (Map UID [UID])
forall c. HasSmithEtAlSRS c => Lens' c (Map UID [UID])
Lens' SmithEtAlSRS (Map UID [UID])
traceTable Map UID [UID]
tdb
     (SmithEtAlSRS -> SmithEtAlSRS) -> SmithEtAlSRS -> SmithEtAlSRS
forall a b. (a -> b) -> a -> b
$ ASetter SmithEtAlSRS SmithEtAlSRS (Map UID [UID]) (Map UID [UID])
-> Map UID [UID] -> SmithEtAlSRS -> SmithEtAlSRS
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter SmithEtAlSRS SmithEtAlSRS (Map UID [UID]) (Map UID [UID])
forall c. HasSmithEtAlSRS c => Lens' c (Map UID [UID])
Lens' SmithEtAlSRS (Map UID [UID])
refbyTable (Map UID [UID] -> Map UID [UID]
forall v k. Ord v => Map k [v] -> Map v [k]
invert Map UID [UID]
tdb) SmithEtAlSRS
si
  | Bool
otherwise = SmithEtAlSRS
si
  where
    containsTraceSec :: DocDesc -> Bool
    containsTraceSec :: DocDesc -> Bool
containsTraceSec ((TraceabilitySec TraceabilitySec
_):DocDesc
_) = Bool
True
    containsTraceSec (DocSection
_:DocDesc
ss)                = DocDesc -> Bool
containsTraceSec DocDesc
ss
    containsTraceSec []                    = Bool
False

-- | Takes in existing information from the Chunk database to construct a database of references.
fillReferences :: [Section] -> [Citation] -> SmithEtAlSRS -> SmithEtAlSRS
fillReferences :: [Section] -> BibRef -> SmithEtAlSRS -> SmithEtAlSRS
fillReferences [Section]
allSections BibRef
cites SmithEtAlSRS
si = SmithEtAlSRS
si2
  where
    -- get old chunk database + ref database
    chkdb :: ChunkDB
chkdb = SmithEtAlSRS
si SmithEtAlSRS -> Getting ChunkDB SmithEtAlSRS ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB SmithEtAlSRS ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' SmithEtAlSRS ChunkDB
systemdb
    -- get refs from SRSDecl. Should include all section labels and labelled content.
    refsFromSRS :: [Reference]
refsFromSRS = (Section -> [Reference]) -> [Section] -> [Reference]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Reference]
findAllRefs [Section]
allSections
    -- get refs from the stuff already inside the chunk database
    ddefs :: [DataDefinition]
ddefs   = SmithEtAlSRS
si SmithEtAlSRS
-> Getting [DataDefinition] SmithEtAlSRS [DataDefinition]
-> [DataDefinition]
forall s a. s -> Getting a s a -> a
^. Getting [DataDefinition] SmithEtAlSRS [DataDefinition]
forall c. HasSmithEtAlSRS c => Lens' c [DataDefinition]
Lens' SmithEtAlSRS [DataDefinition]
dataDefns
    gdefs :: [GenDefn]
gdefs   = SmithEtAlSRS
si SmithEtAlSRS
-> Getting [GenDefn] SmithEtAlSRS [GenDefn] -> [GenDefn]
forall s a. s -> Getting a s a -> a
^. Getting [GenDefn] SmithEtAlSRS [GenDefn]
forall c. HasSmithEtAlSRS c => Lens' c [GenDefn]
Lens' SmithEtAlSRS [GenDefn]
genDefns
    imods :: [InstanceModel]
imods   = SmithEtAlSRS
si SmithEtAlSRS
-> Getting [InstanceModel] SmithEtAlSRS [InstanceModel]
-> [InstanceModel]
forall s a. s -> Getting a s a -> a
^. Getting [InstanceModel] SmithEtAlSRS [InstanceModel]
forall c. HasSmithEtAlSRS c => Lens' c [InstanceModel]
Lens' SmithEtAlSRS [InstanceModel]
instModels
    tmods :: [TheoryModel]
tmods   = SmithEtAlSRS
si SmithEtAlSRS
-> Getting [TheoryModel] SmithEtAlSRS [TheoryModel]
-> [TheoryModel]
forall s a. s -> Getting a s a -> a
^. Getting [TheoryModel] SmithEtAlSRS [TheoryModel]
forall c. HasSmithEtAlSRS c => Lens' c [TheoryModel]
Lens' SmithEtAlSRS [TheoryModel]
theoryModels
    lblCon :: [LabelledContent]
lblCon  = SmithEtAlSRS
si SmithEtAlSRS
-> Getting [LabelledContent] SmithEtAlSRS [LabelledContent]
-> [LabelledContent]
forall s a. s -> Getting a s a -> a
^. Getting [LabelledContent] SmithEtAlSRS [LabelledContent]
forall c. HasSmithEtAlSRS c => Lens' c [LabelledContent]
Lens' SmithEtAlSRS [LabelledContent]
lbldCntnt
    concIns :: [ConceptInstance]
concIns = ChunkDB -> [ConceptInstance]
findAllConcInsts ChunkDB
chkdb
    newRefs :: Map UID Reference
newRefs = [(UID, Reference)] -> Map UID Reference
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(UID, Reference)] -> Map UID Reference)
-> [(UID, Reference)] -> Map UID Reference
forall a b. (a -> b) -> a -> b
$ (Reference -> (UID, Reference))
-> [Reference] -> [(UID, Reference)]
forall a b. (a -> b) -> [a] -> [b]
map (\Reference
x -> (Reference
x Reference -> Getting UID Reference UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID Reference UID
forall c. HasUID c => Getter c UID
Getter Reference UID
uid, Reference
x)) ([Reference] -> [(UID, Reference)])
-> [Reference] -> [(UID, Reference)]
forall a b. (a -> b) -> a -> b
$ [Reference]
refsFromSRS
      [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (TraceConfig -> Reference) -> [TraceConfig] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map (Reference -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref (Reference -> Reference)
-> (TraceConfig -> Reference) -> TraceConfig -> Reference
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UID -> Reference
makeTabRef' (UID -> Reference)
-> (TraceConfig -> UID) -> TraceConfig -> Reference
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TraceConfig -> UID
getTraceConfigUID) (SmithEtAlSRS -> [TraceConfig]
traceMatStandard SmithEtAlSRS
si)
      [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ [Reference]
secRefs -- secRefs can be removed once #946 is complete
      [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ String -> [Reference]
traceyGraphGetRefs (SmithEtAlSRS
si SmithEtAlSRS -> Getting String SmithEtAlSRS String -> String
forall s a. s -> Getting a s a -> a
^. Getting String SmithEtAlSRS String
forall c. HasSmithEtAlSRS c => Lens' c String
Lens' SmithEtAlSRS String
programName) [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (Citation -> Reference) -> BibRef -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map Citation -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref BibRef
cites
      [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (DataDefinition -> Reference) -> [DataDefinition] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map DataDefinition -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [DataDefinition]
ddefs [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (GenDefn -> Reference) -> [GenDefn] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map GenDefn -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [GenDefn]
gdefs [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (InstanceModel -> Reference) -> [InstanceModel] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map InstanceModel -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [InstanceModel]
imods
      [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (TheoryModel -> Reference) -> [TheoryModel] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map TheoryModel -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [TheoryModel]
tmods [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (ConceptInstance -> Reference) -> [ConceptInstance] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map ConceptInstance -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [ConceptInstance]
concIns [Reference] -> [Reference] -> [Reference]
forall a. [a] -> [a] -> [a]
++ (LabelledContent -> Reference) -> [LabelledContent] -> [Reference]
forall a b. (a -> b) -> [a] -> [b]
map LabelledContent -> Reference
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Reference
ref [LabelledContent]
lblCon
    si2 :: SmithEtAlSRS
si2 = ASetter
  SmithEtAlSRS SmithEtAlSRS (Map UID Reference) (Map UID Reference)
-> Map UID Reference -> SmithEtAlSRS -> SmithEtAlSRS
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
  SmithEtAlSRS SmithEtAlSRS (Map UID Reference) (Map UID Reference)
forall c. HasSmithEtAlSRS c => Lens' c (Map UID Reference)
Lens' SmithEtAlSRS (Map UID Reference)
refTable (Map UID Reference -> Map UID Reference -> Map UID Reference
forall k a. Ord k => Map k a -> Map k a -> Map k a
M.union (SmithEtAlSRS
si SmithEtAlSRS
-> Getting (Map UID Reference) SmithEtAlSRS (Map UID Reference)
-> Map UID Reference
forall s a. s -> Getting a s a -> a
^. Getting (Map UID Reference) SmithEtAlSRS (Map UID Reference)
forall c. HasSmithEtAlSRS c => Lens' c (Map UID Reference)
Lens' SmithEtAlSRS (Map UID Reference)
refTable) Map UID Reference
newRefs) SmithEtAlSRS
si

-- | Recursively find all references in a section (meant for getting at 'LabelledContent').
findAllRefs :: Section -> [Reference]
findAllRefs :: Section -> [Reference]
findAllRefs (Section Sentence
_ [SecCons]
cs Reference
r) = Reference
r Reference -> [Reference] -> [Reference]
forall a. a -> [a] -> [a]
: (SecCons -> [Reference]) -> [SecCons] -> [Reference]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SecCons -> [Reference]
findRefSecCons [SecCons]
cs
  where
    findRefSecCons :: SecCons -> [Reference]
    findRefSecCons :: SecCons -> [Reference]
findRefSecCons (Sub Section
s) = Section -> [Reference]
findAllRefs Section
s
    findRefSecCons (Con (LlC (LblC UID
_ Reference
rf RawContent
_))) = [Reference
rf]
    findRefSecCons SecCons
_ = []

-- | Constructs the unit definitions ('UnitDefn's) found in the document description ('DocDesc') from a database ('ChunkDB').
extractUnits :: DocDesc -> ChunkDB -> [UnitDefn]
extractUnits :: DocDesc -> ChunkDB -> [UnitDefn]
extractUnits DocDesc
dd ChunkDB
cdb = ChunkDB -> [DefinedQuantityDict] -> [UnitDefn]
forall c. Quantity c => ChunkDB -> [c] -> [UnitDefn]
collectUnitDeps ChunkDB
cdb ([DefinedQuantityDict] -> [UnitDefn])
-> [DefinedQuantityDict] -> [UnitDefn]
forall a b. (a -> b) -> a -> b
$ [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss' (DocDesc -> [Sentence]
getDocDesc DocDesc
dd) (DocDesc -> [ModelExpr]
egetDocDesc DocDesc
dd) ChunkDB
cdb

-- | For a given list of 'Quantity's, collects the 'UnitDefn's dependencies of
-- their units (i.e., what units their units are defined with).
collectUnitDeps :: Quantity c => ChunkDB -> [c] -> [UnitDefn]
collectUnitDeps :: forall c. Quantity c => ChunkDB -> [c] -> [UnitDefn]
collectUnitDeps ChunkDB
db = (UID -> UnitDefn) -> [UID] -> [UnitDefn]
forall a b. (a -> b) -> [a] -> [b]
map (UID -> ChunkDB -> UnitDefn
forall a. Typeable a => UID -> ChunkDB -> a
`findOrErr` ChunkDB
db) ([UID] -> [UnitDefn]) -> ([c] -> [UID]) -> [c] -> [UnitDefn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnitDefn -> [UID]) -> [UnitDefn] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap UnitDefn -> [UID]
forall u. IsUnit u => u -> [UID]
getUnits ([UnitDefn] -> [UID]) -> ([c] -> [UnitDefn]) -> [c] -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> Maybe UnitDefn) -> [c] -> [UnitDefn]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (ChunkDB -> c -> Maybe UnitDefn
forall c. HasUID c => ChunkDB -> c -> Maybe UnitDefn
getUnitLup ChunkDB
db)

getUnitLup :: HasUID c => ChunkDB -> c -> Maybe UnitDefn
getUnitLup :: forall c. HasUID c => ChunkDB -> c -> Maybe UnitDefn
getUnitLup ChunkDB
m c
c = DefinedQuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (UID -> ChunkDB -> DefinedQuantityDict
forall a. Typeable a => UID -> ChunkDB -> a
findOrErr (c
c c -> Getting UID c UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID c UID
forall c. HasUID c => Getter c UID
Getter c UID
uid) ChunkDB
m :: DefinedQuantityDict)

-- * Section Creator Functions

-- | Helper for creating the different document sections.
mkSections :: SmithEtAlSRS -> DocDesc -> Maybe BibRef -> [Section]
mkSections :: SmithEtAlSRS -> DocDesc -> Maybe BibRef -> [Section]
mkSections SmithEtAlSRS
si DocDesc
dd Maybe BibRef
mbib = (Either RefSec Section -> Section)
-> [Either RefSec Section] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map ((RefSec -> Section)
-> (Section -> Section) -> Either RefSec Section -> Section
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either RefSec -> Section
renderRefSec Section -> Section
forall a. a -> a
id) [Either RefSec Section]
partialRender
  where
    delayRenderRefSec :: DocSection -> Either RefSec Section
    delayRenderRefSec :: DocSection -> Either RefSec Section
delayRenderRefSec (RefSec RefSec
rs) = RefSec -> Either RefSec Section
forall a b. a -> Either a b
Left RefSec
rs
    delayRenderRefSec DocSection
x           = Section -> Either RefSec Section
forall a b. b -> Either a b
Right (DocSection -> Section
render DocSection
x)

    partialRender :: [Either RefSec Section]
    partialRender :: [Either RefSec Section]
partialRender = (DocSection -> Either RefSec Section)
-> DocDesc -> [Either RefSec Section]
forall a b. (a -> b) -> [a] -> [b]
map DocSection -> Either RefSec Section
delayRenderRefSec DocDesc
dd

    nonRefSecs :: [Section]
    nonRefSecs :: [Section]
nonRefSecs = [Either RefSec Section] -> [Section]
forall a b. [Either a b] -> [b]
rights [Either RefSec Section]
partialRender

    renderRefSec :: RefSec -> Section
    renderRefSec :: RefSec -> Section
renderRefSec RefSec
rs = SmithEtAlSRS -> DocDesc -> RefSec -> [Section] -> Section
mkRefSec SmithEtAlSRS
si DocDesc
dd RefSec
rs [Section]
nonRefSecs

    render :: DocSection -> Section
    render :: DocSection -> Section
render DocSection
TableOfContents      = DocDesc -> Section
mkToC DocDesc
dd
    render (IntroSec IntroSec
is)        = SmithEtAlSRS -> IntroSec -> Section
mkIntroSec SmithEtAlSRS
si IntroSec
is
    render (StkhldrSec StkhldrSec
sts)     = StkhldrSec -> Section
mkStkhldrSec StkhldrSec
sts
    render (SSDSec SSDSec
ss)          = SmithEtAlSRS -> SSDSec -> Section
mkSSDSec SmithEtAlSRS
si SSDSec
ss
    render (AuxConstntSec AuxConstntSec
acs)  = AuxConstntSec -> Section
mkAuxConsSec AuxConstntSec
acs
    render DocSection
Bibliography         = BibRef -> Section
mkBib (BibRef -> Section) -> BibRef -> Section
forall a b. (a -> b) -> a -> b
$ BibRef -> Maybe BibRef -> BibRef
forall a. a -> Maybe a -> a
fromMaybe [] Maybe BibRef
mbib
    render (GSDSec GSDSec
gs')         = GSDSec -> Section
mkGSDSec GSDSec
gs'
    render (ReqrmntSec ReqrmntSec
r)       = ReqrmntSec -> Section
mkReqrmntSec ReqrmntSec
r
    render (LCsSec LCsSec
lc)          = LCsSec -> Section
mkLCsSec LCsSec
lc
    render (UCsSec UCsSec
ulcs)        = UCsSec -> Section
mkUCsSec UCsSec
ulcs
    render (TraceabilitySec TraceabilitySec
t)  = TraceabilitySec -> SmithEtAlSRS -> Section
mkTraceabilitySec TraceabilitySec
t SmithEtAlSRS
si
    render (AppndxSec AppndxSec
a)        = AppndxSec -> Section
mkAppndxSec AppndxSec
a
    render (OffShelfSolnsSec OffShelfSolnsSec
o) = OffShelfSolnsSec -> Section
mkOffShelfSolnSec OffShelfSolnsSec
o
    render (RefSec RefSec
_)           = String -> Section
forall a. HasCallStack => String -> a
error
      String
"mkSections passed `render` a `RefSec` in partial-render phase!"

-- ** Table of Contents

-- | Helper for making the Table of Contents section.
mkToC :: DocDesc -> Section
mkToC :: DocDesc -> Section
mkToC DocDesc
dd = [Contents] -> [Section] -> Section
SRS.tOfCont [Contents
intro, UnlabelledContent -> Contents
UlC (UnlabelledContent -> Contents) -> UnlabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc (RawContent -> UnlabelledContent)
-> RawContent -> UnlabelledContent
forall a b. (a -> b) -> a -> b
$ ListType -> RawContent
Enumeration (ListType -> RawContent) -> ListType -> RawContent
forall a b. (a -> b) -> a -> b
$ [(ItemType, Maybe String)] -> ListType
Bullet ([(ItemType, Maybe String)] -> ListType)
-> [(ItemType, Maybe String)] -> ListType
forall a b. (a -> b) -> a -> b
$ (DocSection -> (ItemType, Maybe String))
-> DocDesc -> [(ItemType, Maybe String)]
forall a b. (a -> b) -> [a] -> [b]
map ((, Maybe String
forall a. Maybe a
Nothing) (ItemType -> (ItemType, Maybe String))
-> (DocSection -> ItemType)
-> DocSection
-> (ItemType, Maybe String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocSection -> ItemType
toToC) DocDesc
dd] []
  where
    intro :: Contents
intro = Sentence -> Contents
mkParagraph (Sentence -> Contents) -> Sentence -> Contents
forall a b. (a -> b) -> a -> b
$ String -> Sentence
S String
"An outline of all sections included in this SRS is recorded here for easy reference."

-- ** Reference Materials

-- | Helper for creating the reference section and subsections.
-- Includes Table of Symbols, Units and Abbreviations and Acronyms.
mkRefSec :: SmithEtAlSRS -> DocDesc -> RefSec -> [Section] -> Section
mkRefSec :: SmithEtAlSRS -> DocDesc -> RefSec -> [Section] -> Section
mkRefSec SmithEtAlSRS
si DocDesc
dd (RefProg Contents
c [RefTab]
l) [Section]
renderedSecs = [Contents] -> [Section] -> Section
SRS.refMat [Contents
c] ((RefTab -> Section) -> [RefTab] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map RefTab -> Section
mkSubRef [RefTab]
l)
  where
    sysNameUID :: UID
sysNameUID = SmithEtAlSRS
si SmithEtAlSRS -> Getting UID SmithEtAlSRS UID -> UID
forall s a. s -> Getting a s a -> a
^. (CI -> Const UID CI) -> SmithEtAlSRS -> Const UID SmithEtAlSRS
forall c. HasSystemMeta c => Lens' c CI
Lens' SmithEtAlSRS CI
sysName ((CI -> Const UID CI) -> SmithEtAlSRS -> Const UID SmithEtAlSRS)
-> ((UID -> Const UID UID) -> CI -> Const UID CI)
-> Getting UID SmithEtAlSRS UID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> Const UID UID) -> CI -> Const UID CI
forall c. HasUID c => Getter c UID
Getter CI UID
uid
    db :: ChunkDB
db = SmithEtAlSRS
si SmithEtAlSRS -> Getting ChunkDB SmithEtAlSRS ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB SmithEtAlSRS ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' SmithEtAlSRS ChunkDB
systemdb

    mkSubRef :: RefTab -> Section
    mkSubRef :: RefTab -> Section
mkSubRef RefTab
TUnits = RefTab -> Section
mkSubRef (RefTab -> Section) -> RefTab -> Section
forall a b. (a -> b) -> a -> b
$ [TUIntro] -> ([UnitDefn] -> LabelledContent) -> RefTab
TUnits' [TUIntro]
defaultTUI [UnitDefn] -> LabelledContent
forall s. IsUnit s => [s] -> LabelledContent
tOfUnitSIName
    mkSubRef (TUnits' [TUIntro]
con [UnitDefn] -> LabelledContent
f) =
        [Contents] -> [Section] -> Section
SRS.tOfUnit [[TUIntro] -> Contents
tuIntro [TUIntro]
con, LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ [UnitDefn] -> LabelledContent
f ([UnitDefn] -> [UnitDefn]
forall a. Eq a => [a] -> [a]
nub ([UnitDefn] -> [UnitDefn]) -> [UnitDefn] -> [UnitDefn]
forall a b. (a -> b) -> a -> b
$ (UnitDefn -> UnitDefn -> Ordering) -> [UnitDefn] -> [UnitDefn]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy UnitDefn -> UnitDefn -> Ordering
compUnitDefn ([UnitDefn] -> [UnitDefn]) -> [UnitDefn] -> [UnitDefn]
forall a b. (a -> b) -> a -> b
$ DocDesc -> ChunkDB -> [UnitDefn]
extractUnits DocDesc
dd ChunkDB
db)] []
    mkSubRef (TSymb [TSIntro]
con) =
      [Contents] -> [Section] -> Section
SRS.tOfSymb
      [[TSIntro] -> Contents
tsIntro [TSIntro]
con,
                LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ Stage
-> [DefinedQuantityDict]
-> (DefinedQuantityDict -> Sentence)
-> LabelledContent
forall s.
(Quantity s, MayHaveUnit s) =>
Stage -> [s] -> (s -> Sentence) -> LabelledContent
table Stage
Equational ([DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. HasSymbol a => [a] -> [a]
sortBySymbol
                ([DefinedQuantityDict] -> [DefinedQuantityDict])
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ (DefinedQuantityDict -> Bool)
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. (a -> Bool) -> [a] -> [a]
filter (DefinedQuantityDict -> Stage -> Bool
forall q. HasSymbol q => q -> Stage -> Bool
`hasStageSymbol` Stage
Equational)
                ([DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Eq a => [a] -> [a]
nub ([DefinedQuantityDict] -> [DefinedQuantityDict])
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a b. (a -> b) -> a -> b
$ [Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss' (DocDesc -> [Sentence]
getDocDesc DocDesc
dd) (DocDesc -> [ModelExpr]
egetDocDesc DocDesc
dd) ChunkDB
db))
                DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart] []
    mkSubRef (TSymb' LFunc
f [TSIntro]
con) =
      [DefinedQuantityDict] -> LFunc -> [TSIntro] -> Section
forall e.
(Quantity e, Concept e, Eq e, MayHaveUnit e) =>
[e] -> LFunc -> [TSIntro] -> Section
mkTSymb ([Sentence] -> [ModelExpr] -> ChunkDB -> [DefinedQuantityDict]
ccss (DocDesc -> [Sentence]
getDocDesc DocDesc
dd) (DocDesc -> [ModelExpr]
egetDocDesc DocDesc
dd) ChunkDB
db) LFunc
f [TSIntro]
con

    mkSubRef RefTab
TAandA =
      [Contents] -> [Section] -> Section
SRS.tOfAbbAcc
        [LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ [TermAbbr] -> LabelledContent
tableAbbAccGen ([TermAbbr] -> LabelledContent) -> [TermAbbr] -> LabelledContent
forall a b. (a -> b) -> a -> b
$ UID -> [Section] -> ChunkDB -> [TermAbbr]
collectDocumentAbbreviations UID
sysNameUID [Section]
renderedSecs ChunkDB
db]
        []

collectDocumentAbbreviations :: UID -> [Section] -> ChunkDB -> [TermAbbr]
collectDocumentAbbreviations :: UID -> [Section] -> ChunkDB -> [TermAbbr]
collectDocumentAbbreviations UID
sysNameUID [Section]
renderedSecs ChunkDB
cdb =
  (TermAbbr -> Bool) -> [TermAbbr] -> [TermAbbr]
forall a. (a -> Bool) -> [a] -> [a]
filter (Maybe String -> Bool
forall a. Maybe a -> Bool
isJust (Maybe String -> Bool)
-> (TermAbbr -> Maybe String) -> TermAbbr -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TermAbbr -> Maybe String
shortForm) [TermAbbr]
allTerms
  where
    -- Terms found in the document using the list of `Sentence`s extracted from
    -- the sections.
    foundInDoc :: [UID]
foundInDoc = (Sentence -> [UID]) -> [Sentence] -> [UID]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Set UID -> [UID]
forall a. Set a -> [a]
Set.toList (Set UID -> [UID]) -> (Sentence -> Set UID) -> Sentence -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sentence -> Set UID
shortdep) ([Sentence] -> [UID]) -> [Sentence] -> [UID]
forall a b. (a -> b) -> a -> b
$ (Section -> [Sentence]) -> [Section] -> [Sentence]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Section -> [Sentence]
getSec [Section]
renderedSecs
    -- Terms that could not be found in `Sentence`s, but are important to
    -- include in the table of abbreviations and acronyms.
    missingFromDocHACK :: [UID]
missingFromDocHACK = (CI -> UID) -> [CI] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (CI -> ((UID -> Const UID UID) -> CI -> Const UID CI) -> UID
forall s a. s -> Getting a s a -> a
^. (UID -> Const UID UID) -> CI -> Const UID CI
forall c. HasUID c => Getter c UID
Getter CI UID
uid) [CI
assumption, CI
dataDefn, CI
genDefn, CI
goalStmt,
      CI
inModel, CI
requirement, CI
thModel, CI
refName, CI
refBy]
    -- Filter out the system name and duplicates
    filtered :: [UID]
filtered = [UID] -> [UID]
forall a. Eq a => [a] -> [a]
nub ([UID]
foundInDoc [UID] -> [UID] -> [UID]
forall a. [a] -> [a] -> [a]
++ [UID]
missingFromDocHACK) [UID] -> [UID] -> [UID]
forall a. Eq a => [a] -> [a] -> [a]
\\ [UID
sysNameUID]
    allTerms :: [TermAbbr]
allTerms = (UID -> TermAbbr) -> [UID] -> [TermAbbr]
forall a b. (a -> b) -> [a] -> [b]
map (ChunkDB -> UID -> TermAbbr
termResolve' ChunkDB
cdb) [UID]
filtered

-- | Helper for creating the table of symbols.
mkTSymb :: (Quantity e, Concept e, Eq e, MayHaveUnit e) =>
  [e] -> LFunc -> [TSIntro] -> Section
mkTSymb :: forall e.
(Quantity e, Concept e, Eq e, MayHaveUnit e) =>
[e] -> LFunc -> [TSIntro] -> Section
mkTSymb [e]
v LFunc
f [TSIntro]
c = [Contents] -> [Section] -> Section
SRS.tOfSymb [[TSIntro] -> Contents
tsIntro [TSIntro]
c,
  LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ Stage -> [e] -> (e -> Sentence) -> LabelledContent
forall s.
(Quantity s, MayHaveUnit s) =>
Stage -> [s] -> (s -> Sentence) -> LabelledContent
table Stage
Equational
    ((e -> e -> Ordering) -> [e] -> [e]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (Symbol -> Symbol -> Ordering
compsy (Symbol -> Symbol -> Ordering)
-> (e -> Symbol) -> e -> e -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` e -> Symbol
forall q. HasSymbol q => q -> Symbol
eqSymb) ([e] -> [e]) -> [e] -> [e]
forall a b. (a -> b) -> a -> b
$ (e -> Bool) -> [e] -> [e]
forall a. (a -> Bool) -> [a] -> [a]
filter (e -> Stage -> Bool
forall q. HasSymbol q => q -> Stage -> Bool
`hasStageSymbol` Stage
Equational) ([e] -> [e]
forall a. Eq a => [a] -> [a]
nub [e]
v))
    (LFunc -> e -> Sentence
forall {n}. (NamedIdea n, Definition n) => LFunc -> n -> Sentence
lf LFunc
f)]
    []
  where lf :: LFunc -> n -> Sentence
lf LFunc
Term = n -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart
        lf LFunc
Defn = Sentence -> Sentence
capSent (Sentence -> Sentence) -> (n -> Sentence) -> n -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> Getting Sentence n Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence n Sentence
forall c. Definition c => Lens' c Sentence
Lens' n Sentence
defn)
        lf (TermExcept [DefinedQuantityDict]
cs) = \n
x -> if (n
x n -> Getting UID n UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID n UID
forall c. HasUID c => Getter c UID
Getter n UID
uid) UID -> [UID] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (DefinedQuantityDict -> UID) -> [DefinedQuantityDict] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (DefinedQuantityDict -> Getting UID DefinedQuantityDict UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID DefinedQuantityDict UID
forall c. HasUID c => Getter c UID
Getter DefinedQuantityDict UID
uid) [DefinedQuantityDict]
cs then
          Sentence -> Sentence
capSent (n
x n -> Getting Sentence n Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence n Sentence
forall c. Definition c => Lens' c Sentence
Lens' n Sentence
defn) else n -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart n
x --Compare chunk uids, since we don't
          --actually care about the chunks themselves in LFunc.
        lf (DefnExcept [DefinedQuantityDict]
cs) = \n
x -> if (n
x n -> Getting UID n UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID n UID
forall c. HasUID c => Getter c UID
Getter n UID
uid) UID -> [UID] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (DefinedQuantityDict -> UID) -> [DefinedQuantityDict] -> [UID]
forall a b. (a -> b) -> [a] -> [b]
map (DefinedQuantityDict -> Getting UID DefinedQuantityDict UID -> UID
forall s a. s -> Getting a s a -> a
^.Getting UID DefinedQuantityDict UID
forall c. HasUID c => Getter c UID
Getter DefinedQuantityDict UID
uid) [DefinedQuantityDict]
cs then
          n -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart n
x else Sentence -> Sentence
capSent (n
x n -> Getting Sentence n Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence n Sentence
forall c. Definition c => Lens' c Sentence
Lens' n Sentence
defn)
        lf LFunc
TAD = \n
tDef -> n -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize n
tDef Sentence -> Sentence -> Sentence
+: Sentence
EmptyS Sentence -> Sentence -> Sentence
+:+. Sentence -> Sentence
capSent (n
tDef n -> Getting Sentence n Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence n Sentence
forall c. Definition c => Lens' c Sentence
Lens' n Sentence
defn)

-- ** Introduction

-- | Makes the Introduction section into a 'Section'.
mkIntroSec :: SmithEtAlSRS -> IntroSec -> Section
mkIntroSec :: SmithEtAlSRS -> IntroSec -> Section
mkIntroSec SmithEtAlSRS
si (IntroProg Sentence
probIntro Sentence
progDefn [IntroSub]
l) =
  Sentence -> Sentence -> [IntroSub] -> [Section] -> Section
Intro.introductionSection Sentence
probIntro Sentence
progDefn [IntroSub]
l ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (IntroSub -> Section) -> [IntroSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map IntroSub -> Section
mkSubIntro [IntroSub]
l
  where
    mkSubIntro :: IntroSub -> Section
    mkSubIntro :: IntroSub -> Section
mkSubIntro (IPurpose [Sentence]
intro) = [Sentence] -> Section
Intro.purposeOfDoc [Sentence]
intro
    mkSubIntro (IScope Sentence
main) = Sentence -> Section
Intro.scopeOfRequirements Sentence
main
    mkSubIntro (IChar [Sentence]
assumed [Sentence]
topic [Sentence]
asset) =
      CI -> [Sentence] -> [Sentence] -> [Sentence] -> Section -> Section
forall a.
Idea a =>
a -> [Sentence] -> [Sentence] -> [Sentence] -> Section -> Section
Intro.charIntRdrF (SmithEtAlSRS
si SmithEtAlSRS -> Getting CI SmithEtAlSRS CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI SmithEtAlSRS CI
forall c. HasSystemMeta c => Lens' c CI
Lens' SmithEtAlSRS CI
sysName) [Sentence]
assumed [Sentence]
topic [Sentence]
asset ([Contents] -> [Section] -> Section
SRS.userChar [] [])
    mkSubIntro (IOrgSec CI
b Section
s Maybe Sentence
t) = CI -> Section -> Maybe Sentence -> Section
forall c. NamedIdea c => c -> Section -> Maybe Sentence -> Section
Intro.orgSec CI
b Section
s Maybe Sentence
t
    -- FIXME: s should be "looked up" using "b" once we have all sections being generated

-- ** Stakeholders

-- | Helper for making the Stakeholders section.
mkStkhldrSec :: StkhldrSec -> Section
mkStkhldrSec :: StkhldrSec -> Section
mkStkhldrSec (StkhldrProg [StkhldrSub]
l) = [Contents] -> [Section] -> Section
SRS.stakeholder [Contents
Stk.stakeholderIntro] ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (StkhldrSub -> Section) -> [StkhldrSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map StkhldrSub -> Section
mkSubs [StkhldrSub]
l
  where
    mkSubs :: StkhldrSub -> Section
    mkSubs :: StkhldrSub -> Section
mkSubs (Client CI
kWrd Sentence
details) = CI -> Sentence -> Section
forall a. Idea a => a -> Sentence -> Section
Stk.tClientF CI
kWrd Sentence
details
    mkSubs (Cstmr CI
kWrd)          = CI -> Section
forall a. Idea a => a -> Section
Stk.tCustomerF CI
kWrd

-- ** General System Description

-- | Helper for making the General System Description section.
mkGSDSec :: GSDSec -> Section
mkGSDSec :: GSDSec -> Section
mkGSDSec (GSDProg [GSDSub]
l) = [Contents] -> [Section] -> Section
SRS.genSysDes [Contents
GSD.genSysIntro] ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (GSDSub -> Section) -> [GSDSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map GSDSub -> Section
mkSubs [GSDSub]
l
   where
     mkSubs :: GSDSub -> Section
     mkSubs :: GSDSub -> Section
mkSubs (SysCntxt [Contents]
cs)            = [Contents] -> Section
GSD.sysContxt [Contents]
cs
     mkSubs (UsrChars [Contents]
intro)         = [Contents] -> Section
GSD.usrCharsF [Contents]
intro
     mkSubs (SystCons [Contents]
cntnts [Section]
subsec) = [Contents] -> [Section] -> Section
GSD.systCon [Contents]
cntnts [Section]
subsec

-- ** Specific System Description

-- | Helper for making the Specific System Description section.
mkSSDSec :: SmithEtAlSRS -> SSDSec -> Section
mkSSDSec :: SmithEtAlSRS -> SSDSec -> Section
mkSSDSec SmithEtAlSRS
si (SSDProg [SSDSub]
l) =
  [Section] -> Section
SSD.specSysDescr ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (SSDSub -> Section) -> [SSDSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map (SmithEtAlSRS -> SSDSub -> Section
mkSubSSD SmithEtAlSRS
si) [SSDSub]
l
  where
    mkSubSSD :: SmithEtAlSRS -> SSDSub -> Section
    mkSubSSD :: SmithEtAlSRS -> SSDSub -> Section
mkSubSSD SmithEtAlSRS
sysi (SSDProblem ProblemDescription
pd)    = SmithEtAlSRS -> ProblemDescription -> Section
mkSSDProb SmithEtAlSRS
sysi ProblemDescription
pd
    mkSubSSD SmithEtAlSRS
sysi (SSDSolChSpec SolChSpec
scs) = SmithEtAlSRS -> SolChSpec -> Section
mkSolChSpec SmithEtAlSRS
sysi SolChSpec
scs

-- | Helper for making the Specific System Description Problem section.
mkSSDProb :: SmithEtAlSRS -> ProblemDescription -> Section
mkSSDProb :: SmithEtAlSRS -> ProblemDescription -> Section
mkSSDProb SmithEtAlSRS
_ (PDProg Sentence
prob [Section]
subSec [PDSub]
subPD) = Sentence -> [Section] -> Section
SSD.probDescF Sentence
prob ([Section]
subSec [Section] -> [Section] -> [Section]
forall a. [a] -> [a] -> [a]
++ (PDSub -> Section) -> [PDSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map PDSub -> Section
mkSubPD [PDSub]
subPD)
  where mkSubPD :: PDSub -> Section
mkSubPD (TermsAndDefs Maybe Sentence
sen [c]
concepts) = Maybe Sentence -> [c] -> Section
forall c. Concept c => Maybe Sentence -> [c] -> Section
SSD.termDefnF Maybe Sentence
sen [c]
concepts
        mkSubPD (PhySysDesc a
prog [Sentence]
parts LabelledContent
dif [Contents]
extra) = a -> [Sentence] -> LabelledContent -> [Contents] -> Section
forall a.
Idea a =>
a -> [Sentence] -> LabelledContent -> [Contents] -> Section
SSD.physSystDesc a
prog [Sentence]
parts LabelledContent
dif [Contents]
extra
        mkSubPD (Goals [Sentence]
ins [ConceptInstance]
g) = [Sentence] -> [Contents] -> Int -> Section
SSD.goalStmtF [Sentence]
ins ([ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD [ConceptInstance]
g) ([ConceptInstance] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ConceptInstance]
g)

-- | Helper for making the Solution Characteristics Specification section.
mkSolChSpec :: SmithEtAlSRS -> SolChSpec -> Section
mkSolChSpec :: SmithEtAlSRS -> SolChSpec -> Section
mkSolChSpec SmithEtAlSRS
si (SCSProg [SCSSub]
l) =
  [Contents] -> [Section] -> Section
SRS.solCharSpec [CI -> Section -> Contents
forall a. Idea a => a -> Section -> Contents
SSD.solutionCharSpecIntro (SmithEtAlSRS
si SmithEtAlSRS -> Getting CI SmithEtAlSRS CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI SmithEtAlSRS CI
forall c. HasSystemMeta c => Lens' c CI
Lens' SmithEtAlSRS CI
sysName) Section
SSD.imStub] ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$
    (SCSSub -> Section) -> [SCSSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map (SmithEtAlSRS -> SCSSub -> Section
mkSubSCS SmithEtAlSRS
si) [SCSSub]
l
  where
    mkSubSCS :: SmithEtAlSRS -> SCSSub -> Section
    mkSubSCS :: SmithEtAlSRS -> SCSSub -> Section
mkSubSCS SmithEtAlSRS
si' (TMs [Sentence]
intro Fields
fields [TheoryModel]
ts) =
      CI -> [Contents] -> Section
forall a. Idea a => a -> [Contents] -> Section
SSD.thModF (SmithEtAlSRS
si' SmithEtAlSRS -> Getting CI SmithEtAlSRS CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI SmithEtAlSRS CI
forall c. HasSystemMeta c => Lens' c CI
Lens' SmithEtAlSRS CI
sysName) ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (TheoryModel -> Contents) -> [TheoryModel] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map (LabelledContent -> Contents
LlC (LabelledContent -> Contents)
-> (TheoryModel -> LabelledContent) -> TheoryModel -> Contents
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fields -> SmithEtAlSRS -> TheoryModel -> LabelledContent
tmodel Fields
fields SmithEtAlSRS
si') [TheoryModel]
ts
    mkSubSCS SmithEtAlSRS
si' (DDs [Sentence]
intro Fields
fields [DataDefinition]
dds DerivationDisplay
ShowDerivation) = --FIXME: need to keep track of DD intro.
      Sentence -> [Contents] -> Section
SSD.dataDefnF Sentence
EmptyS ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (DataDefinition -> [Contents]) -> [DataDefinition] -> [Contents]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap DataDefinition -> [Contents]
f [DataDefinition]
dds
      where f :: DataDefinition -> [Contents]
f DataDefinition
e = LabelledContent -> Contents
LlC (Fields -> SmithEtAlSRS -> DataDefinition -> LabelledContent
ddefn Fields
fields SmithEtAlSRS
si' DataDefinition
e) Contents -> [Contents] -> [Contents]
forall a. a -> [a] -> [a]
: Maybe Contents -> [Contents]
forall a. Maybe a -> [a]
maybeToList (DataDefinition -> Maybe Contents
forall c.
(MayHaveDerivation c, HasShortName c, Referable c) =>
c -> Maybe Contents
derivation DataDefinition
e)
    mkSubSCS SmithEtAlSRS
si' (DDs [Sentence]
intro Fields
fields [DataDefinition]
dds DerivationDisplay
_) =
      Sentence -> [Contents] -> Section
SSD.dataDefnF Sentence
EmptyS ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (DataDefinition -> Contents) -> [DataDefinition] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map DataDefinition -> Contents
f [DataDefinition]
dds
      where f :: DataDefinition -> Contents
f DataDefinition
e = LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ Fields -> SmithEtAlSRS -> DataDefinition -> LabelledContent
ddefn Fields
fields SmithEtAlSRS
si' DataDefinition
e
    mkSubSCS SmithEtAlSRS
si' (GDs [Sentence]
intro Fields
fields [GenDefn]
gs' DerivationDisplay
ShowDerivation) =
      [Contents] -> Section
SSD.genDefnF ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (GenDefn -> [Contents]) -> [GenDefn] -> [Contents]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\GenDefn
x -> LabelledContent -> Contents
LlC (Fields -> SmithEtAlSRS -> GenDefn -> LabelledContent
gdefn Fields
fields SmithEtAlSRS
si' GenDefn
x) Contents -> [Contents] -> [Contents]
forall a. a -> [a] -> [a]
: Maybe Contents -> [Contents]
forall a. Maybe a -> [a]
maybeToList (GenDefn -> Maybe Contents
forall c.
(MayHaveDerivation c, HasShortName c, Referable c) =>
c -> Maybe Contents
derivation GenDefn
x)) [GenDefn]
gs'
    mkSubSCS SmithEtAlSRS
si' (GDs [Sentence]
intro Fields
fields [GenDefn]
gs' DerivationDisplay
_) =
      [Contents] -> Section
SSD.genDefnF ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (GenDefn -> Contents) -> [GenDefn] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map (LabelledContent -> Contents
LlC (LabelledContent -> Contents)
-> (GenDefn -> LabelledContent) -> GenDefn -> Contents
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fields -> SmithEtAlSRS -> GenDefn -> LabelledContent
gdefn Fields
fields SmithEtAlSRS
si') [GenDefn]
gs'
    mkSubSCS SmithEtAlSRS
si' (IMs [Sentence]
intro Fields
fields [InstanceModel]
ims DerivationDisplay
ShowDerivation) =
      Section -> Section -> Section -> Section -> [Contents] -> Section
SSD.inModelF Section
SSD.pdStub Section
SSD.ddStub Section
SSD.tmStub Section
SSD.gdStub ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++
      (InstanceModel -> [Contents]) -> [InstanceModel] -> [Contents]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\InstanceModel
x -> LabelledContent -> Contents
LlC (Fields -> SmithEtAlSRS -> InstanceModel -> LabelledContent
instanceModel Fields
fields SmithEtAlSRS
si' InstanceModel
x) Contents -> [Contents] -> [Contents]
forall a. a -> [a] -> [a]
: Maybe Contents -> [Contents]
forall a. Maybe a -> [a]
maybeToList (InstanceModel -> Maybe Contents
forall c.
(MayHaveDerivation c, HasShortName c, Referable c) =>
c -> Maybe Contents
derivation InstanceModel
x)) [InstanceModel]
ims
    mkSubSCS SmithEtAlSRS
si' (IMs [Sentence]
intro Fields
fields [InstanceModel]
ims DerivationDisplay
_) =
      Section -> Section -> Section -> Section -> [Contents] -> Section
SSD.inModelF Section
SSD.pdStub Section
SSD.ddStub Section
SSD.tmStub Section
SSD.gdStub ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ (Sentence -> Contents) -> [Sentence] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map Sentence -> Contents
mkParagraph [Sentence]
intro [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++
      (InstanceModel -> Contents) -> [InstanceModel] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map (LabelledContent -> Contents
LlC (LabelledContent -> Contents)
-> (InstanceModel -> LabelledContent) -> InstanceModel -> Contents
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fields -> SmithEtAlSRS -> InstanceModel -> LabelledContent
instanceModel Fields
fields SmithEtAlSRS
si') [InstanceModel]
ims
    mkSubSCS SmithEtAlSRS
si' (Assumptions [ConceptInstance]
ci) =
      [Contents] -> Section
SSD.assumpF ([Contents] -> Section) -> [Contents] -> Section
forall a b. (a -> b) -> a -> b
$ [ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD ([ConceptInstance] -> [Contents])
-> [ConceptInstance] -> [Contents]
forall a b. (a -> b) -> a -> b
$ (ConceptInstance -> ConceptInstance)
-> [ConceptInstance] -> [ConceptInstance]
forall a b. (a -> b) -> [a] -> [b]
map (ConceptInstance -> SmithEtAlSRS -> ConceptInstance
`SSD.helperCI` SmithEtAlSRS
si') [ConceptInstance]
ci
    mkSubSCS SmithEtAlSRS
_ (Constraints Sentence
end [c]
cs)  = Sentence -> [c] -> Section
forall c.
(HasUncertainty c, Quantity c, Constrained c, HasReasVal c,
 MayHaveUnit c) =>
Sentence -> [c] -> Section
SSD.datConF Sentence
end [c]
cs
    mkSubSCS SmithEtAlSRS
_ (CorrSolnPpties [c]
c [Contents]
cs) = [c] -> [Contents] -> Section
forall c.
(Quantity c, Constrained c) =>
[c] -> [Contents] -> Section
SSD.propCorSolF [c]
c [Contents]
cs

-- ** Requirements

-- | Helper for making the Requirements section.
mkReqrmntSec :: ReqrmntSec -> Section
mkReqrmntSec :: ReqrmntSec -> Section
mkReqrmntSec (ReqsProg [ReqsSub]
l) = [Section] -> Section
R.reqF ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (ReqsSub -> Section) -> [ReqsSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map ReqsSub -> Section
mkSubs [ReqsSub]
l
  where
    mkSubs :: ReqsSub -> Section
    mkSubs :: ReqsSub -> Section
mkSubs (FReqsSub  [ConceptInstance]
frs [LabelledContent]
tbs) = [Contents] -> Section
R.fReqF ([ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD [ConceptInstance]
frs [Contents] -> [Contents] -> [Contents]
forall a. [a] -> [a] -> [a]
++ (LabelledContent -> Contents) -> [LabelledContent] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map LabelledContent -> Contents
LlC [LabelledContent]
tbs)
    mkSubs (NonFReqsSub [ConceptInstance]
nfrs) = [Contents] -> Section
R.nfReqF ([ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD [ConceptInstance]
nfrs)

-- ** Likely Changes

-- | Helper for making the Likely Changes section.
mkLCsSec :: LCsSec -> Section
mkLCsSec :: LCsSec -> Section
mkLCsSec (LCsProg [ConceptInstance]
c) = [Contents] -> [Section] -> Section
SRS.likeChg (CI -> [ConceptInstance] -> Contents
forall n. Idea n => n -> [ConceptInstance] -> Contents
introChgs CI
likelyChg [ConceptInstance]
cContents -> [Contents] -> [Contents]
forall a. a -> [a] -> [a]
: [ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD [ConceptInstance]
c) []

-- ** Unlikely Changes

-- | Helper for making the Unikely Changes section.
mkUCsSec :: UCsSec -> Section
mkUCsSec :: UCsSec -> Section
mkUCsSec (UCsProg [ConceptInstance]
c) = [Contents] -> [Section] -> Section
SRS.unlikeChg (CI -> [ConceptInstance] -> Contents
forall n. Idea n => n -> [ConceptInstance] -> Contents
introChgs CI
unlikelyChg  [ConceptInstance]
c Contents -> [Contents] -> [Contents]
forall a. a -> [a] -> [a]
: [ConceptInstance] -> [Contents]
forall c.
(Referable c, HasShortName c, Definition c) =>
[c] -> [Contents]
mkEnumSimpleD [ConceptInstance]
c) []

-- | Intro paragraph for likely and unlikely changes
introChgs :: Idea n => n -> [ConceptInstance] -> Contents
introChgs :: forall n. Idea n => n -> [ConceptInstance] -> Contents
introChgs n
xs [] = Sentence -> Contents
mkParagraph (Sentence -> Contents) -> Sentence -> Contents
forall a b. (a -> b) -> a -> b
$ [n] -> Sentence
forall n. NamedIdea n => [n] -> Sentence
emptySectSentPlu [n
xs]
introChgs n
xs [ConceptInstance]
_ = [Sentence] -> Contents
foldlSP [String -> Sentence
S String
"This", IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
section_, String -> Sentence
S String
"lists the",
  n -> Sentence
forall n. Idea n => n -> Sentence
introduceAbbPlrl n
xs, String -> Sentence
S String
"to be made to the", IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
software]

-- ** Traceability

-- | Helper for making the Traceability Matrices and Graphs section.
mkTraceabilitySec :: TraceabilitySec -> SmithEtAlSRS -> Section
mkTraceabilitySec :: TraceabilitySec -> SmithEtAlSRS -> Section
mkTraceabilitySec (TraceabilityProg [TraceConfig]
progs) SmithEtAlSRS
si = [LabelledContent]
-> [Sentence] -> [Contents] -> String -> [Section] -> Section
TG.traceMGF [LabelledContent]
trace
  ((TraceConfig -> Sentence) -> [TraceConfig] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (\(TraceConfig UID
_ [Sentence]
pre Sentence
_ [TraceViewCat]
_ [TraceViewCat]
_) -> SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List [Sentence]
pre) [TraceConfig]
fProgs)
  ((LabelledContent -> Contents) -> [LabelledContent] -> [Contents]
forall a b. (a -> b) -> [a] -> [b]
map LabelledContent -> Contents
LlC [LabelledContent]
trace) (SmithEtAlSRS
si SmithEtAlSRS -> Getting String SmithEtAlSRS String -> String
forall s a. s -> Getting a s a -> a
^. Getting String SmithEtAlSRS String
forall c. HasSmithEtAlSRS c => Lens' c String
Lens' SmithEtAlSRS String
programName) []
  where
    trace :: [LabelledContent]
trace = (TraceConfig -> LabelledContent)
-> [TraceConfig] -> [LabelledContent]
forall a b. (a -> b) -> [a] -> [b]
map (\(TraceConfig UID
u [Sentence]
_ Sentence
desc [TraceViewCat]
cols [TraceViewCat]
rows) ->
      UID
-> Sentence
-> [TraceViewCat]
-> [TraceViewCat]
-> SmithEtAlSRS
-> LabelledContent
TM.generateTraceTableView UID
u Sentence
desc [TraceViewCat]
cols [TraceViewCat]
rows SmithEtAlSRS
si) [TraceConfig]
fProgs
    fProgs :: [TraceConfig]
fProgs = (TraceConfig -> Bool) -> [TraceConfig] -> [TraceConfig]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(TraceConfig UID
_ [Sentence]
_ Sentence
_ [TraceViewCat]
cols [TraceViewCat]
rows) ->
      Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Sentence] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (([UID] -> [UID]) -> SmithEtAlSRS -> [Sentence]
header ([TraceViewCat] -> SmithEtAlSRS -> [UID] -> [UID]
TM.layoutUIDs [TraceViewCat]
rows SmithEtAlSRS
si) SmithEtAlSRS
si)
         Bool -> Bool -> Bool
|| [Sentence] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (([UID] -> [UID]) -> SmithEtAlSRS -> [Sentence]
header ([TraceViewCat] -> SmithEtAlSRS -> [UID] -> [UID]
TM.layoutUIDs [TraceViewCat]
cols SmithEtAlSRS
si) SmithEtAlSRS
si)) [TraceConfig]
progs

-- | Helper to get headers of rows and columns
header :: ([UID] -> [UID]) -> SmithEtAlSRS -> [Sentence]
header :: ([UID] -> [UID]) -> SmithEtAlSRS -> [Sentence]
header [UID] -> [UID]
f = (SmithEtAlSRS -> [UID]) -> SmithEtAlSRS -> [Sentence]
TM.traceMHeader ([UID] -> [UID]
f ([UID] -> [UID])
-> (SmithEtAlSRS -> [UID]) -> SmithEtAlSRS -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map UID [UID] -> [UID]
forall k a. Map k a -> [k]
Map.keys (Map UID [UID] -> [UID])
-> (SmithEtAlSRS -> Map UID [UID]) -> SmithEtAlSRS -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SmithEtAlSRS
-> Getting (Map UID [UID]) SmithEtAlSRS (Map UID [UID])
-> Map UID [UID]
forall s a. s -> Getting a s a -> a
^. Getting (Map UID [UID]) SmithEtAlSRS (Map UID [UID])
forall c. HasSmithEtAlSRS c => Lens' c (Map UID [UID])
Lens' SmithEtAlSRS (Map UID [UID])
refbyTable))

-- ** Off the Shelf Solutions

-- | Helper for making the Off-the-Shelf Solutions section.
mkOffShelfSolnSec :: OffShelfSolnsSec -> Section
mkOffShelfSolnSec :: OffShelfSolnsSec -> Section
mkOffShelfSolnSec (OffShelfSolnsProg [Contents]
cs) = [Contents] -> [Section] -> Section
SRS.offShelfSol [Contents]
cs []

-- ** Auxiliary Constants

-- | Helper for making the Values of Auxiliary Constants section.
mkAuxConsSec :: AuxConstntSec -> Section
mkAuxConsSec :: AuxConstntSec -> Section
mkAuxConsSec (AuxConsProg CI
key [ConstQDef]
listOfCons) = CI -> [ConstQDef] -> Section
forall a. Idea a => a -> [ConstQDef] -> Section
AC.valsOfAuxConstantsF CI
key ([ConstQDef] -> Section) -> [ConstQDef] -> Section
forall a b. (a -> b) -> a -> b
$ [ConstQDef] -> [ConstQDef]
forall a. HasSymbol a => [a] -> [a]
sortBySymbol [ConstQDef]
listOfCons

-- ** References

-- | Helper for making the References section.
mkBib :: BibRef -> Section
mkBib :: BibRef -> Section
mkBib BibRef
bib = [Contents] -> [Section] -> Section
SRS.reference [UnlabelledContent -> Contents
UlC (UnlabelledContent -> Contents) -> UnlabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc (BibRef -> RawContent
Bib BibRef
bib)] []

-- ** Appendix

-- | Helper for making the Appendix section.
mkAppndxSec :: AppndxSec -> Section
mkAppndxSec :: AppndxSec -> Section
mkAppndxSec (AppndxProg [Contents]
cs) = [Contents] -> [Section] -> Section
SRS.appendix [Contents]
cs []

-- ** Find Table of Contents

-- Find more concise way to do this
-- | Finds whether the Table of Contents is in a SRSDecl.
findToC :: SRSDecl -> ShowTableOfContents
findToC :: SRSDecl -> ShowTableOfContents
findToC [] = ShowTableOfContents
NoToC
findToC (DocSection
DD.TableOfContents:SRSDecl
_) = ShowTableOfContents
ToC
findToC (DocSection
_:SRSDecl
dds) = SRSDecl -> ShowTableOfContents
findToC SRSDecl
dds