{-# Language TemplateHaskell #-}
module Language.Drasil.Chunk.Concept.Core(
ConceptChunk(ConDict)
, ConceptInstance(ConInst)
, sDom)
where
import Language.Drasil.ShortName (HasShortName(..), ShortName)
import Language.Drasil.Classes (NamedIdea(term), Idea(getA),
Definition(defn), ConceptDomain(cdom))
import Language.Drasil.Chunk.NamedIdea (IdeaDict)
import Language.Drasil.Label.Type ((+::+), defer, name, raw,
LblType(..), Referable(..), HasRefAddress(..))
import Language.Drasil.Sentence (Sentence)
import Language.Drasil.UID (UID, HasUID(..))
import Control.Lens (makeLenses, (^.), view)
sDom :: [UID] -> UID
sDom :: [UID] -> UID
sDom [UID
d] = UID
d
sDom [UID]
d = forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"Expected ConceptDomain to have a single domain, found " forall a. [a] -> [a] -> [a]
++
forall a. Show a => a -> [Char]
show (forall (t :: * -> *) a. Foldable t => t a -> Int
length [UID]
d) forall a. [a] -> [a] -> [a]
++ [Char]
" instead."
data ConceptChunk = ConDict { ConceptChunk -> IdeaDict
_idea :: IdeaDict
, ConceptChunk -> Sentence
_defn' :: Sentence
, ConceptChunk -> [UID]
cdom' :: [UID]
}
makeLenses ''ConceptChunk
instance Eq ConceptChunk where ConceptChunk
c1 == :: ConceptChunk -> ConceptChunk -> Bool
== ConceptChunk
c2 = (ConceptChunk
c1 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) forall a. Eq a => a -> a -> Bool
== (ConceptChunk
c2 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid)
instance HasUID ConceptChunk where uid :: Lens' ConceptChunk UID
uid = Lens' ConceptChunk IdeaDict
idea forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance NamedIdea ConceptChunk where term :: Lens' ConceptChunk NP
term = Lens' ConceptChunk IdeaDict
idea forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. NamedIdea c => Lens' c NP
term
instance Idea ConceptChunk where getA :: ConceptChunk -> Maybe [Char]
getA = forall c. Idea c => c -> Maybe [Char]
getA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Lens' ConceptChunk IdeaDict
idea
instance Definition ConceptChunk where defn :: Lens' ConceptChunk Sentence
defn = Lens' ConceptChunk Sentence
defn'
instance ConceptDomain ConceptChunk where cdom :: ConceptChunk -> [UID]
cdom = ConceptChunk -> [UID]
cdom'
data ConceptInstance = ConInst { ConceptInstance -> ConceptChunk
_cc :: ConceptChunk , ConceptInstance -> [Char]
ra :: String, ConceptInstance -> ShortName
shnm :: ShortName}
makeLenses ''ConceptInstance
instance Eq ConceptInstance where ConceptInstance
c1 == :: ConceptInstance -> ConceptInstance -> Bool
== ConceptInstance
c2 = (ConceptInstance
c1 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) forall a. Eq a => a -> a -> Bool
== (ConceptInstance
c2 forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid)
instance HasUID ConceptInstance where uid :: Lens' ConceptInstance UID
uid = Lens' ConceptInstance ConceptChunk
cc forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ConceptChunk IdeaDict
idea forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance NamedIdea ConceptInstance where term :: Lens' ConceptInstance NP
term = Lens' ConceptInstance ConceptChunk
cc forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ConceptChunk IdeaDict
idea forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. NamedIdea c => Lens' c NP
term
instance Idea ConceptInstance where getA :: ConceptInstance -> Maybe [Char]
getA = forall c. Idea c => c -> Maybe [Char]
getA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (Lens' ConceptInstance ConceptChunk
cc forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ConceptChunk IdeaDict
idea)
instance Definition ConceptInstance where defn :: Lens' ConceptInstance Sentence
defn = Lens' ConceptInstance ConceptChunk
cc forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens' ConceptChunk Sentence
defn'
instance ConceptDomain ConceptInstance where cdom :: ConceptInstance -> [UID]
cdom = ConceptChunk -> [UID]
cdom' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Lens' ConceptInstance ConceptChunk
cc
instance HasShortName ConceptInstance where shortname :: ConceptInstance -> ShortName
shortname = ConceptInstance -> ShortName
shnm
instance HasRefAddress ConceptInstance where getRefAdd :: ConceptInstance -> LblType
getRefAdd ConceptInstance
l = IRefProg -> [Char] -> LblType
RP (UID -> IRefProg
defer ([UID] -> UID
sDom forall a b. (a -> b) -> a -> b
$ forall c. ConceptDomain c => c -> [UID]
cdom ConceptInstance
l) IRefProg -> IRefProg -> IRefProg
+::+ [Char] -> IRefProg
raw [Char]
":" IRefProg -> IRefProg -> IRefProg
+::+ IRefProg
name) (ConceptInstance -> [Char]
ra ConceptInstance
l)
instance Referable ConceptInstance where
refAdd :: ConceptInstance -> [Char]
refAdd = ConceptInstance -> [Char]
ra
renderRef :: ConceptInstance -> LblType
renderRef = forall b. HasRefAddress b => b -> LblType
getRefAdd