Skip to content

Commit

Permalink
moved DType and makePairs for use in shortname setting hack; removed …
Browse files Browse the repository at this point in the history
…Data, Data', Theory that were causing import cycles with move (#926)
  • Loading branch information
niazim3 committed Aug 2, 2018
1 parent 535c446 commit 53ba95d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 96 deletions.
27 changes: 14 additions & 13 deletions code/drasil-docLang/Drasil/Sections/SolutionCharacterSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ sectionMap progName (SectionModel niname xs)
render :: (Idea c, HasSymbolTable s) => c -> s -> SubSec -> Section
render progName symMap item@(SectionModel niname _)
| compareID niname (Doc.assumption ^. uid) = assumptionSect item
| compareID niname (Doc.thModel ^. uid) = theoreticalModelSect item symMap progName
| compareID niname (Doc.genDefn ^. uid) = generalDefinitionSect item symMap
| compareID niname (Doc.inModel ^. uid) = instanceModelSect item symMap
| compareID niname (Doc.dataDefn ^. uid) = dataDefinitionSect item symMap
| compareID niname (Doc.dataConst ^. uid) = dataConstraintSect item
| compareID niname (Doc.termAndDef ^. uid) = termDefinitionSect item
| compareID niname (Doc.goalStmt ^. uid) = goalStatementSect item
| compareID niname (Doc.systemConstraint ^. uid) = systemConstraintSect item
| otherwise = genericSect item

{---| compareID niname (Doc.thModel ^. uid) = theoreticalModelSect item symMap progName
--| compareID niname (Doc.inModel ^. uid) = instanceModelSect item symMap
--| compareID niname (Doc.dataDefn ^. uid) = dataDefinitionSect item symMap-}

------------------------------
-- Section Render Functions --
------------------------------
Expand Down Expand Up @@ -318,21 +319,13 @@ assumptionSect (SectionModel _ xs) = SRS.assumpt
(assumpIntro:(pullContents xs)) (pullSections xs)


theoreticalModelSect :: (Idea a, HasSymbolTable s) => SubSec -> s -> a -> Section
{-theoreticalModelSect :: (Idea a, HasSymbolTable s) => SubSec -> s -> a -> Section
theoreticalModelSect (SectionModel _ xs) _ progName = SRS.thModel
((tModIntro progName):theoreticalModels ++
(pullContents xs)) (pullSections xs)
where theoreticalModels = map (UlC . ulcc) $ map symMap $ pullTMods xs
symMap = Definition . Theory

generalDefinitionSect :: (HasSymbolTable s) => SubSec -> s -> Section
generalDefinitionSect (SectionModel _ xs) _ = SRS.genDefn
(generalDefsIntro:contents) (pullSections xs)
where generalDefsIntro = generalDefinitionIntro contents
contents = (pullContents xs)


instanceModelSect :: (HasSymbolTable s) => SubSec -> s -> Section
instanceModelSect (SectionModel _ xs) _ = SRS.inModel
(iModIntro:instanceModels ++ (pullContents xs)) (pullSections xs)
Expand All @@ -345,7 +338,15 @@ dataDefinitionSect (SectionModel _ xs) _ = SRS.dataDefn
(dataIntro:dataDefinitions ++ (pullContents xs)) (pullSections xs)
where dataIntro = dataDefinitionIntro $ pullSents xs
symMap = Definition . Data'
dataDefinitions = map (UlC . ulcc . symMap) $ pullDDefs xs
dataDefinitions = map (UlC . ulcc . symMap) $ pullDDefs xs-}

generalDefinitionSect :: (HasSymbolTable s) => SubSec -> s -> Section
generalDefinitionSect (SectionModel _ xs) _ = SRS.genDefn
(generalDefsIntro:contents) (pullSections xs)
where generalDefsIntro = generalDefinitionIntro contents
contents = (pullContents xs)




