diff --git a/code/drasil-database/lib/Drasil/Database/UIDRef.hs b/code/drasil-database/lib/Drasil/Database/UIDRef.hs index 135c2dfcd4..5955ab33f7 100644 --- a/code/drasil-database/lib/Drasil/Database/UIDRef.hs +++ b/code/drasil-database/lib/Drasil/Database/UIDRef.hs @@ -1,7 +1,7 @@ module Drasil.Database.UIDRef ( -- * 'UID' References - UIDRef, hide, unhide, unhideOrErr, - UnitypedUIDRef, hideUni, unhideUni, unhideUniOrErr + UIDRef, hide, unhide, unhideOrErr, raw, + UnitypedUIDRef, hideUni, unhideUni, unhideUniOrErr, rawUni ) where import Control.Lens ((^.)) @@ -30,9 +30,13 @@ hide = UIDRef . (^. uid) unhide :: IsChunk t => UIDRef t -> ChunkDB -> Maybe t unhide (UIDRef u) = find u +-- | Get the raw 'UID' from a 'UIDRef'. +raw :: UIDRef t -> UID +raw (UIDRef u) = u + -- | Find a chunk by a 'UIDRef', erroring if not found. unhideOrErr :: IsChunk t => UIDRef t -> ChunkDB -> t -unhideOrErr tu cdb = fromMaybe (error "Typed UID dereference failed.") (unhide tu cdb) +unhideOrErr tu cdb = fromMaybe (error $ "Typed UID dereference failed for UID: " ++ show (raw tu)) (unhide tu cdb) -- | A variant of 'UIDRef' without type information about the chunk being -- referred to, effectively treating chunks as being "unityped." @@ -54,3 +58,7 @@ unhideUni (UnitypedUIDRef u) = find u -- | Find a chunk by its 'UnitypedUIDRef', erroring if not found. unhideUniOrErr :: IsChunk t => UnitypedUIDRef -> ChunkDB -> t unhideUniOrErr tu cdb = fromMaybe (error "Untyped UID dereference failed.") (unhideUni tu cdb) + +-- | Get the raw 'UID' from a 'UnitypedUIDRef'. +rawUni :: UnitypedUIDRef -> UID +rawUni (UnitypedUIDRef u) = u diff --git a/code/drasil-docLang/lib/Drasil/DocDecl.hs b/code/drasil-docLang/lib/Drasil/DocDecl.hs index 5f89a05073..f1ead4741a 100644 --- a/code/drasil-docLang/lib/Drasil/DocDecl.hs +++ b/code/drasil-docLang/lib/Drasil/DocDecl.hs @@ -15,7 +15,7 @@ import qualified Drasil.DocumentLanguage.Core as DL (DocSection(..), RefSec(..), ReqsSub(..), LCsSec(..), UCsSec(..), TraceabilitySec(..), AuxConstntSec(..), AppndxSec(..), OffShelfSolnsSec(..), DerivationDisplay) -import Drasil.Database (HasUID(..), findAll) +import Drasil.Database (HasUID(..), findAll, IsChunk) import Drasil.System import Language.Drasil hiding (sec) @@ -85,9 +85,9 @@ data SCSSub where -- | Instance models. IMs :: [Sentence] -> Fields -> DL.DerivationDisplay -> SCSSub -- | Constraints. - Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub + Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub -- | Properties of a correct solution. - CorrSolnPpties :: (Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub + CorrSolnPpties :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub -- | Requirements section (wraps 'ReqsSub' subsections). newtype ReqrmntSec = ReqsProg [ReqsSub] diff --git a/code/drasil-docLang/lib/Drasil/DocumentLanguage/Core.hs b/code/drasil-docLang/lib/Drasil/DocumentLanguage/Core.hs index 53df0f5d84..96f3ff45e9 100644 --- a/code/drasil-docLang/lib/Drasil/DocumentLanguage/Core.hs +++ b/code/drasil-docLang/lib/Drasil/DocumentLanguage/Core.hs @@ -4,7 +4,7 @@ module Drasil.DocumentLanguage.Core where import Data.Generics.Multiplate (Multiplate(multiplate, mkPlate)) -import Drasil.Database (UID) +import Drasil.Database (UID, IsChunk) import Language.Drasil hiding (Manual, Verb) -- Manual - Citation name conflict. FIXME: Move to different namespace import Theory.Drasil (DataDefinition, GenDefn, InstanceModel, TheoryModel) @@ -184,11 +184,11 @@ data SCSSub where -- | Instance Models. IMs :: [Sentence] -> Fields -> [InstanceModel] -> DerivationDisplay -> SCSSub -- | Constraints. - Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub + Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub -- Sentence -> [LabelledContent] Fields -> [UncertainWrapper] -> [ConstrainedChunk] -> SCSSub --FIXME: temporary definition? --FIXME: Work in Progress ^ -- | Properties of a correct solution. - CorrSolnPpties :: (Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub + CorrSolnPpties :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> SCSSub -- | Choose whether to show or hide the derivation of an expression. data DerivationDisplay = ShowDerivation diff --git a/code/drasil-docLang/lib/Drasil/Sections/Requirements.hs b/code/drasil-docLang/lib/Drasil/Sections/Requirements.hs index 9a56d56046..3f80e9b01e 100644 --- a/code/drasil-docLang/lib/Drasil/Sections/Requirements.hs +++ b/code/drasil-docLang/lib/Drasil/Sections/Requirements.hs @@ -17,7 +17,7 @@ import Utils.Drasil (stringList, mkTable) import Control.Lens ((^.)) import Data.Bifunctor (bimap) -import Drasil.Database (HasUID(..)) +import Drasil.Database (HasUID(..), IsChunk) import Language.Drasil import Language.Drasil.Chunk.Concept.NamedCombinators import qualified Language.Drasil.Sentence.Combinators as S @@ -47,7 +47,7 @@ reqF = SRS.require [reqIntro] -- The resulting requirement sentence is of the form: "Inputs the values from -- @table_ref@, which define @description@". If the description is 'Nothing', -- the sentence is: "Inputs the values from @table_ref@". -inReqWTab :: (Quantity q, MayHaveUnit q) => Maybe Sentence -> [q] -> (ConceptInstance, LabelledContent) +inReqWTab :: (IsChunk q, Quantity q, MayHaveUnit q) => Maybe Sentence -> [q] -> (ConceptInstance, LabelledContent) inReqWTab mdesc qs = (ci, tbl) where tbl = mkInputPropsTable qs @@ -143,7 +143,7 @@ mkSecurityNFR refAddress lbl = cic refAddress (foldlSent [ ]) lbl nonFuncReqDom -- | Creates an Input Data Table for use in the Functional Requirments section. Takes a list of wrapped variables and something that is 'Referable'. -mkInputPropsTable :: (Quantity i, MayHaveUnit i) => +mkInputPropsTable :: (IsChunk i, Quantity i, MayHaveUnit i) => [i] -> LabelledContent mkInputPropsTable [] = mkRawLC (Paragraph EmptyS) reqInputsRef mkInputPropsTable reqInputs = mkRawLC (Table [atStart symbol_, atStart description, atStart' unit_] @@ -155,14 +155,14 @@ reqInputsRef :: Reference reqInputsRef = makeTabRef' (reqInput ^. uid) -- | Creates a table for use in the Functional Requirments section. Takes a list of tuples containing variables and sources, a label, and a caption. -mkValsSourceTable :: (Quantity i, MayHaveUnit i, Concept i) => +mkValsSourceTable :: (IsChunk i, Quantity i, MayHaveUnit i, Concept i) => [(i, Sentence)] -> String -> Sentence -> LabelledContent mkValsSourceTable vals labl cap = llccTab labl $ Table [atStart symbol_, atStart description, S "Source", atStart' unit_] (mkTable [ch . fst, atStart . fst, snd, toSentence . fst] $ sortBySymbolTuple vals) cap True -mkQRTuple :: (HasOutput i, HasShortName i, Referable i) => [i] -> [(DefinedQuantityDict, Sentence)] +mkQRTuple :: (IsChunk i, HasOutput i, HasShortName i, Referable i) => [i] -> [(DefinedQuantityDict, Sentence)] mkQRTuple = map (\c -> (c ^. output, refS c)) -mkQRTupleRef :: (Quantity i, MayHaveUnit i, Concept i, HasShortName r, Referable r) => [i] -> [r] -> [(DefinedQuantityDict, Sentence)] +mkQRTupleRef :: (Quantity i, MayHaveUnit i, Concept i, HasShortName r, Referable r) =>[i] -> [r] -> [(DefinedQuantityDict, Sentence)] mkQRTupleRef = zipWith (curry (bimap dqdWr refS)) diff --git a/code/drasil-docLang/lib/Drasil/Sections/SpecificSystemDescription.hs b/code/drasil-docLang/lib/Drasil/Sections/SpecificSystemDescription.hs index 6fadec6ab3..dd44a8b8b2 100644 --- a/code/drasil-docLang/lib/Drasil/Sections/SpecificSystemDescription.hs +++ b/code/drasil-docLang/lib/Drasil/Sections/SpecificSystemDescription.hs @@ -26,7 +26,7 @@ import Control.Lens ((^.), over) import Data.Maybe -- rest of Drasil -import Drasil.Database (UID, HasUID(..), showUID) +import Drasil.Database (UID, HasUID(..), showUID, IsChunk) import Data.Drasil.Concepts.Documentation (assumption, column, constraint, datum, datumConstraint, inDatumConstraint, outDatumConstraint, definition, element, general, goalStmt, information, input_, limitation, model, output_, @@ -200,7 +200,7 @@ inModelIntro r1 r2 r3 r4 = foldlSP [S "This", phrase section_, namedRef r4 (plural genDefn)] -- | Constructor for Data Constraints section. Takes a trailing 'Sentence' (use 'EmptyS' if none) and data constraints. -datConF :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => +datConF :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> Section datConF _ [] = SRS.datCon [mkParagraph $ emptySectSentPlu [datumConstraint]] [] datConF t c = SRS.datCon [dataConstraintParagraph t, LlC $ inDataConstTbl c] [] @@ -253,7 +253,7 @@ mkDataConstraintTable col rf lab = llccTab' rf $ uncurry Table (mkTableFromColumns col) lab True -- | Creates the input Data Constraints Table. -inDataConstTbl :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => +inDataConstTbl :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => [c] -> LabelledContent inDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch $ sortBySymbol qlst), (titleize' physicalConstraint, map fmtPhys $ sortBySymbol qlst), @@ -265,7 +265,7 @@ inDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch $ sortBySymbol qls getRVal c = fromMaybe (error $ "getRVal found no Expr for " ++ showUID c) (c ^. reasVal) -- | Creates the output Data Constraints Table. -outDataConstTbl :: (Quantity c, Constrained c) => [c] -> LabelledContent +outDataConstTbl :: (IsChunk c, Quantity c, Constrained c) => [c] -> LabelledContent outDataConstTbl qlst = mkDataConstraintTable [(S "Var", map ch qlst), (titleize' physicalConstraint, map fmtPhys qlst), (titleize' softwareConstraint, map fmtSfwr qlst)] (outDatumConstraint ^. uid) $ @@ -286,7 +286,7 @@ fmtSfwr :: (Constrained c, Quantity c) => c -> Sentence fmtSfwr c = foldConstraints c $ filter isSfwrC (c ^. constraints) -- | Creates the Properties of a Correct Solution section. -propCorSolF :: (Quantity c, Constrained c) => [c] -> [Contents] -> Section +propCorSolF :: (IsChunk c, Quantity c, Constrained c) => [c] -> [Contents] -> Section propCorSolF [] [] = SRS.propCorSol [mkParagraph $ emptySectSentPlu [propOfCorSol]] [] propCorSolF [] con = SRS.propCorSol con [] propCorSolF c con = SRS.propCorSol ([propsIntro, LlC $ outDataConstTbl c] ++ con) [] diff --git a/code/drasil-docLang/lib/Drasil/Sentence/Combinators.hs b/code/drasil-docLang/lib/Drasil/Sentence/Combinators.hs index f2023452e0..013259b629 100644 --- a/code/drasil-docLang/lib/Drasil/Sentence/Combinators.hs +++ b/code/drasil-docLang/lib/Drasil/Sentence/Combinators.hs @@ -23,11 +23,10 @@ import Control.Lens ((^.)) import Data.Decimal (DecimalRaw, realFracToDecimal) import Data.List (transpose) -import Drasil.Database (HasUID) +import Drasil.Database (IsChunk) import Language.Drasil (ConceptChunk, DefinesQuantity(defLhs) , UnitDefn, MayHaveUnit(..) , UnitalChunk , HasUnitSymbol(usymb), Quantity, Concept, Definition(defn), NamedIdea(..) - , HasSymbol , HasShortName(..) , short, atStart, titleize, phrase, plural , Section , ItemType(..), ListType(Bullet) , ModelExpr , refS, namedRef , Sentence(S, Percent, (:+:), Sy, EmptyS), eS @@ -67,7 +66,7 @@ definedIn'' :: (Referable r, HasShortName r) => r -> Sentence definedIn'' q = S "defined" `S.in_` refS q -- | Takes a 'Symbol' and its 'Reference' (does not append a period at the end!). Outputs as "@symbol@ is defined in @source@". -definedIn''' :: (HasSymbol q, HasUID q, Referable r, HasShortName r) => q -> r -> Sentence +definedIn''' :: (IsChunk q, Quantity q, Referable r, HasShortName r) => q -> r -> Sentence definedIn''' q src = ch q `S.is` S "defined in" +:+ refS src -- | Zip helper function enumerates abbreviations and zips it with list of 'ItemType': @@ -192,7 +191,7 @@ tAndDWAcc temp = Flat $ atStart temp +:+. (sParen (short temp) `sDash` capSent ( -- | Helpful combinators for making 'Sentence's into Terminologies with Definitions. -- Returns of the form: "@term (symbol) - termDefinition@". -tAndDWSym :: (Concept s, Quantity a) => s -> a -> ItemType +tAndDWSym :: (IsChunk a, Concept s, Quantity a) => s -> a -> ItemType tAndDWSym tD sym = Flat $ atStart tD +:+. (sParen (ch sym) `sDash` capSent (tD ^. defn)) -- | Helpful combinators for making 'Sentence's into Terminologies with Definitions. diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs index 1708e83df8..c9778ff40a 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs @@ -2,6 +2,7 @@ module Drasil.GlassBR.Assumptions (assumpGT, assumpGC, assumpES, assumpSV, assumpGL, assumpBC, assumpRT, assumpLDFC, assumptionConstants, assumptions) where +import Drasil.Database (IsChunk) import Language.Drasil hiding (organization) import qualified Language.Drasil.Development as D import qualified Drasil.DocLang.SRS as SRS (valsOfAuxCons) @@ -84,7 +85,7 @@ responseTypeDesc :: Sentence responseTypeDesc = foldlSent [D.toSent $ atStartNP (the responseTy), S "considered in", short progName, S "is flexural"] -ldfConstantDesc :: (HasSymbol c, NamedIdea c) => c -> Sentence +ldfConstantDesc :: (IsChunk c, Quantity c) => c -> Sentence ldfConstantDesc mainConcept = foldlSent [S "With", phrase reference, S "to", refS assumpSV `sC` D.toSent (phraseNP (NP.the (value `of_` mainConcept))), sParen (ch mainConcept) `S.is` D.toSent (phraseNP (a_ constant)) diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/DataDefs.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/DataDefs.hs index 82784d5725..ce08022df6 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/DataDefs.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/DataDefs.hs @@ -5,7 +5,7 @@ module Drasil.GlassBR.DataDefs (dataDefs, aspRat, glaTyFac, glaTyFacQD, gtfRef, import Control.Lens ((^.)) import Prelude hiding (log, exp, sqrt) -import Drasil.Database (HasUID) +import Drasil.Database (IsChunk) import Language.Drasil import Theory.Drasil (DataDefinition, ddE) import qualified Language.Drasil.Sentence.Combinators as S @@ -150,7 +150,7 @@ gtfRef = definedIn glaTyFac hRef = definedIn' hFromt (S "and is based on the nominal thicknesses") --- Helper -stdVals :: (HasSymbol s, HasUID s) => [s] -> Sentence +stdVals :: (IsChunk s, Quantity s) => [s] -> Sentence stdVals s = foldlList Comma List (map ch s) +:+ sent +:+. refS assumpSV where sent = case s of [ ] -> error "stdVals needs quantities" [_] -> S "comes from" diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs index bdf59e54fe..db091f49d5 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs @@ -3,7 +3,7 @@ module Drasil.GlassBR.IMods (symb, iMods, pbIsSafe, lrIsSafe, instModIntro) wher import Control.Lens ((^.)) import Prelude hiding (exp) -import Drasil.Database (HasUID) +import Drasil.Database (IsChunk) import Drasil.Sentence.Combinators (definedIn', definedIn) import Language.Drasil import qualified Language.Drasil.Development as D @@ -215,6 +215,6 @@ qHtTlTolRef = definedIn tolPre riskRef = definedIn risk -- Helper -- -interpolating :: (HasUID s, HasSymbol s, Referable f, HasShortName f) => s -> f -> Sentence +interpolating :: (IsChunk s, Quantity s, Referable f, HasShortName f) => s -> f -> Sentence interpolating s f = foldlSent [ch s `S.is` S "obtained by interpolating from", plural datum, S "shown" `S.in_` refS f] diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs index bafbb94dc9..43fd11c1a2 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Constrained ( import Control.Lens ((^.), makeLenses, view) -import Drasil.Database (HasUID(..)) +import Drasil.Database (HasUID(..), HasChunkRefs(..)) import Language.Drasil.Chunk.Concept (cw, dcc, dccWDS) import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr, dqdNoUnit) @@ -38,6 +38,9 @@ data ConstrConcept = ConstrConcept { _defq :: DefinedQuantityDict } makeLenses ''ConstrConcept +instance HasChunkRefs ConstrConcept where + chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks. + -- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'ConstrConcept'. instance HasUID ConstrConcept where uid = defq . uid -- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'ConstrConcept'. diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs index fc50aa1343..b9bf281f32 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs @@ -15,7 +15,7 @@ module Language.Drasil.Chunk.Eq ( ) where import Control.Lens ((^.), view, lens, Lens', to) -import Drasil.Database (UID, HasUID(..)) +import Drasil.Database (UID, HasUID(..), HasChunkRefs(..)) import Language.Drasil.Chunk.UnitDefn (unitWrapper, MayHaveUnit(getUnit), UnitDefn) import Language.Drasil.Symbol (HasSymbol(symbol), Symbol) @@ -40,6 +40,9 @@ import Language.Drasil.WellTyped (RequiresChecking(..)) data QDefinition e where QD :: DefinedQuantityDict -> [UID] -> e -> QDefinition e +instance HasChunkRefs (QDefinition e) where + chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks. + qdQua :: Lens' (QDefinition e) DefinedQuantityDict qdQua = lens (\(QD qua _ _) -> qua) (\(QD _ ins e) qua' -> QD qua' ins e) diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/UncertainQuantity.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/UncertainQuantity.hs index a3ea3de78d..3bd35e0a7c 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/UncertainQuantity.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/UncertainQuantity.hs @@ -9,7 +9,7 @@ module Language.Drasil.Chunk.UncertainQuantity ( import Control.Lens ((^.), makeLenses, view) -import Drasil.Database (HasUID(..)) +import Drasil.Database (HasUID(..), HasChunkRefs(..)) import Language.Drasil.Chunk.DefinedQuantity (dqdWr) import Language.Drasil.Chunk.Constrained (ConstrConcept(..), cuc') @@ -32,6 +32,9 @@ import Language.Drasil.Uncertainty data UncertQ = UQ { _coco :: ConstrConcept , _unc'' :: Uncertainty } makeLenses ''UncertQ +instance HasChunkRefs UncertQ where + chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks. + -- | Equal if 'UID's are equal. instance Eq UncertQ where a == b = (a ^. uid) == (b ^. uid) -- | Finds 'UID' of the 'ConstrConcept' used to make the 'UncertQ'. diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs index 50f12aa053..ea9c6030fb 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs @@ -8,7 +8,7 @@ module Language.Drasil.Chunk.Unital ( import Control.Lens (makeLenses, view, (^.)) -import Drasil.Database (HasUID(..)) +import Drasil.Database (HasUID(..), HasChunkRefs(..)) import Language.Drasil.Chunk.Concept (dccWDS,cw) import Language.Drasil.Chunk.DefinedQuantity (DefinedQuantityDict, dqd, dqd', dqdWr) @@ -33,6 +33,9 @@ data UnitalChunk = UC { _defq' :: DefinedQuantityDict } makeLenses ''UnitalChunk +instance HasChunkRefs UnitalChunk where + chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks. + -- | Finds 'UID' of the 'DefinedQuantityDict' used to make the 'UnitalChunk'. instance HasUID UnitalChunk where uid = defq' . uid -- | Finds term ('NP') of the 'DefinedQuantityDict' used to make the 'UnitalChunk'. diff --git a/code/drasil-lang/lib/Language/Drasil/Sentence.hs b/code/drasil-lang/lib/Language/Drasil/Sentence.hs index 10bffd04e1..b93aab5472 100644 --- a/code/drasil-lang/lib/Language/Drasil/Sentence.hs +++ b/code/drasil-lang/lib/Language/Drasil/Sentence.hs @@ -10,24 +10,24 @@ module Language.Drasil.Sentence ( -- * Functions (+:+), (+:+.), (+:), (!.), capSent, headSent, ch, eS, eS', sC, sDash, sParen, sentencePlural, sentenceShort, - sentenceSymb, sentenceTerm, + sentenceTerm, sdep, shortdep, lnames, lnames', sentenceRefs ) where -import Control.Lens ((^.)) import Data.Char (toUpper) +import qualified Data.Set as Set -import Drasil.Database (HasChunkRefs(..), HasUID(..), UID) +import Drasil.Database (IsChunk, HasChunkRefs(..), UID, UIDRef, hide, raw) +import Language.Drasil.Chunk.NamedIdea (Idea) import Language.Drasil.ExprClasses (Express(express)) import Language.Drasil.ModelExpr.Lang (ModelExpr) import Language.Drasil.ModelExpr.Extract (meNames) import Language.Drasil.NounPhrase.Types (NP) import Language.Drasil.UnitLang (USymb) +import Language.Drasil.Space (HasSpace) import Language.Drasil.Symbol (HasSymbol, Symbol) -import qualified Data.Set as Set - -- | Used in 'Ch' constructor to determine the state of a term -- (can record whether something is in plural form, a singular term, or in short form). data SentenceStyle = PluralTerm @@ -60,7 +60,7 @@ data Sentence where -- This allows Sentences to hold plural forms of 'NamedIdea's. Ch :: SentenceStyle -> TermCapitalization -> UID -> Sentence -- | A branch of Ch dedicated to SymbolStyle only. - SyCh :: UID -> Sentence + SyCh :: (IsChunk t, Idea t, HasSpace t, HasSymbol t) => UIDRef t -> Sentence -- | Converts a unit symbol into a usable Sentence form. Sy :: USymb -> Sentence -- | Directly embeds a 'NP' @@ -90,8 +90,8 @@ eS' = E . express -- The HasSymbol is redundant, but on purpose -- | Gets a symbol and places it in a 'Sentence'. -ch :: (HasUID c, HasSymbol c) => c -> Sentence -ch x = SyCh (x ^. uid) +ch :: (IsChunk t, Idea t, HasSpace t, HasSymbol t) => t -> Sentence +ch s = SyCh $ hide s -- | Sentences can be concatenated. instance Semigroup Sentence where @@ -102,13 +102,11 @@ instance Monoid Sentence where mempty = EmptyS -- | Smart constructors for turning a 'UID' into a 'Sentence'. -sentencePlural, sentenceShort, sentenceSymb, sentenceTerm :: UID -> Sentence +sentencePlural, sentenceShort, sentenceTerm :: UID -> Sentence -- | Gets plural term of 'UID'. sentencePlural = Ch PluralTerm NoCap -- | Gets short form of 'UID'. sentenceShort = Ch ShortStyle NoCap --- | Gets symbol form of 'UID'. -sentenceSymb = SyCh -- | Gets singular form of 'UID'. sentenceTerm = Ch TermStyle NoCap @@ -161,7 +159,7 @@ getUIDs :: Sentence -> [UID] getUIDs (Ch ShortStyle _ _) = [] getUIDs (Ch TermStyle _ _) = [] getUIDs (Ch PluralTerm _ _) = [] -getUIDs (SyCh a) = [a] +getUIDs (SyCh a) = [raw a] getUIDs Sy {} = [] getUIDs NP {} = [] getUIDs S {} = [] diff --git a/code/drasil-lang/lib/Language/Drasil/Sentence/Generators.hs b/code/drasil-lang/lib/Language/Drasil/Sentence/Generators.hs index 2a719860a3..2111747226 100644 --- a/code/drasil-lang/lib/Language/Drasil/Sentence/Generators.hs +++ b/code/drasil-lang/lib/Language/Drasil/Sentence/Generators.hs @@ -7,6 +7,8 @@ module Language.Drasil.Sentence.Generators ( import Control.Lens ((^.)) +import Drasil.Database (IsChunk) + import Language.Drasil.Classes (NamedIdea(..), Quantity) import Language.Drasil.Development.Sentence (phrase) import Language.Drasil.Label.Type (Referable) @@ -26,7 +28,7 @@ fterms :: (NamedIdea c, NamedIdea d) => (NP -> NP -> t) -> c -> d -> t fterms f a b = f (a ^. term) (b ^. term) -- | Used when you want to say a term followed by its symbol. ex. "...using the Force F in...". -getTandS :: (Quantity a) => a -> Sentence +getTandS :: (IsChunk t, Quantity t) => t -> Sentence getTandS a = phrase a +:+ ch a -- | Uses an 'Either' type to check if a 'String' is valid - diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Helpers.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Helpers.hs index fa4f18e283..7c5de3fb2e 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Helpers.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Helpers.hs @@ -1,15 +1,16 @@ +{-# OPTIONS_GHC -Wno-redundant-constraints #-} -- | Printing helpers. module Language.Drasil.Printing.Import.Helpers where import Control.Lens ((^.)) import Data.Char (toUpper) +import Drasil.Database (UID, ChunkDB, findOrErr, raw, IsChunk, UIDRef) +import Drasil.Database.SearchTools (termResolve', TermAbbr(..)) import Language.Drasil (Stage(..), codeSymb, eqSymb, NounPhrase(..), Sentence(S), Symbol, TermCapitalization(..), titleizeNP, titleizeNP', - atStartNP, atStartNP', NP, DefinedQuantityDict) + atStartNP, atStartNP', NP, DefinedQuantityDict, HasSymbol) import Language.Drasil.Development (toSent) -import Drasil.Database (UID, ChunkDB, findOrErr) -import Drasil.Database.SearchTools (termResolve', TermAbbr(..)) import qualified Language.Drasil.Printing.AST as P import Language.Drasil.Printing.PrintingInformation (PrintingInformation, stg, sysdb) @@ -61,6 +62,14 @@ lookupC Implementation sm c = codeSymb (findOrErr c sm :: DefinedQuantityDict) lookupC' :: PrintingInformation -> UID -> Symbol lookupC' pinfo = lookupC (pinfo ^. stg) (pinfo ^. sysdb) +-- | Look up a symbol given a chunk database and a 'UID' associated with the +-- symbol. Hack: Always uses 'DefinedQuantityDict' as the chunk type to look up, +-- despite that not being the _actual type_ of the chunk being looked up. +lookupSymb :: (IsChunk t, HasSymbol t) => PrintingInformation -> UIDRef t -> Symbol +lookupSymb pinfo u = sytyF (pinfo ^. stg) (findOrErr (raw u) (pinfo ^. sysdb) :: DefinedQuantityDict) + where sytyF Equational = eqSymb + sytyF Implementation = codeSymb + -- | Look up a term given a chunk database and a 'UID' associated with the term. Also specifies capitalization lookupT :: PrintingInformation -> UID -> TermCapitalization -> Sentence lookupT sm c tCap = resolveCapT tCap $ longForm $ termResolve' (sm ^. sysdb) c diff --git a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Sentence.hs b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Sentence.hs index 2520d6e655..f0fd54e679 100644 --- a/code/drasil-printers/lib/Language/Drasil/Printing/Import/Sentence.hs +++ b/code/drasil-printers/lib/Language/Drasil/Printing/Import/Sentence.hs @@ -12,7 +12,7 @@ import qualified Language.Drasil.Printing.AST as P import Language.Drasil.Printing.PrintingInformation (PrintingInformation, refFind, sysdb) import Language.Drasil.Printing.Import.ModelExpr (modelExpr) -import Language.Drasil.Printing.Import.Helpers (lookupT, lookupS, lookupP, lookupC') +import Language.Drasil.Printing.Import.Helpers (lookupT, lookupS, lookupP, lookupSymb) import Language.Drasil.Printing.Import.Symbol (symbol, pUnit) -- * Main Function @@ -29,7 +29,7 @@ spec _ (Sy s) = P.E $ pUnit s spec sm (NP np) = spec sm (toSent $ phraseNP np) spec _ Percent = P.E $ P.MO P.Perc spec _ (P s) = P.E $ symbol s -spec sm (SyCh s) = P.E $ symbol $ lookupC' sm s +spec sm (SyCh s) = P.E $ symbol $ lookupSymb sm s -- First term is the tooltip, second term is the rendered short form spec sm (Ch ShortStyle caps s) = P.Tooltip (spec sm $ lookupT