{-# 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 :: Getter Citation UID
uid = (UID -> f UID) -> Citation -> f Citation
Lens' Citation UID
citeID
instance HasShortName Citation where shortname :: Citation -> ShortName
shortname = Citation -> ShortName
sn
instance HasFields Citation where getFields :: Lens' Citation [CiteField]
getFields = ([CiteField] -> f [CiteField]) -> Citation -> f Citation
Lens' Citation [CiteField]
fields
instance Referable Citation where
refAdd :: Citation -> String
refAdd = Citation -> String
forall a. HasUID a => a -> String
showUID
renderRef :: Citation -> LblType
renderRef = String -> LblType
Citation (String -> LblType) -> (Citation -> String) -> Citation -> LblType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Citation -> String
forall s. Referable s => s -> String
refAdd
instance HasRefAddress Citation where getRefAdd :: Citation -> LblType
getRefAdd = String -> LblType
Citation (String -> LblType) -> (Citation -> String) -> Citation -> LblType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Citation -> String
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
' ' Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
n = String -> Citation
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
title String
t CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
journal String
journ CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
chapter Int
chap CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: [Int] -> CiteField
pages [Int]
pgs CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
bookTitle String
bt CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
title String
t CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
bookTitle String
bt CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
title String
t CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
institution String
inst CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
title String
t CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
note String
n CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
publisher String
pub CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
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 CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
title String
t CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: String -> CiteField
school String
sch CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: Int -> CiteField
year Int
yr CiteField -> [CiteField] -> [CiteField]
forall a. a -> [a] -> [a]
: [CiteField]
opt