{-# Language TemplateHaskell #-}
module Language.Drasil.Chunk.Citation (
Citation, BibRef, EntryID,
HasCitation(..),
citeID, citeKind,
cArticle, cBookA, cBookE, cBooklet,
cInBookACP, cInBookECP, cInBookAC, cInBookEC, cInBookAP, cInBookEP,
cInCollection, cInProceedings, cManual, cMThesis, cMisc, cPhDThesis,
cProceedings, cTechReport, cUnpublished
) where
import Language.Drasil.People (People)
import Language.Drasil.ShortName (HasShortName(..), ShortName, shortname')
import Language.Drasil.Data.Citation (HasFields(..), CitationKind(..), CiteField,
author, chapter, pages, editor, bookTitle, title,
year, school, journal, institution, note, publisher)
import Language.Drasil.Sentence (Sentence(S))
import Language.Drasil.Label.Type (LblType(Citation), Referable(..), HasRefAddress(..))
import Language.Drasil.UID (UID, HasUID(..), showUID, mkUid)
import Control.Lens (makeLenses, Lens')
type BibRef = [Citation]
type EntryID = String
data Citation = Cite
{ Citation -> CitationKind
_citeKind :: CitationKind
, Citation -> [CiteField]
_fields :: [CiteField]
, Citation -> UID
_citeID :: UID
, Citation -> ShortName
sn :: ShortName
}
makeLenses ''Citation
class HasCitation c where
getCitations :: Lens' c [Citation]
instance HasUID Citation where uid :: Lens' Citation UID
uid = Lens' Citation UID
citeID
instance HasShortName Citation where shortname :: Citation -> ShortName
shortname = Citation -> ShortName
sn
instance HasFields Citation where getFields :: Lens' Citation [CiteField]
getFields = Lens' Citation [CiteField]
fields
instance Referable Citation where
refAdd :: Citation -> String
refAdd = forall a. HasUID a => a -> String
showUID
renderRef :: Citation -> LblType
renderRef = String -> LblType
Citation forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Referable s => s -> String
refAdd
instance HasRefAddress Citation where getRefAdd :: Citation -> LblType
getRefAdd = String -> LblType
Citation forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasUID a => a -> String
showUID
cite :: CitationKind -> [CiteField] -> String -> Citation
cite :: CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
ck [CiteField]
cfs String
n
| Char
' ' forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
n = forall a. HasCallStack => String -> a
error String
"Citation names may not contain spaces."
| Bool
otherwise = CitationKind -> [CiteField] -> UID -> ShortName -> Citation
Cite CitationKind
ck [CiteField]
cfs (String -> UID
mkUid String
n) (Sentence -> ShortName
shortname' (String -> Sentence
S String
n))
cArticle :: People -> String -> String -> Int -> [CiteField] -> String -> Citation
cArticle :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cArticle People
aut String
t String
journ Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Article
(People -> CiteField
author People
aut forall a. a -> [a] -> [a]
: String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
journal String
journ forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt)
cBookA, cBookE :: People -> String -> String -> Int ->
[CiteField] -> String -> Citation
cBookA :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cBookA People
aut String
t String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Book (People -> CiteField
author People
aut forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cBookE :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cBookE People
ed String
t String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Book (People -> CiteField
editor People
ed forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cBooklet :: String -> [CiteField] -> String -> Citation
cBooklet :: String -> [CiteField] -> String -> Citation
cBooklet String
t [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Booklet (String -> CiteField
title String
t forall a. a -> [a] -> [a]
: [CiteField]
opt)
cInBookACP, cInBookECP :: People -> String -> Int -> [Int] ->
String -> Int -> [CiteField] -> String -> Citation
cInBookACP :: People
-> String
-> Int
-> [Int]
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookACP People
auth String
t Int
chap [Int]
pgs String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInBookECP :: People
-> String
-> Int
-> [Int]
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookECP People
ed String
t Int
chap [Int]
pgs String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
editor People
ed forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInBookAC, cInBookEC :: People -> String -> Int ->
String -> Int -> [CiteField] -> String -> Citation
cInBookAC :: People
-> String
-> Int
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookAC People
auth String
t Int
chap String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInBookEC :: People
-> String
-> Int
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookEC People
ed String
t Int
chap String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
editor People
ed forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInBookAP, cInBookEP :: People -> String -> [Int] ->
String -> Int -> [CiteField] -> String -> Citation
cInBookAP :: People
-> String
-> [Int]
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookAP People
auth String
t [Int]
pgs String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInBookEP :: People
-> String
-> [Int]
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInBookEP People
ed String
t [Int]
pgs String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InBook
(People -> CiteField
editor People
ed forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInCollection :: People -> String -> String -> String -> Int ->
[CiteField] -> String -> Citation
cInCollection :: People
-> String
-> String
-> String
-> Int
-> [CiteField]
-> String
-> Citation
cInCollection People
auth String
t String
bt String
pub Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InCollection
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: String -> CiteField
bookTitle String
bt forall a. a -> [a] -> [a]
: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt)
cInProceedings :: People -> String -> String -> Int ->
[CiteField] -> String -> Citation
cInProceedings :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cInProceedings People
auth String
t String
bt Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
InProceedings
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
bookTitle String
bt forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt)
cManual :: String -> [CiteField] -> String -> Citation
cManual :: String -> [CiteField] -> String -> Citation
cManual String
t [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Manual (String -> CiteField
title String
t forall a. a -> [a] -> [a]
: [CiteField]
opt)
cMThesis :: People -> String -> String -> Int -> [CiteField] -> String -> Citation
cMThesis :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cMThesis People
auth String
t String
sch Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
MThesis (People -> String -> String -> Int -> [CiteField] -> [CiteField]
thesis People
auth String
t String
sch Int
yr [CiteField]
opt)
cMisc :: [CiteField] -> String -> Citation
cMisc :: [CiteField] -> String -> Citation
cMisc = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Misc
cPhDThesis :: People -> String -> String -> Int -> [CiteField] -> String -> Citation
cPhDThesis :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cPhDThesis People
auth String
t String
sch Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
PhDThesis (People -> String -> String -> Int -> [CiteField] -> [CiteField]
thesis People
auth String
t String
sch Int
yr [CiteField]
opt)
cProceedings :: String -> Int -> [CiteField] -> String -> Citation
cProceedings :: String -> Int -> [CiteField] -> String -> Citation
cProceedings String
t Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Proceedings (String -> CiteField
title String
t forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt)
cTechReport :: People -> String -> String -> Int -> [CiteField] -> String -> Citation
cTechReport :: People
-> String -> String -> Int -> [CiteField] -> String -> Citation
cTechReport People
auth String
t String
inst Int
yr [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
TechReport
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
institution String
inst forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt)
cUnpublished :: People -> String -> String -> [CiteField] -> String -> Citation
cUnpublished :: People -> String -> String -> [CiteField] -> String -> Citation
cUnpublished People
auth String
t String
n [CiteField]
opt = CitationKind -> [CiteField] -> String -> Citation
cite CitationKind
Unpublished
(People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
note String
n forall a. a -> [a] -> [a]
: [CiteField]
opt)
stdFields :: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields :: String -> String -> Int -> [CiteField] -> [CiteField]
stdFields String
t String
pub Int
yr [CiteField]
opt = String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
publisher String
pub forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt
thesis :: People -> String -> String -> Int -> [CiteField] -> [CiteField]
thesis :: People -> String -> String -> Int -> [CiteField] -> [CiteField]
thesis People
auth String
t String
sch Int
yr [CiteField]
opt = People -> CiteField
author People
auth forall a. a -> [a] -> [a]
: String -> CiteField
title String
t forall a. a -> [a] -> [a]
: String -> CiteField
school String
sch forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr forall a. a -> [a] -> [a]
: [CiteField]
opt