dataConstraintSect :: SubSec -> Section
Expand Down
5 changes: 2 additions & 3 deletions code/drasil-lang/Language/Drasil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ import Language.Drasil.Document (section, fig, figWithWidth
, llcc, ulcc, Document(..)
, HasContents(accessContents)
, mkParagraph, mkFig, mkRawLC)
import Language.Drasil.Document.Core (DType(..)
, Contents(..), ListType(..), ItemType(..)
import Language.Drasil.Document.Core (Contents(..), ListType(..), ItemType(..)
, RawContent(..), ListTuple, MaxWidthPercent
, LabelledContent(..), UnlabelledContent(..) )
import Language.Drasil.Unicode -- all of it
Expand Down Expand Up @@ -351,7 +350,7 @@ import Language.Drasil.Misc -- all of it
import Language.Drasil.People (People, Person, person, HasName(..), manyNames
, person', personWM, personWM', mononym, name, nameStr, rendPersLFM,
rendPersLFM', rendPersLFM'')
import Language.Drasil.RefTypes(RefAdd, RefType(Cite))
import Language.Drasil.RefTypes(RefAdd, RefType(Cite), DType(..))
import Language.Drasil.Label (mkLabelRA, mkLabelRA', mkLabelRA'', mkEmptyLabel)
import Language.Drasil.Label.Core (getAdd)
--Should be in lang-dev package?
11 changes: 1 addition & 10 deletions code/drasil-lang/Language/Drasil/Document.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Language.Drasil.Classes (HasUID(uid), HasRefAddress(getRefAdd),
MayHaveLabel(getMaybeLabel), HasLabel(getLabel))

import Language.Drasil.Label (Label, getAdd, mkLabelRA, mkLabelRA', mkEmptyLabel)
import Language.Drasil.RefTypes (RefAdd)
import Language.Drasil.RefTypes (RefAdd, DType(..))
import Language.Drasil.Spec (Sentence(..))

import Control.Lens ((^.), makeLenses, Lens', set)
Expand All @@ -40,12 +40,6 @@ repUnd :: Char -> String
repUnd '_' = "."
repUnd c = c : []

getDefLabel :: DType -> Label
getDefLabel (Data c) = c ^. getLabel
getDefLabel (Data' c) = c ^. getLabel
getDefLabel (Theory c) = c ^. getLabel
getDefLabel (_) = mkEmptyLabel

instance HasContents Contents where
accessContents f (UlC c) = fmap (UlC . (\x -> set cntnts x c)) (f $ c ^. cntnts)
accessContents f (LlC c) = fmap (LlC . (\x -> set ctype x c)) (f $ c ^. ctype)
Expand Down Expand Up @@ -122,9 +116,6 @@ setSN prependSN sn = prependSN ++ concatMap repUnd (getStringSN sn)

-- | Automatically create the label for a definition
getDefName :: DType -> String
getDefName (Data c) = "DD:"
getDefName (Data' c) = "DD:"
getDefName (Theory c) = "T:"
getDefName TM = "T:"
getDefName DD = "DD:"
getDefName Instance = "IM:"
Expand Down
13 changes: 1 addition & 12 deletions code/drasil-lang/Language/Drasil/Document/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Language.Drasil.Expr (Expr)
import Language.Drasil.Label (Label)
import Language.Drasil.RefTypes (RefAdd)
import Language.Drasil.Spec (Sentence(..))
import Language.Drasil.RefTypes (DType(..))


data ListType = Bullet [(ItemType,Maybe RefAdd)] -- ^ Bulleted list
Expand Down Expand Up @@ -40,18 +41,6 @@ type Filepath = String
type Lbl = Sentence


--FIXME: Remove Data, Data', and Theory from below.
-- | Types of definitions
data DType = Data QDefinition -- ^ QDefinition is the chunk with the defining
-- equation used to generate the Data Definition
| Data' DataDefinition
| General
| Theory RelationConcept -- ^ Theoretical models use a relation as
-- their definition
| Instance
| TM
| DD

-- | Types of layout objects we deal with explicitly
data RawContent = Table [Sentence] [[Sentence]] Title Bool
-- ^ table has: header-row data(rows) label/caption showlabel?
Expand Down
6 changes: 1 addition & 5 deletions code/drasil-lang/Language/Drasil/Document/Extract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Language.Drasil.Chunk.Citation
import Language.Drasil.Chunk.ReqChunk
import Language.Drasil.Chunk.Eq (QDefinition)
import Language.Drasil.Chunk.References

import Language.Drasil.RefTypes(DType(..))
import Language.Drasil.Development.Unit(UnitDefn, MayHaveUnit(getUnit))

import Language.Drasil.Classes (NamedIdea(term),
Expand Down Expand Up @@ -57,8 +57,6 @@ egetCon (Defnt dt []) = [] ++ egetDtype dt
egetCon _ = []

egetDtype :: DType -> [Expr]
egetDtype (Data q) = egetQDef q
egetDtype (Theory t) = [t ^. relat]
egetDtype _ = []

egetQDef :: QDefinition -> [Expr]
Expand Down Expand Up @@ -107,8 +105,6 @@ getCon (Defnt _ []) = []
getCon _ = []

getDtype :: DType -> [Sentence]
getDtype (Data q) = getQDef q
getDtype (Theory t) = getTerm t ++ getDefn t
getDtype _ = []


Expand Down
14 changes: 11 additions & 3 deletions code/drasil-lang/Language/Drasil/RefTypes.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{-# LANGUAGE GADTs #-}
-- | Contains the types associated to references
module Language.Drasil.RefTypes(RefAdd, RefType(..)) where
module Language.Drasil.RefTypes(RefAdd, RefType(..), DType(..)) where

--import Language.Drasil.Document.Core (DType(..)) cannot be imported due to importcycles

-- | Types of definitions
data DType = General
| Instance
| TM
| DD

type RefAdd = String

-- | For building references. Defines the possible type of reference.
data RefType = Tab -- ^ Table
| Fig -- ^ Figure
| Sect -- ^ Section
| Def -- ^ Definition (includes theoretical models)
| Def DType -- ^ Definition (includes theoretical models) (DType used to set shortnames)
| Mod -- ^ Module
| Req -- ^ Requirement
| Assump -- ^ Assumption
Expand All @@ -27,7 +35,7 @@ instance Show RefType where
show Sect = "Section"
show Lbl = "Section" --FIXME: hack until section has labels
show Mod = "Module"
show Def = "Definition"
show (Def _)= "Definition"
show Req = "Requirement"
show Assump = "Assumption"
show LC = "Likely Change"
Expand Down
42 changes: 19 additions & 23 deletions code/drasil-lang/Language/Drasil/Reference.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# Language TemplateHaskell #-}
module Language.Drasil.Reference where

import Language.Drasil.RefTypes (RefType(..))
import Language.Drasil.RefTypes (RefType(..), DType(..))
import Control.Lens ((^.), Simple, Lens, makeLenses)
import Data.Function (on)
import Data.List (concatMap, find, groupBy, partition, sortBy)
Expand Down Expand Up @@ -223,31 +223,31 @@ instance Referable Citation where

instance Referable TheoryModel where
refAdd t = "T:" ++ t ^. uid
rType _ = Def
rType _ = Def TM

instance Referable GenDefn where
refAdd g = "GD:" ++ g ^. uid
rType _ = Def
rType _ = Def General

instance Referable QDefinition where -- FIXME: This could lead to trouble; need
-- to ensure sanity checking when building
-- Refs. Double-check QDef is a DD before allowing
-- FIXME: QDefinition should no longer be referable
-- after its Label is removed.
refAdd d = "DD:" ++ concatMap repUnd (d ^. uid)
rType _ = Def
rType _ = Def DD

instance Referable DataDefinition where
refAdd d = "DD:" ++ concatMap repUnd (d ^. uid)
rType _ = Def
rType _ = Def DD

instance Referable InstanceModel where
refAdd i = "IM:" ++ i^.uid
rType _ = Def
rType _ = Def Instance

instance Referable ConceptInstance where
refAdd i = i ^. uid
rType _ = Def
rType _ = Def Instance --note: not actually used

--FIXME: assumes reference to a direct Label is for a section
--Should refer to an object WITH a variable.
Expand All @@ -266,7 +266,7 @@ temp' r (Figure _ _ _) = "Figure:" ++ r
temp' r (Graph _ _ _ _) = "Figure:" ++ r
temp' r (EqnBlock _) = "Equation:" ++ r
temp' _ (Definition d) = getDefName d --fixme: to be removed
temp' r (Defnt _ _ ) = concatMap repUnd r
temp' r (Defnt _ _) = concatMap repUnd r
temp' r (Requirement rc) = r
temp' r (Assumption ca) = r
temp' r (Change lcc) = r
Expand All @@ -278,8 +278,8 @@ temp :: RawContent -> RefType
temp (Table _ _ _ _) = Tab
temp (Figure _ _ _) = Fig
temp (Graph _ _ _ _) = Fig
temp (Definition _) = Def
temp (Defnt _ _) = Def
temp (Definition _) = Def DD --fixme: to be removed completely
temp (Defnt x _) = Def x
temp (Requirement r) = rType r
temp (Assumption a) = rType a
temp (Change l) = rType l
Expand Down Expand Up @@ -356,20 +356,16 @@ customRef :: (HasShortName l, Referable l) => l -> ShortName -> Sentence
customRef r n = Ref (rType r) (refAdd r) (shortname' $ temp (rType r) n)
where
temp :: RefType -> ShortName -> String
temp Tab s = setSN "" s
temp Fig s = setSN "" s
temp Sect s = setSN "" s
temp Def s = setSN "" s
temp Mod s = setSN "" s
temp Req s = setSN "" s
temp Assump s = setSN "" s
temp LC s = setSN "" s
temp UC s = setSN "" s
temp EqnB s = setSN "" s
temp Cite s = setSN "" s
temp Goal s = setSN "" s
temp PSD s = setSN "" s
temp (Def dtp) s = setSN (getDefName dtp) s
temp Req s = setSN "" s
temp Assump s = setSN "A:" s
temp LC s = setSN "LC:" s
temp UC s = setSN "UC:" s
temp EqnB s = setSN "" s
temp Goal s = setSN "GS:" s
temp PSD s = setSN "PS:" s
temp Lbl s = setSN "" s
temp _ s = setSN "" s

-- This works for passing the correct id to the reference generator for Assumptions,
-- Requirements and Likely Changes but I question whether we should use it.
Expand Down
6 changes: 2 additions & 4 deletions code/drasil-printers/Language/Drasil/HTML/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Arrow (second)
import qualified Language.Drasil as L (People, Person, StyleGuide(APA, MLA, Chicago),
CitationKind(Misc, Book, MThesis, PhDThesis, Article),
Symbol(Corners, Concat, Special, Atomic, Empty, Atop), USymb(US),
DType(DD, TM, Instance, General, Theory, Data), MaxWidthPercent,
DType(DD, TM, Instance, General), MaxWidthPercent,
Decoration(Prime, Hat, Vector), Document, HasSymbolTable, nameStr,
rendPersLFM, rendPersLFM', rendPersLFM'', special, bibStyleH)

Expand Down Expand Up @@ -262,9 +262,7 @@ makeColumns = vcat . map (td . p_spec)
makeDefn :: L.DType -> [(String,[LayoutObj])] -> Doc -> Doc
makeDefn _ [] _ = error "L.Empty definition"
makeDefn dt ps l = refwrap l $ wrap "table" [dtag dt] (makeDRows ps)
where dtag (L.Data _) = "ddefn"
dtag (L.Theory _) = "tdefn"
dtag (L.General) = "gdefn"
where dtag (L.General) = "gdefn"
dtag (L.Instance) = "idefn"
dtag (L.TM) = "tdefn"
dtag (L.DD) = "ddefn"
Expand Down
24 changes: 2 additions & 22 deletions code/drasil-printers/Language/Drasil/Printing/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ layLabelled sm x@(LblC _ (Defnt dtyp pairs)) = T.Definition
(P.S $ getAdd (x ^. getRefAdd))
where layPairs = map (\(x,y) -> (x, map (lay sm) y))
layLabelled sm (LblC _ (Paragraph c)) = T.Paragraph (spec sm c)
layLabelled sm (LblC _ (Definition c)) = T.Definition c (makePairs sm c)
(P.S "nolabel8")
layLabelled sm (LblC _ (Definition c)) = T.Definition c [("nolabel!", [T.Paragraph $ P.EmptyS])] (P.S "nolabel8")
layLabelled sm (LblC _ (Enumeration cs)) = T.List $ makeL sm cs
layLabelled sm (LblC _ (Bib bib)) = T.Bib $ map (layCite sm) bib

Expand All @@ -293,7 +292,7 @@ layUnlabelled sm (Table hdr lls t b) = T.Table ["table"]
((map (spec sm) hdr) : (map (map (spec sm)) lls)) (P.S "nolabel0") b (spec sm t)
layUnlabelled sm (Paragraph c) = T.Paragraph (spec sm c)
layUnlabelled sm (EqnBlock c) = T.HDiv ["equation"] [T.EqnBlock (P.E (expr c sm))] P.EmptyS
layUnlabelled sm (Definition c) = T.Definition c (makePairs sm c) (P.S "nolabel1")
layUnlabelled sm (Definition c) = T.Definition c [("nolabel!", [T.Paragraph $ P.EmptyS])] (P.S "nolabel1")
layUnlabelled sm (Enumeration cs) = T.List $ makeL sm cs
layUnlabelled sm (Figure c f wp) = T.Figure (P.S "nolabel2") (spec sm c) f wp
layUnlabelled sm (Requirement r) = T.ALUR T.Requirement
Expand Down Expand Up @@ -354,25 +353,6 @@ item sm (Nested t s) = P.Nested (spec sm t) (makeL sm s)
labref :: Maybe RefAdd -> Maybe P.Spec
labref l = maybe Nothing (\z -> Just $ P.S z) l

-- | Translates definitions
-- (Data defs, General defs, Theoretical models, etc.)
makePairs :: HasSymbolTable ctx => ctx -> DType -> [(String,[T.LayoutObj])]
makePairs m (Data c) = [
("Label", [T.Paragraph $ spec m (titleize $ c ^. term)]),
("Units", [T.Paragraph $ spec m (unitToSentence c)]),
("Equation", [T.HDiv ["equation"] [eqnStyle numberedDDEquations $ buildEqn m c] P.EmptyS]),
("Description", [T.Paragraph $ buildDDDescription m c])
]
makePairs m (Theory c) = [
("Label", [T.Paragraph $ spec m (titleize $ c ^. term)]),
("Equation", [T.HDiv ["equation"] [eqnStyle numberedTMEquations $ P.E (expr (c ^. relat) m)] P.EmptyS]),
("Description", [T.Paragraph (spec m (c ^. defn))])
]
makePairs _ General = error "Not yet implemented"
makePairs _ Instance = error "Not yet implemented"
makePairs _ TM = error "Not yet implemented"
makePairs _ DD = error "Not yet implemented"

-- Toggle equation style
eqnStyle :: Bool -> T.Contents -> T.LayoutObj
eqnStyle b = if b then T.EqnBlock else T.Paragraph
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-printers/Language/Drasil/TeX/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ spec (Sy s) = p_unit s
spec (Sp s) = pure $ text $ unPL $ L.special s
spec HARDNL = pure $ text "\\newline"
spec (Ref t@RT.Sect r _ _) = sref (show t) (pure $ text r)
spec (Ref t@RT.Def r _ _) = hyperref (show t) (pure $ text r)
spec (Ref t@(RT.Def _) r _ _) = hyperref (show t) (pure $ text r)
spec (Ref RT.Mod r _ _) = mref (pure $ text r)
spec (Ref RT.Req r _ _) = rref (pure $ text r)
spec (Ref RT.Assump r _ _) = aref (pure $ text r)
Expand Down

1 comment on commit 53ba95d

@niazim3
Copy link
Collaborator Author

@niazim3 niazim3 commented on 53ba95d Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contributes to #929.

Please sign in to comment.