{-# LANGUAGE StrictData #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Citeproc.Types
  ( CiteprocOptions(..)
  , defaultCiteprocOptions
  , CiteprocOutput(..)
  , addFormatting
  , CiteprocError(..)
  , prettyCiteprocError
  , ItemId(..)
  , CitationItem(..)
  , CitationItemType(..)
  , Citation(..)
  , ElementType(..)
  , Element(..)
  , NumberForm(..)
  , Pluralize(..)
  , DateType(..)
  , Date(..)
  , rawDateEDTF
  , DateParts(..)
  , ShowDateParts(..)
  , DPName(..)
  , DPForm(..)
  , DP(..)
  , VariableForm(..)
  , TextType(..)
  , NameFormat(..)
  , defaultNameFormat
  , NameAsSortOrder(..)
  , NamesFormat(..)
  , NameForm(..)
  , Name(..)
  , extractParticles
  , isByzantineName
  , DelimiterPrecedes(..)
  , Condition(..)
  , Position(..)
  , Match(..)
  , Formatting(..)
  , FontStyle(..)
  , FontVariant(..)
  , FontWeight(..)
  , TextDecoration(..)
  , VerticalAlign(..)
  , DisplayStyle(..)
  , TextCase(..)
  , DemoteNonDroppingParticle(..)
  , StyleOptions(..)
  , SubsequentAuthorSubstitute(..)
  , SubsequentAuthorSubstituteRule(..)
  , SecondFieldAlign(..)
  , PageRangeFormat(..)
  , Style(..)
  , TermMatch(..)
  , TermGender(..)
  , TermNumber(..)
  , TermForm(..)
  , Term(..)
  , emptyTerm
  , SortDirection(..)
  , SortKey(..)
  , SortKeyValue(..)
  , LayoutOptions(..)
  , Collapsing(..)
  , Layout(..)
  , DisambiguationStrategy(..)
  , GivenNameDisambiguationRule(..)
  , Lang(..)
  , parseLang
  , renderLang
  , Locale(..)
  , DisambiguationData(..)
  , NameHints(..)
  , Reference(..)
  , ReferenceMap(..)
  , makeReferenceMap
  , lookupReference
  , Val(..)
  , valToText
  , Variable
  , toVariable
  , fromVariable
  , lookupVariable
  , Output(..)
  , Identifier(..)
  , identifierToURL
  , fixShortDOI
  , Tag(..)
  , outputToText
  , renderOutput
  , grouped
  , formatted
  , readAsInt
  , variableType
  , VariableType(..)
  , Abbreviations
  , lookupAbbreviation
  , Result(..)
  , Inputs(..)
  )
where
import qualified Data.Set as Set
import qualified Data.Map as M
import qualified Data.Text.Read as TR
import qualified Data.Scientific as S
import qualified Data.CaseInsensitive as CI
import Control.Monad (foldM, guard, mzero)
import Control.Applicative ((<|>), optional)
import Data.Char (isLower, isDigit, isLetter, isSpace)
import Data.Text (Text)
import qualified Data.Text as T
import Data.List (elemIndex)
import Data.Maybe
import qualified Data.Vector as V
import Data.Aeson (FromJSON (..), ToJSON (..), ToJSONKey (..),
                   FromJSONKey (..), FromJSONKeyFunction (..),
                   withArray, withObject, object, Value(..),
                   (.:), (.:?), (.!=))
import Data.Aeson.Types (typeMismatch, Parser, toJSONKeyText)
import Data.Coerce
import Data.Generics.Uniplate.Direct
import qualified Data.Attoparsec.Text as P
import Safe (readMay)
import Data.String (IsString)
import Citeproc.Unicode (Lang(..), parseLang, renderLang)

-- import Debug.Trace
--
-- traceShowIdLabeled :: Show a => String -> a -> a
-- traceShowIdLabeled label x =
--   trace (label ++ ": " ++ show x) x

-- import Text.Show.Pretty (ppShow)
--
-- ppTrace :: Show a => a -> a
-- ppTrace x = trace (ppShow x) x

-- | Options affecting the output in ways that go beyond
-- what can be specified in styles.
data CiteprocOptions =
  CiteprocOptions
  { CiteprocOptions -> Bool
linkCitations :: Bool
    -- ^ Create hyperlinks from citations to bibliography entries
  , CiteprocOptions -> Bool
linkBibliography :: Bool
    -- ^ Enables the following options:
    --
    --   * Automatically linkify any DOI, PMCID, PMID, or URL
    --     appearing in a bibliography entry.
    --   * When a bibliography entry has a DOI, PMCID, PMID, or URL available
    --     (in order of priority), but the style does not explicitly render at
    --     least one of them, add a hyperlink to the title instead.
    --   * A bibliography item with a DOI, PMCID, PMID, or URL available
    --     (in order of priority) will be wrapped in a hyperlink when the hyperlink
    --     has not already been applied to one of its parts (e.g. to the title).
  }
  deriving (Int -> CiteprocOptions -> ShowS
[CiteprocOptions] -> ShowS
CiteprocOptions -> String
(Int -> CiteprocOptions -> ShowS)
-> (CiteprocOptions -> String)
-> ([CiteprocOptions] -> ShowS)
-> Show CiteprocOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CiteprocOptions -> ShowS
showsPrec :: Int -> CiteprocOptions -> ShowS
$cshow :: CiteprocOptions -> String
show :: CiteprocOptions -> String
$cshowList :: [CiteprocOptions] -> ShowS
showList :: [CiteprocOptions] -> ShowS
Show, CiteprocOptions -> CiteprocOptions -> Bool
(CiteprocOptions -> CiteprocOptions -> Bool)
-> (CiteprocOptions -> CiteprocOptions -> Bool)
-> Eq CiteprocOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CiteprocOptions -> CiteprocOptions -> Bool
== :: CiteprocOptions -> CiteprocOptions -> Bool
$c/= :: CiteprocOptions -> CiteprocOptions -> Bool
/= :: CiteprocOptions -> CiteprocOptions -> Bool
Eq)

defaultCiteprocOptions :: CiteprocOptions
defaultCiteprocOptions :: CiteprocOptions
defaultCiteprocOptions =
  CiteprocOptions
  { linkCitations :: Bool
linkCitations = Bool
False 
  , linkBibliography :: Bool
linkBibliography = Bool
False
  }

data CiteprocError =
    CiteprocXMLError Text
  | CiteprocParseError Text
  | CiteprocLocaleNotFound Text
  deriving (Int -> CiteprocError -> ShowS
[CiteprocError] -> ShowS
CiteprocError -> String
(Int -> CiteprocError -> ShowS)
-> (CiteprocError -> String)
-> ([CiteprocError] -> ShowS)
-> Show CiteprocError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CiteprocError -> ShowS
showsPrec :: Int -> CiteprocError -> ShowS
$cshow :: CiteprocError -> String
show :: CiteprocError -> String
$cshowList :: [CiteprocError] -> ShowS
showList :: [CiteprocError] -> ShowS
Show, CiteprocError -> CiteprocError -> Bool
(CiteprocError -> CiteprocError -> Bool)
-> (CiteprocError -> CiteprocError -> Bool) -> Eq CiteprocError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CiteprocError -> CiteprocError -> Bool
== :: CiteprocError -> CiteprocError -> Bool
$c/= :: CiteprocError -> CiteprocError -> Bool
/= :: CiteprocError -> CiteprocError -> Bool
Eq)

prettyCiteprocError :: CiteprocError -> Text
prettyCiteprocError :: CiteprocError -> Text
prettyCiteprocError (CiteprocXMLError Text
t) =
  Text
"CiteprocXMLError: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t
prettyCiteprocError (CiteprocParseError Text
t) =
  Text
"CiteprocParseError: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t
prettyCiteprocError (CiteprocLocaleNotFound Text
t) =
  Text
"CiteprocLocaleNotFound: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

-- | CSL styles require certain formatting transformations to
-- be defined.  These are defined in the 'CiteprocOutput' class.
-- The library may be used with any structured format that defines
-- these operations.  See the 'Citeproc.CslJson' module for an instance
-- that corresponds to the markup allowed in CSL JSON. See
-- the 'Citeproc.Pandoc' module for an instance for Pandoc 'Inlines'.
class (Semigroup a, Monoid a, Show a, Eq a, Ord a) => CiteprocOutput a where
  toText                      :: a -> Text
  fromText                    :: Text -> a
  dropTextWhile               :: (Char -> Bool) -> a -> a
  dropTextWhileEnd            :: (Char -> Bool) -> a -> a
  addFontVariant              :: FontVariant -> a -> a
  addFontStyle                :: FontStyle -> a -> a
  addFontWeight               :: FontWeight -> a -> a
  addTextDecoration           :: TextDecoration -> a -> a
  addVerticalAlign            :: VerticalAlign -> a -> a
  addTextCase                 :: Maybe Lang -> TextCase -> a -> a
  addDisplay                  :: DisplayStyle -> a -> a
  addQuotes                   :: a -> a
  movePunctuationInsideQuotes :: a -> a
  inNote                      :: a -> a
  mapText                     :: (Text -> Text) -> a -> a
  addHyperlink                :: Text -> a -> a
  localizeQuotes              :: Locale -> a -> a

addFormatting :: CiteprocOutput a => Formatting -> a -> a
addFormatting :: forall a. CiteprocOutput a => Formatting -> a -> a
addFormatting Formatting
f a
x =
  if Text -> Bool
T.null (a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x)  -- TODO inefficient
     then a
forall a. Monoid a => a
mempty
     else
       (a -> a)
-> (DisplayStyle -> a -> a) -> Maybe DisplayStyle -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id DisplayStyle -> a -> a
forall a. CiteprocOutput a => DisplayStyle -> a -> a
addDisplay (Formatting -> Maybe DisplayStyle
formatDisplay Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (if Bool
affixesInside then a -> a
forall a. a -> a
id else a -> a
forall {a}. CiteprocOutput a => a -> a
addPrefix (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
forall {a}. CiteprocOutput a => a -> a
addSuffix) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (if Formatting -> Bool
formatQuotes Formatting
f then a -> a
forall {a}. CiteprocOutput a => a -> a
addQuotes else a -> a
forall a. a -> a
id) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a)
-> (VerticalAlign -> a -> a) -> Maybe VerticalAlign -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id VerticalAlign -> a -> a
forall a. CiteprocOutput a => VerticalAlign -> a -> a
addVerticalAlign (Formatting -> Maybe VerticalAlign
formatVerticalAlign Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a)
-> (TextDecoration -> a -> a) -> Maybe TextDecoration -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id TextDecoration -> a -> a
forall a. CiteprocOutput a => TextDecoration -> a -> a
addTextDecoration (Formatting -> Maybe TextDecoration
formatTextDecoration Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a) -> (FontWeight -> a -> a) -> Maybe FontWeight -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id FontWeight -> a -> a
forall a. CiteprocOutput a => FontWeight -> a -> a
addFontWeight (Formatting -> Maybe FontWeight
formatFontWeight Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a) -> (FontVariant -> a -> a) -> Maybe FontVariant -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id FontVariant -> a -> a
forall a. CiteprocOutput a => FontVariant -> a -> a
addFontVariant (Formatting -> Maybe FontVariant
formatFontVariant Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a) -> (TextCase -> a -> a) -> Maybe TextCase -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id (Maybe Lang -> TextCase -> a -> a
forall a. CiteprocOutput a => Maybe Lang -> TextCase -> a -> a
addTextCase (Formatting -> Maybe Lang
formatLang Formatting
f)) (Formatting -> Maybe TextCase
formatTextCase Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (a -> a) -> (FontStyle -> a -> a) -> Maybe FontStyle -> a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a -> a
forall a. a -> a
id FontStyle -> a -> a
forall a. CiteprocOutput a => FontStyle -> a -> a
addFontStyle (Formatting -> Maybe FontStyle
formatFontStyle Formatting
f) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (if Bool
affixesInside then a -> a
forall {a}. CiteprocOutput a => a -> a
addPrefix (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
forall {a}. CiteprocOutput a => a -> a
addSuffix else a -> a
forall a. a -> a
id) (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       (if Formatting -> Bool
formatStripPeriods Formatting
f then (Text -> Text) -> a -> a
forall a. CiteprocOutput a => (Text -> Text) -> a -> a
mapText ((Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'.')) else a -> a
forall a. a -> a
id)
       (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a
x
 where
  addPrefix :: a -> a
addPrefix a
z = case Formatting -> Maybe Text
formatPrefix Formatting
f of
                  Just Text
s   -> [a] -> a
forall a. Monoid a => [a] -> a
mconcat ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct [Text -> a
forall a. CiteprocOutput a => Text -> a
fromText Text
s, a
z]
                  Maybe Text
Nothing  -> a
z
  addSuffix :: a -> a
addSuffix a
z = case Formatting -> Maybe Text
formatSuffix Formatting
f of
                  Just Text
s   -> [a] -> a
forall a. Monoid a => [a] -> a
mconcat ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct [a
z, Text -> a
forall a. CiteprocOutput a => Text -> a
fromText Text
s]
                  Maybe Text
Nothing  -> a
z
  affixesInside :: Bool
affixesInside = Formatting -> Bool
formatAffixesInside Formatting
f

-- | The identifier used to identify a work in a bibliographic
-- database.
newtype ItemId = ItemId { ItemId -> Text
unItemId :: Text }
  deriving (Int -> ItemId -> ShowS
[ItemId] -> ShowS
ItemId -> String
(Int -> ItemId -> ShowS)
-> (ItemId -> String) -> ([ItemId] -> ShowS) -> Show ItemId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ItemId -> ShowS
showsPrec :: Int -> ItemId -> ShowS
$cshow :: ItemId -> String
show :: ItemId -> String
$cshowList :: [ItemId] -> ShowS
showList :: [ItemId] -> ShowS
Show, ItemId -> ItemId -> Bool
(ItemId -> ItemId -> Bool)
-> (ItemId -> ItemId -> Bool) -> Eq ItemId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ItemId -> ItemId -> Bool
== :: ItemId -> ItemId -> Bool
$c/= :: ItemId -> ItemId -> Bool
/= :: ItemId -> ItemId -> Bool
Eq, Eq ItemId
Eq ItemId =>
(ItemId -> ItemId -> Ordering)
-> (ItemId -> ItemId -> Bool)
-> (ItemId -> ItemId -> Bool)
-> (ItemId -> ItemId -> Bool)
-> (ItemId -> ItemId -> Bool)
-> (ItemId -> ItemId -> ItemId)
-> (ItemId -> ItemId -> ItemId)
-> Ord ItemId
ItemId -> ItemId -> Bool
ItemId -> ItemId -> Ordering
ItemId -> ItemId -> ItemId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ItemId -> ItemId -> Ordering
compare :: ItemId -> ItemId -> Ordering
$c< :: ItemId -> ItemId -> Bool
< :: ItemId -> ItemId -> Bool
$c<= :: ItemId -> ItemId -> Bool
<= :: ItemId -> ItemId -> Bool
$c> :: ItemId -> ItemId -> Bool
> :: ItemId -> ItemId -> Bool
$c>= :: ItemId -> ItemId -> Bool
>= :: ItemId -> ItemId -> Bool
$cmax :: ItemId -> ItemId -> ItemId
max :: ItemId -> ItemId -> ItemId
$cmin :: ItemId -> ItemId -> ItemId
min :: ItemId -> ItemId -> ItemId
Ord, NonEmpty ItemId -> ItemId
ItemId -> ItemId -> ItemId
(ItemId -> ItemId -> ItemId)
-> (NonEmpty ItemId -> ItemId)
-> (forall b. Integral b => b -> ItemId -> ItemId)
-> Semigroup ItemId
forall b. Integral b => b -> ItemId -> ItemId
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: ItemId -> ItemId -> ItemId
<> :: ItemId -> ItemId -> ItemId
$csconcat :: NonEmpty ItemId -> ItemId
sconcat :: NonEmpty ItemId -> ItemId
$cstimes :: forall b. Integral b => b -> ItemId -> ItemId
stimes :: forall b. Integral b => b -> ItemId -> ItemId
Semigroup, Semigroup ItemId
ItemId
Semigroup ItemId =>
ItemId
-> (ItemId -> ItemId -> ItemId)
-> ([ItemId] -> ItemId)
-> Monoid ItemId
[ItemId] -> ItemId
ItemId -> ItemId -> ItemId
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: ItemId
mempty :: ItemId
$cmappend :: ItemId -> ItemId -> ItemId
mappend :: ItemId -> ItemId -> ItemId
$cmconcat :: [ItemId] -> ItemId
mconcat :: [ItemId] -> ItemId
Monoid, [ItemId] -> Value
[ItemId] -> Encoding
ItemId -> Bool
ItemId -> Value
ItemId -> Encoding
(ItemId -> Value)
-> (ItemId -> Encoding)
-> ([ItemId] -> Value)
-> ([ItemId] -> Encoding)
-> (ItemId -> Bool)
-> ToJSON ItemId
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ItemId -> Value
toJSON :: ItemId -> Value
$ctoEncoding :: ItemId -> Encoding
toEncoding :: ItemId -> Encoding
$ctoJSONList :: [ItemId] -> Value
toJSONList :: [ItemId] -> Value
$ctoEncodingList :: [ItemId] -> Encoding
toEncodingList :: [ItemId] -> Encoding
$comitField :: ItemId -> Bool
omitField :: ItemId -> Bool
ToJSON, Maybe ItemId
Value -> Parser [ItemId]
Value -> Parser ItemId
(Value -> Parser ItemId)
-> (Value -> Parser [ItemId]) -> Maybe ItemId -> FromJSON ItemId
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ItemId
parseJSON :: Value -> Parser ItemId
$cparseJSONList :: Value -> Parser [ItemId]
parseJSONList :: Value -> Parser [ItemId]
$comittedField :: Maybe ItemId
omittedField :: Maybe ItemId
FromJSON)

data CitationItemType =
    AuthorOnly      -- ^ e.g., Smith
  | SuppressAuthor  -- ^ e.g., (2000, p. 30)
  | NormalCite      -- ^ e.g., (Smith 2000, p. 30)
  deriving (Int -> CitationItemType -> ShowS
[CitationItemType] -> ShowS
CitationItemType -> String
(Int -> CitationItemType -> ShowS)
-> (CitationItemType -> String)
-> ([CitationItemType] -> ShowS)
-> Show CitationItemType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CitationItemType -> ShowS
showsPrec :: Int -> CitationItemType -> ShowS
$cshow :: CitationItemType -> String
show :: CitationItemType -> String
$cshowList :: [CitationItemType] -> ShowS
showList :: [CitationItemType] -> ShowS
Show, CitationItemType -> CitationItemType -> Bool
(CitationItemType -> CitationItemType -> Bool)
-> (CitationItemType -> CitationItemType -> Bool)
-> Eq CitationItemType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CitationItemType -> CitationItemType -> Bool
== :: CitationItemType -> CitationItemType -> Bool
$c/= :: CitationItemType -> CitationItemType -> Bool
/= :: CitationItemType -> CitationItemType -> Bool
Eq, Eq CitationItemType
Eq CitationItemType =>
(CitationItemType -> CitationItemType -> Ordering)
-> (CitationItemType -> CitationItemType -> Bool)
-> (CitationItemType -> CitationItemType -> Bool)
-> (CitationItemType -> CitationItemType -> Bool)
-> (CitationItemType -> CitationItemType -> Bool)
-> (CitationItemType -> CitationItemType -> CitationItemType)
-> (CitationItemType -> CitationItemType -> CitationItemType)
-> Ord CitationItemType
CitationItemType -> CitationItemType -> Bool
CitationItemType -> CitationItemType -> Ordering
CitationItemType -> CitationItemType -> CitationItemType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CitationItemType -> CitationItemType -> Ordering
compare :: CitationItemType -> CitationItemType -> Ordering
$c< :: CitationItemType -> CitationItemType -> Bool
< :: CitationItemType -> CitationItemType -> Bool
$c<= :: CitationItemType -> CitationItemType -> Bool
<= :: CitationItemType -> CitationItemType -> Bool
$c> :: CitationItemType -> CitationItemType -> Bool
> :: CitationItemType -> CitationItemType -> Bool
$c>= :: CitationItemType -> CitationItemType -> Bool
>= :: CitationItemType -> CitationItemType -> Bool
$cmax :: CitationItemType -> CitationItemType -> CitationItemType
max :: CitationItemType -> CitationItemType -> CitationItemType
$cmin :: CitationItemType -> CitationItemType -> CitationItemType
min :: CitationItemType -> CitationItemType -> CitationItemType
Ord)

instance FromJSON CitationItemType where
  parseJSON :: Value -> Parser CitationItemType
parseJSON Value
x = Value -> Parser String
forall a. FromJSON a => Value -> Parser a
parseJSON Value
x Parser String
-> (String -> Parser CitationItemType) -> Parser CitationItemType
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
    \case
      String
"author-only"     -> CitationItemType -> Parser CitationItemType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CitationItemType
AuthorOnly
      String
"suppress-author" -> CitationItemType -> Parser CitationItemType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CitationItemType
SuppressAuthor
      String
"normal-cite"     -> CitationItemType -> Parser CitationItemType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CitationItemType
NormalCite
      String
t                 -> String -> Parser CitationItemType
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser CitationItemType)
-> String -> Parser CitationItemType
forall a b. (a -> b) -> a -> b
$ String
"Unknown type " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
t

instance ToJSON CitationItemType where
  toJSON :: CitationItemType -> Value
toJSON CitationItemType
AuthorOnly     = Value
"author-only"
  toJSON CitationItemType
SuppressAuthor = Value
"suppress-author"
  toJSON CitationItemType
NormalCite     = Value
"normal-cite"

-- | The part of a citation corresponding to a single work,
-- possibly including a label, locator, prefix and suffix.
data CitationItem a =
  CitationItem
  { forall a. CitationItem a -> ItemId
citationItemId             :: ItemId
  , forall a. CitationItem a -> Maybe Text
citationItemLabel          :: Maybe Text
  , forall a. CitationItem a -> Maybe Text
citationItemLocator        :: Maybe Text
  , forall a. CitationItem a -> CitationItemType
citationItemType           :: CitationItemType
  , forall a. CitationItem a -> Maybe a
citationItemPrefix         :: Maybe a
  , forall a. CitationItem a -> Maybe a
citationItemSuffix         :: Maybe a
  , forall a. CitationItem a -> Maybe (Reference a)
citationItemData           :: Maybe (Reference a)
  } deriving (Int -> CitationItem a -> ShowS
[CitationItem a] -> ShowS
CitationItem a -> String
(Int -> CitationItem a -> ShowS)
-> (CitationItem a -> String)
-> ([CitationItem a] -> ShowS)
-> Show (CitationItem a)
forall a. Show a => Int -> CitationItem a -> ShowS
forall a. Show a => [CitationItem a] -> ShowS
forall a. Show a => CitationItem a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> CitationItem a -> ShowS
showsPrec :: Int -> CitationItem a -> ShowS
$cshow :: forall a. Show a => CitationItem a -> String
show :: CitationItem a -> String
$cshowList :: forall a. Show a => [CitationItem a] -> ShowS
showList :: [CitationItem a] -> ShowS
Show, CitationItem a -> CitationItem a -> Bool
(CitationItem a -> CitationItem a -> Bool)
-> (CitationItem a -> CitationItem a -> Bool)
-> Eq (CitationItem a)
forall a. Eq a => CitationItem a -> CitationItem a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => CitationItem a -> CitationItem a -> Bool
== :: CitationItem a -> CitationItem a -> Bool
$c/= :: forall a. Eq a => CitationItem a -> CitationItem a -> Bool
/= :: CitationItem a -> CitationItem a -> Bool
Eq, Eq (CitationItem a)
Eq (CitationItem a) =>
(CitationItem a -> CitationItem a -> Ordering)
-> (CitationItem a -> CitationItem a -> Bool)
-> (CitationItem a -> CitationItem a -> Bool)
-> (CitationItem a -> CitationItem a -> Bool)
-> (CitationItem a -> CitationItem a -> Bool)
-> (CitationItem a -> CitationItem a -> CitationItem a)
-> (CitationItem a -> CitationItem a -> CitationItem a)
-> Ord (CitationItem a)
CitationItem a -> CitationItem a -> Bool
CitationItem a -> CitationItem a -> Ordering
CitationItem a -> CitationItem a -> CitationItem a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (CitationItem a)
forall a. Ord a => CitationItem a -> CitationItem a -> Bool
forall a. Ord a => CitationItem a -> CitationItem a -> Ordering
forall a.
Ord a =>
CitationItem a -> CitationItem a -> CitationItem a
$ccompare :: forall a. Ord a => CitationItem a -> CitationItem a -> Ordering
compare :: CitationItem a -> CitationItem a -> Ordering
$c< :: forall a. Ord a => CitationItem a -> CitationItem a -> Bool
< :: CitationItem a -> CitationItem a -> Bool
$c<= :: forall a. Ord a => CitationItem a -> CitationItem a -> Bool
<= :: CitationItem a -> CitationItem a -> Bool
$c> :: forall a. Ord a => CitationItem a -> CitationItem a -> Bool
> :: CitationItem a -> CitationItem a -> Bool
$c>= :: forall a. Ord a => CitationItem a -> CitationItem a -> Bool
>= :: CitationItem a -> CitationItem a -> Bool
$cmax :: forall a.
Ord a =>
CitationItem a -> CitationItem a -> CitationItem a
max :: CitationItem a -> CitationItem a -> CitationItem a
$cmin :: forall a.
Ord a =>
CitationItem a -> CitationItem a -> CitationItem a
min :: CitationItem a -> CitationItem a -> CitationItem a
Ord)

instance (FromJSON a, Eq a) => FromJSON (CitationItem a) where
  parseJSON :: Value -> Parser (CitationItem a)
parseJSON = String
-> (Object -> Parser (CitationItem a))
-> Value
-> Parser (CitationItem a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CitationItem" ((Object -> Parser (CitationItem a))
 -> Value -> Parser (CitationItem a))
-> (Object -> Parser (CitationItem a))
-> Value
-> Parser (CitationItem a)
forall a b. (a -> b) -> a -> b
$ \Object
v -> ItemId
-> Maybe Text
-> Maybe Text
-> CitationItemType
-> Maybe a
-> Maybe a
-> Maybe (Reference a)
-> CitationItem a
forall a.
ItemId
-> Maybe Text
-> Maybe Text
-> CitationItemType
-> Maybe a
-> Maybe a
-> Maybe (Reference a)
-> CitationItem a
CitationItem
    (ItemId
 -> Maybe Text
 -> Maybe Text
 -> CitationItemType
 -> Maybe a
 -> Maybe a
 -> Maybe (Reference a)
 -> CitationItem a)
-> Parser ItemId
-> Parser
     (Maybe Text
      -> Maybe Text
      -> CitationItemType
      -> Maybe a
      -> Maybe a
      -> Maybe (Reference a)
      -> CitationItem a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id" Parser Value -> (Value -> Parser ItemId) -> Parser ItemId
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Text -> ItemId) -> Parser Text -> Parser ItemId
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> ItemId
ItemId (Parser Text -> Parser ItemId)
-> (Value -> Parser Text) -> Value -> Parser ItemId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser Text
asText)
    Parser
  (Maybe Text
   -> Maybe Text
   -> CitationItemType
   -> Maybe a
   -> Maybe a
   -> Maybe (Reference a)
   -> CitationItem a)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> CitationItemType
      -> Maybe a
      -> Maybe a
      -> Maybe (Reference a)
      -> CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"label"
    Parser
  (Maybe Text
   -> CitationItemType
   -> Maybe a
   -> Maybe a
   -> Maybe (Reference a)
   -> CitationItem a)
-> Parser (Maybe Text)
-> Parser
     (CitationItemType
      -> Maybe a -> Maybe a -> Maybe (Reference a) -> CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Text -> Parser (Maybe Text)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"locator" Parser Value -> (Value -> Parser Text) -> Parser Text
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Parser Text
asText)
    Parser
  (CitationItemType
   -> Maybe a -> Maybe a -> Maybe (Reference a) -> CitationItem a)
-> Parser CitationItemType
-> Parser
     (Maybe a -> Maybe a -> Maybe (Reference a) -> CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( (Object
v Object -> Key -> Parser CitationItemType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type")
        Parser CitationItemType
-> Parser CitationItemType -> Parser CitationItemType
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Maybe Bool
suppressAuth <- Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"suppress-author"
                Maybe Bool
authorOnly <- Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"author-only"
                CitationItemType -> Parser CitationItemType
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (CitationItemType -> Parser CitationItemType)
-> CitationItemType -> Parser CitationItemType
forall a b. (a -> b) -> a -> b
$
                  case Maybe Bool
suppressAuth of
                    Just Bool
True -> CitationItemType
SuppressAuthor
                    Maybe Bool
_ -> case Maybe Bool
authorOnly of
                           Just Bool
True -> CitationItemType
AuthorOnly
                           Maybe Bool
_ -> CitationItemType
NormalCite) )
    Parser
  (Maybe a -> Maybe a -> Maybe (Reference a) -> CitationItem a)
-> Parser (Maybe a)
-> Parser (Maybe a -> Maybe (Reference a) -> CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe a)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prefix"
    Parser (Maybe a -> Maybe (Reference a) -> CitationItem a)
-> Parser (Maybe a)
-> Parser (Maybe (Reference a) -> CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe a)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"suffix"
    Parser (Maybe (Reference a) -> CitationItem a)
-> Parser (Maybe (Reference a)) -> Parser (CitationItem a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Reference a))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"itemData"

instance ToJSON a => ToJSON (CitationItem a) where
  toJSON :: CitationItem a -> Value
toJSON CitationItem a
i = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
    [ ( Key
"id", ItemId -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> ItemId
forall a. CitationItem a -> ItemId
citationItemId CitationItem a
i) )
    , (Key
"type", CitationItemType -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItemType -> Value) -> CitationItemType -> Value
forall a b. (a -> b) -> a -> b
$ CitationItem a -> CitationItemType
forall a. CitationItem a -> CitationItemType
citationItemType CitationItem a
i) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
    [ ( Key
"label", Maybe Text -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> Maybe Text
forall a. CitationItem a -> Maybe Text
citationItemLabel CitationItem a
i) )
                  | Maybe Text -> Bool
forall a. Maybe a -> Bool
isJust (CitationItem a -> Maybe Text
forall a. CitationItem a -> Maybe Text
citationItemLabel CitationItem a
i) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
    [ (Key
"locator", Maybe Text -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> Maybe Text
forall a. CitationItem a -> Maybe Text
citationItemLocator CitationItem a
i) )
                  | Maybe Text -> Bool
forall a. Maybe a -> Bool
isJust (CitationItem a -> Maybe Text
forall a. CitationItem a -> Maybe Text
citationItemLocator CitationItem a
i) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
    [ (Key
"prefix", Maybe a -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> Maybe a
forall a. CitationItem a -> Maybe a
citationItemPrefix CitationItem a
i))
                 | Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (CitationItem a -> Maybe a
forall a. CitationItem a -> Maybe a
citationItemPrefix CitationItem a
i) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
    [ (Key
"suffix", Maybe a -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> Maybe a
forall a. CitationItem a -> Maybe a
citationItemSuffix CitationItem a
i))
                 | Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (CitationItem a -> Maybe a
forall a. CitationItem a -> Maybe a
citationItemSuffix CitationItem a
i) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
    [ (Key
"itemData", Maybe (Reference a) -> Value
forall a. ToJSON a => a -> Value
toJSON (CitationItem a -> Maybe (Reference a)
forall a. CitationItem a -> Maybe (Reference a)
citationItemData CitationItem a
i))
                 | Maybe (Reference a) -> Bool
forall a. Maybe a -> Bool
isJust (CitationItem a -> Maybe (Reference a)
forall a. CitationItem a -> Maybe (Reference a)
citationItemData CitationItem a
i) ]


-- | A citation (which may include several items, e.g.
-- in @(Smith 2000; Jones 2010, p. 30)@).
data Citation a =
  Citation { forall a. Citation a -> Maybe Text
citationId         :: Maybe Text
           , forall a. Citation a -> Maybe Int
citationNoteNumber :: Maybe Int
           , forall a. Citation a -> [CitationItem a]
citationItems      :: [CitationItem a] }
  deriving (Int -> Citation a -> ShowS
[Citation a] -> ShowS
Citation a -> String
(Int -> Citation a -> ShowS)
-> (Citation a -> String)
-> ([Citation a] -> ShowS)
-> Show (Citation a)
forall a. Show a => Int -> Citation a -> ShowS
forall a. Show a => [Citation a] -> ShowS
forall a. Show a => Citation a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Citation a -> ShowS
showsPrec :: Int -> Citation a -> ShowS
$cshow :: forall a. Show a => Citation a -> String
show :: Citation a -> String
$cshowList :: forall a. Show a => [Citation a] -> ShowS
showList :: [Citation a] -> ShowS
Show, Citation a -> Citation a -> Bool
(Citation a -> Citation a -> Bool)
-> (Citation a -> Citation a -> Bool) -> Eq (Citation a)
forall a. Eq a => Citation a -> Citation a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Citation a -> Citation a -> Bool
== :: Citation a -> Citation a -> Bool
$c/= :: forall a. Eq a => Citation a -> Citation a -> Bool
/= :: Citation a -> Citation a -> Bool
Eq, Eq (Citation a)
Eq (Citation a) =>
(Citation a -> Citation a -> Ordering)
-> (Citation a -> Citation a -> Bool)
-> (Citation a -> Citation a -> Bool)
-> (Citation a -> Citation a -> Bool)
-> (Citation a -> Citation a -> Bool)
-> (Citation a -> Citation a -> Citation a)
-> (Citation a -> Citation a -> Citation a)
-> Ord (Citation a)
Citation a -> Citation a -> Bool
Citation a -> Citation a -> Ordering
Citation a -> Citation a -> Citation a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Citation a)
forall a. Ord a => Citation a -> Citation a -> Bool
forall a. Ord a => Citation a -> Citation a -> Ordering
forall a. Ord a => Citation a -> Citation a -> Citation a
$ccompare :: forall a. Ord a => Citation a -> Citation a -> Ordering
compare :: Citation a -> Citation a -> Ordering
$c< :: forall a. Ord a => Citation a -> Citation a -> Bool
< :: Citation a -> Citation a -> Bool
$c<= :: forall a. Ord a => Citation a -> Citation a -> Bool
<= :: Citation a -> Citation a -> Bool
$c> :: forall a. Ord a => Citation a -> Citation a -> Bool
> :: Citation a -> Citation a -> Bool
$c>= :: forall a. Ord a => Citation a -> Citation a -> Bool
>= :: Citation a -> Citation a -> Bool
$cmax :: forall a. Ord a => Citation a -> Citation a -> Citation a
max :: Citation a -> Citation a -> Citation a
$cmin :: forall a. Ord a => Citation a -> Citation a -> Citation a
min :: Citation a -> Citation a -> Citation a
Ord)

instance (FromJSON a, Eq a) => FromJSON (Citation a) where
 parseJSON :: Value -> Parser (Citation a)
parseJSON Value
v =
   String
-> (Array -> Parser (Citation a)) -> Value -> Parser (Citation a)
forall a. String -> (Array -> Parser a) -> Value -> Parser a
withArray String
"Citation"
     (\Array
ary ->
       case Array
ary Array -> Int -> Maybe Value
forall a. Vector a -> Int -> Maybe a
V.!? Int
0 of
         Just Value
v' -> (String
-> (Object -> Parser (Citation a)) -> Value -> Parser (Citation a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Citation" ((Object -> Parser (Citation a)) -> Value -> Parser (Citation a))
-> (Object -> Parser (Citation a)) -> Value -> Parser (Citation a)
forall a b. (a -> b) -> a -> b
$ \Object
o
                      -> Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
forall a. Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
Citation (Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a)
-> Parser (Maybe Text)
-> Parser (Maybe Int -> [CitationItem a] -> Citation a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"citationID"
                                  Parser (Maybe Int -> [CitationItem a] -> Citation a)
-> Parser (Maybe Int) -> Parser ([CitationItem a] -> Citation a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"properties"
                                             Parser Object
-> (Object -> Parser (Maybe Int)) -> Parser (Maybe Int)
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"noteIndex"))
                                      Parser (Maybe Int) -> Parser (Maybe Int) -> Parser (Maybe Int)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> Parser (Maybe Int)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Int
forall a. Maybe a
Nothing)
                                  Parser ([CitationItem a] -> Citation a)
-> Parser [CitationItem a] -> Parser (Citation a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [CitationItem a]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"citationItems") Value
v'
                  Parser (Citation a) -> Parser (Citation a) -> Parser (Citation a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
forall a. Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
Citation Maybe Text
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing ([CitationItem a] -> Citation a)
-> Parser [CitationItem a] -> Parser (Citation a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser [CitationItem a]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v'
         Maybe Value
Nothing -> String -> Parser (Citation a)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Empty array") Value
v
   Parser (Citation a) -> Parser (Citation a) -> Parser (Citation a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
   String
-> (Object -> Parser (Citation a)) -> Value -> Parser (Citation a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Citation"
     (\Object
o -> Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
forall a. Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
Citation (Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a)
-> Parser (Maybe Text)
-> Parser (Maybe Int -> [CitationItem a] -> Citation a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"citationID"
                     Parser (Maybe Int -> [CitationItem a] -> Citation a)
-> Parser (Maybe Int) -> Parser ([CitationItem a] -> Citation a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"citationNoteNumber"
                     Parser ([CitationItem a] -> Citation a)
-> Parser [CitationItem a] -> Parser (Citation a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [CitationItem a]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"citationItems") Value
v
   Parser (Citation a) -> Parser (Citation a) -> Parser (Citation a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
   (Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
forall a. Maybe Text -> Maybe Int -> [CitationItem a] -> Citation a
Citation Maybe Text
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing ([CitationItem a] -> Citation a)
-> Parser [CitationItem a] -> Parser (Citation a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser [CitationItem a]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v)

instance ToJSON a => ToJSON (Citation a) where
 toJSON :: Citation a -> Value
toJSON Citation a
c =
   [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
     [ (Key
"citationID", Maybe Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe Text -> Value) -> Maybe Text -> Value
forall a b. (a -> b) -> a -> b
$ Citation a -> Maybe Text
forall a. Citation a -> Maybe Text
citationId Citation a
c) | Maybe Text -> Bool
forall a. Maybe a -> Bool
isJust (Citation a -> Maybe Text
forall a. Citation a -> Maybe Text
citationId Citation a
c) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
     [ (Key
"citationItems" , [CitationItem a] -> Value
forall a. ToJSON a => a -> Value
toJSON ([CitationItem a] -> Value) -> [CitationItem a] -> Value
forall a b. (a -> b) -> a -> b
$ Citation a -> [CitationItem a]
forall a. Citation a -> [CitationItem a]
citationItems Citation a
c) ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++
     case Citation a -> Maybe Int
forall a. Citation a -> Maybe Int
citationNoteNumber Citation a
c of
           Maybe Int
Nothing -> []
           Just Int
n  -> [ (Key
"citationNoteNumber", Int -> Value
forall a. ToJSON a => a -> Value
toJSON Int
n) ]

data Match =
    MatchAll
  | MatchAny
  | MatchNone
  deriving (Int -> Match -> ShowS
[Match] -> ShowS
Match -> String
(Int -> Match -> ShowS)
-> (Match -> String) -> ([Match] -> ShowS) -> Show Match
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Match -> ShowS
showsPrec :: Int -> Match -> ShowS
$cshow :: Match -> String
show :: Match -> String
$cshowList :: [Match] -> ShowS
showList :: [Match] -> ShowS
Show, Match -> Match -> Bool
(Match -> Match -> Bool) -> (Match -> Match -> Bool) -> Eq Match
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Match -> Match -> Bool
== :: Match -> Match -> Bool
$c/= :: Match -> Match -> Bool
/= :: Match -> Match -> Bool
Eq)

data Condition =
    HasVariable Variable
  | HasType Text
  | IsUncertainDate Variable
  | IsNumeric Variable
  | HasLocatorType Variable
  | HasPosition Position
  | WouldDisambiguate
  deriving (Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Condition -> ShowS
showsPrec :: Int -> Condition -> ShowS
$cshow :: Condition -> String
show :: Condition -> String
$cshowList :: [Condition] -> ShowS
showList :: [Condition] -> ShowS
Show, Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
/= :: Condition -> Condition -> Bool
Eq)

data Position =
    FirstPosition
  | IbidWithLocator
  | Ibid
  | NearNote
  | Subsequent
  deriving (Int -> Position -> ShowS
[Position] -> ShowS
Position -> String
(Int -> Position -> ShowS)
-> (Position -> String) -> ([Position] -> ShowS) -> Show Position
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Position -> ShowS
showsPrec :: Int -> Position -> ShowS
$cshow :: Position -> String
show :: Position -> String
$cshowList :: [Position] -> ShowS
showList :: [Position] -> ShowS
Show, Position -> Position -> Bool
(Position -> Position -> Bool)
-> (Position -> Position -> Bool) -> Eq Position
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Position -> Position -> Bool
== :: Position -> Position -> Bool
$c/= :: Position -> Position -> Bool
/= :: Position -> Position -> Bool
Eq, Eq Position
Eq Position =>
(Position -> Position -> Ordering)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Position)
-> (Position -> Position -> Position)
-> Ord Position
Position -> Position -> Bool
Position -> Position -> Ordering
Position -> Position -> Position
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Position -> Position -> Ordering
compare :: Position -> Position -> Ordering
$c< :: Position -> Position -> Bool
< :: Position -> Position -> Bool
$c<= :: Position -> Position -> Bool
<= :: Position -> Position -> Bool
$c> :: Position -> Position -> Bool
> :: Position -> Position -> Bool
$c>= :: Position -> Position -> Bool
>= :: Position -> Position -> Bool
$cmax :: Position -> Position -> Position
max :: Position -> Position -> Position
$cmin :: Position -> Position -> Position
min :: Position -> Position -> Position
Ord)

data DateType =
    LocalizedNumeric
  | LocalizedText
  | NonLocalized
  deriving (Int -> DateType -> ShowS
[DateType] -> ShowS
DateType -> String
(Int -> DateType -> ShowS)
-> (DateType -> String) -> ([DateType] -> ShowS) -> Show DateType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DateType -> ShowS
showsPrec :: Int -> DateType -> ShowS
$cshow :: DateType -> String
show :: DateType -> String
$cshowList :: [DateType] -> ShowS
showList :: [DateType] -> ShowS
Show, DateType -> DateType -> Bool
(DateType -> DateType -> Bool)
-> (DateType -> DateType -> Bool) -> Eq DateType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DateType -> DateType -> Bool
== :: DateType -> DateType -> Bool
$c/= :: DateType -> DateType -> Bool
/= :: DateType -> DateType -> Bool
Eq, Eq DateType
Eq DateType =>
(DateType -> DateType -> Ordering)
-> (DateType -> DateType -> Bool)
-> (DateType -> DateType -> Bool)
-> (DateType -> DateType -> Bool)
-> (DateType -> DateType -> Bool)
-> (DateType -> DateType -> DateType)
-> (DateType -> DateType -> DateType)
-> Ord DateType
DateType -> DateType -> Bool
DateType -> DateType -> Ordering
DateType -> DateType -> DateType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DateType -> DateType -> Ordering
compare :: DateType -> DateType -> Ordering
$c< :: DateType -> DateType -> Bool
< :: DateType -> DateType -> Bool
$c<= :: DateType -> DateType -> Bool
<= :: DateType -> DateType -> Bool
$c> :: DateType -> DateType -> Bool
> :: DateType -> DateType -> Bool
$c>= :: DateType -> DateType -> Bool
>= :: DateType -> DateType -> Bool
$cmax :: DateType -> DateType -> DateType
max :: DateType -> DateType -> DateType
$cmin :: DateType -> DateType -> DateType
min :: DateType -> DateType -> DateType
Ord)

data ShowDateParts =
    YearMonthDay
  | YearMonth
  | Year
  deriving (Int -> ShowDateParts -> ShowS
[ShowDateParts] -> ShowS
ShowDateParts -> String
(Int -> ShowDateParts -> ShowS)
-> (ShowDateParts -> String)
-> ([ShowDateParts] -> ShowS)
-> Show ShowDateParts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShowDateParts -> ShowS
showsPrec :: Int -> ShowDateParts -> ShowS
$cshow :: ShowDateParts -> String
show :: ShowDateParts -> String
$cshowList :: [ShowDateParts] -> ShowS
showList :: [ShowDateParts] -> ShowS
Show, ShowDateParts -> ShowDateParts -> Bool
(ShowDateParts -> ShowDateParts -> Bool)
-> (ShowDateParts -> ShowDateParts -> Bool) -> Eq ShowDateParts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShowDateParts -> ShowDateParts -> Bool
== :: ShowDateParts -> ShowDateParts -> Bool
$c/= :: ShowDateParts -> ShowDateParts -> Bool
/= :: ShowDateParts -> ShowDateParts -> Bool
Eq)

data DPName =
    DPYear
  | DPMonth
  | DPDay
  deriving (Int -> DPName -> ShowS
[DPName] -> ShowS
DPName -> String
(Int -> DPName -> ShowS)
-> (DPName -> String) -> ([DPName] -> ShowS) -> Show DPName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DPName -> ShowS
showsPrec :: Int -> DPName -> ShowS
$cshow :: DPName -> String
show :: DPName -> String
$cshowList :: [DPName] -> ShowS
showList :: [DPName] -> ShowS
Show, DPName -> DPName -> Bool
(DPName -> DPName -> Bool)
-> (DPName -> DPName -> Bool) -> Eq DPName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DPName -> DPName -> Bool
== :: DPName -> DPName -> Bool
$c/= :: DPName -> DPName -> Bool
/= :: DPName -> DPName -> Bool
Eq, Eq DPName
Eq DPName =>
(DPName -> DPName -> Ordering)
-> (DPName -> DPName -> Bool)
-> (DPName -> DPName -> Bool)
-> (DPName -> DPName -> Bool)
-> (DPName -> DPName -> Bool)
-> (DPName -> DPName -> DPName)
-> (DPName -> DPName -> DPName)
-> Ord DPName
DPName -> DPName -> Bool
DPName -> DPName -> Ordering
DPName -> DPName -> DPName
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DPName -> DPName -> Ordering
compare :: DPName -> DPName -> Ordering
$c< :: DPName -> DPName -> Bool
< :: DPName -> DPName -> Bool
$c<= :: DPName -> DPName -> Bool
<= :: DPName -> DPName -> Bool
$c> :: DPName -> DPName -> Bool
> :: DPName -> DPName -> Bool
$c>= :: DPName -> DPName -> Bool
>= :: DPName -> DPName -> Bool
$cmax :: DPName -> DPName -> DPName
max :: DPName -> DPName -> DPName
$cmin :: DPName -> DPName -> DPName
min :: DPName -> DPName -> DPName
Ord)

data DPForm =
    DPNumeric
  | DPNumericLeadingZeros
  | DPOrdinal
  | DPLong
  | DPShort
  deriving (Int -> DPForm -> ShowS
[DPForm] -> ShowS
DPForm -> String
(Int -> DPForm -> ShowS)
-> (DPForm -> String) -> ([DPForm] -> ShowS) -> Show DPForm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DPForm -> ShowS
showsPrec :: Int -> DPForm -> ShowS
$cshow :: DPForm -> String
show :: DPForm -> String
$cshowList :: [DPForm] -> ShowS
showList :: [DPForm] -> ShowS
Show, DPForm -> DPForm -> Bool
(DPForm -> DPForm -> Bool)
-> (DPForm -> DPForm -> Bool) -> Eq DPForm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DPForm -> DPForm -> Bool
== :: DPForm -> DPForm -> Bool
$c/= :: DPForm -> DPForm -> Bool
/= :: DPForm -> DPForm -> Bool
Eq)

data DP =
  DP
  { DP -> DPName
dpName           :: DPName
  , DP -> DPForm
dpForm           :: DPForm
  , DP -> Text
dpRangeDelimiter :: Text
  , DP -> Formatting
dpFormatting     :: Formatting
  }
  deriving (Int -> DP -> ShowS
[DP] -> ShowS
DP -> String
(Int -> DP -> ShowS)
-> (DP -> String) -> ([DP] -> ShowS) -> Show DP
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DP -> ShowS
showsPrec :: Int -> DP -> ShowS
$cshow :: DP -> String
show :: DP -> String
$cshowList :: [DP] -> ShowS
showList :: [DP] -> ShowS
Show, DP -> DP -> Bool
(DP -> DP -> Bool) -> (DP -> DP -> Bool) -> Eq DP
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DP -> DP -> Bool
== :: DP -> DP -> Bool
$c/= :: DP -> DP -> Bool
/= :: DP -> DP -> Bool
Eq)

data VariableForm =
    ShortForm
  | LongForm
  deriving (Int -> VariableForm -> ShowS
[VariableForm] -> ShowS
VariableForm -> String
(Int -> VariableForm -> ShowS)
-> (VariableForm -> String)
-> ([VariableForm] -> ShowS)
-> Show VariableForm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VariableForm -> ShowS
showsPrec :: Int -> VariableForm -> ShowS
$cshow :: VariableForm -> String
show :: VariableForm -> String
$cshowList :: [VariableForm] -> ShowS
showList :: [VariableForm] -> ShowS
Show, VariableForm -> VariableForm -> Bool
(VariableForm -> VariableForm -> Bool)
-> (VariableForm -> VariableForm -> Bool) -> Eq VariableForm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VariableForm -> VariableForm -> Bool
== :: VariableForm -> VariableForm -> Bool
$c/= :: VariableForm -> VariableForm -> Bool
/= :: VariableForm -> VariableForm -> Bool
Eq)

data TextType =
    TextVariable VariableForm Variable
  | TextMacro Text
  | TextTerm Term
  | TextValue Text
  deriving (Int -> TextType -> ShowS
[TextType] -> ShowS
TextType -> String
(Int -> TextType -> ShowS)
-> (TextType -> String) -> ([TextType] -> ShowS) -> Show TextType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextType -> ShowS
showsPrec :: Int -> TextType -> ShowS
$cshow :: TextType -> String
show :: TextType -> String
$cshowList :: [TextType] -> ShowS
showList :: [TextType] -> ShowS
Show, TextType -> TextType -> Bool
(TextType -> TextType -> Bool)
-> (TextType -> TextType -> Bool) -> Eq TextType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextType -> TextType -> Bool
== :: TextType -> TextType -> Bool
$c/= :: TextType -> TextType -> Bool
/= :: TextType -> TextType -> Bool
Eq)

data NumberForm =
    NumberNumeric
  | NumberOrdinal
  | NumberLongOrdinal
  | NumberRoman
  deriving (Int -> NumberForm -> ShowS
[NumberForm] -> ShowS
NumberForm -> String
(Int -> NumberForm -> ShowS)
-> (NumberForm -> String)
-> ([NumberForm] -> ShowS)
-> Show NumberForm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NumberForm -> ShowS
showsPrec :: Int -> NumberForm -> ShowS
$cshow :: NumberForm -> String
show :: NumberForm -> String
$cshowList :: [NumberForm] -> ShowS
showList :: [NumberForm] -> ShowS
Show, NumberForm -> NumberForm -> Bool
(NumberForm -> NumberForm -> Bool)
-> (NumberForm -> NumberForm -> Bool) -> Eq NumberForm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NumberForm -> NumberForm -> Bool
== :: NumberForm -> NumberForm -> Bool
$c/= :: NumberForm -> NumberForm -> Bool
/= :: NumberForm -> NumberForm -> Bool
Eq)

data Pluralize =
    ContextualPluralize
  | AlwaysPluralize
  | NeverPluralize
  deriving (Int -> Pluralize -> ShowS
[Pluralize] -> ShowS
Pluralize -> String
(Int -> Pluralize -> ShowS)
-> (Pluralize -> String)
-> ([Pluralize] -> ShowS)
-> Show Pluralize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Pluralize -> ShowS
showsPrec :: Int -> Pluralize -> ShowS
$cshow :: Pluralize -> String
show :: Pluralize -> String
$cshowList :: [Pluralize] -> ShowS
showList :: [Pluralize] -> ShowS
Show, Pluralize -> Pluralize -> Bool
(Pluralize -> Pluralize -> Bool)
-> (Pluralize -> Pluralize -> Bool) -> Eq Pluralize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Pluralize -> Pluralize -> Bool
== :: Pluralize -> Pluralize -> Bool
$c/= :: Pluralize -> Pluralize -> Bool
/= :: Pluralize -> Pluralize -> Bool
Eq)

data NamesFormat =
    NamesFormat
    { NamesFormat -> Maybe (TermForm, Pluralize, Formatting)
namesLabel           :: Maybe (TermForm, Pluralize, Formatting)
    , NamesFormat -> Maybe (Text, Formatting)
namesEtAl            :: Maybe (Text, Formatting)
    , NamesFormat -> Maybe (NameFormat, Formatting)
namesName            :: Maybe (NameFormat, Formatting)
    , NamesFormat -> Bool
namesLabelBeforeName :: Bool
    } deriving (Int -> NamesFormat -> ShowS
[NamesFormat] -> ShowS
NamesFormat -> String
(Int -> NamesFormat -> ShowS)
-> (NamesFormat -> String)
-> ([NamesFormat] -> ShowS)
-> Show NamesFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NamesFormat -> ShowS
showsPrec :: Int -> NamesFormat -> ShowS
$cshow :: NamesFormat -> String
show :: NamesFormat -> String
$cshowList :: [NamesFormat] -> ShowS
showList :: [NamesFormat] -> ShowS
Show, NamesFormat -> NamesFormat -> Bool
(NamesFormat -> NamesFormat -> Bool)
-> (NamesFormat -> NamesFormat -> Bool) -> Eq NamesFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NamesFormat -> NamesFormat -> Bool
== :: NamesFormat -> NamesFormat -> Bool
$c/= :: NamesFormat -> NamesFormat -> Bool
/= :: NamesFormat -> NamesFormat -> Bool
Eq)

data DelimiterPrecedes =
    PrecedesContextual
  | PrecedesAfterInvertedName
  | PrecedesAlways
  | PrecedesNever
  deriving (Int -> DelimiterPrecedes -> ShowS
[DelimiterPrecedes] -> ShowS
DelimiterPrecedes -> String
(Int -> DelimiterPrecedes -> ShowS)
-> (DelimiterPrecedes -> String)
-> ([DelimiterPrecedes] -> ShowS)
-> Show DelimiterPrecedes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DelimiterPrecedes -> ShowS
showsPrec :: Int -> DelimiterPrecedes -> ShowS
$cshow :: DelimiterPrecedes -> String
show :: DelimiterPrecedes -> String
$cshowList :: [DelimiterPrecedes] -> ShowS
showList :: [DelimiterPrecedes] -> ShowS
Show, DelimiterPrecedes -> DelimiterPrecedes -> Bool
(DelimiterPrecedes -> DelimiterPrecedes -> Bool)
-> (DelimiterPrecedes -> DelimiterPrecedes -> Bool)
-> Eq DelimiterPrecedes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DelimiterPrecedes -> DelimiterPrecedes -> Bool
== :: DelimiterPrecedes -> DelimiterPrecedes -> Bool
$c/= :: DelimiterPrecedes -> DelimiterPrecedes -> Bool
/= :: DelimiterPrecedes -> DelimiterPrecedes -> Bool
Eq)

data NameForm =
    LongName
  | ShortName
  | CountName
  deriving (Int -> NameForm -> ShowS
[NameForm] -> ShowS
NameForm -> String
(Int -> NameForm -> ShowS)
-> (NameForm -> String) -> ([NameForm] -> ShowS) -> Show NameForm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameForm -> ShowS
showsPrec :: Int -> NameForm -> ShowS
$cshow :: NameForm -> String
show :: NameForm -> String
$cshowList :: [NameForm] -> ShowS
showList :: [NameForm] -> ShowS
Show, NameForm -> NameForm -> Bool
(NameForm -> NameForm -> Bool)
-> (NameForm -> NameForm -> Bool) -> Eq NameForm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameForm -> NameForm -> Bool
== :: NameForm -> NameForm -> Bool
$c/= :: NameForm -> NameForm -> Bool
/= :: NameForm -> NameForm -> Bool
Eq)

data NameFormat =
  NameFormat
  { NameFormat -> Maybe Formatting
nameGivenFormatting        :: Maybe Formatting
  , NameFormat -> Maybe Formatting
nameFamilyFormatting       :: Maybe Formatting
  , NameFormat -> Maybe TermForm
nameAndStyle               :: Maybe TermForm
  , NameFormat -> Text
nameDelimiter              :: Text
  , NameFormat -> DelimiterPrecedes
nameDelimiterPrecedesEtAl  :: DelimiterPrecedes
  , NameFormat -> DelimiterPrecedes
nameDelimiterPrecedesLast  :: DelimiterPrecedes
  , NameFormat -> Maybe Int
nameEtAlMin                :: Maybe Int
  , NameFormat -> Maybe Int
nameEtAlUseFirst           :: Maybe Int
  , NameFormat -> Maybe Int
nameEtAlSubsequentUseFirst :: Maybe Int
  , NameFormat -> Maybe Int
nameEtAlSubsequentMin      :: Maybe Int
  , NameFormat -> Bool
nameEtAlUseLast            :: Bool
  , NameFormat -> NameForm
nameForm                   :: NameForm
  , NameFormat -> Bool
nameInitialize             :: Bool
  , NameFormat -> Maybe Text
nameInitializeWith         :: Maybe Text
  , NameFormat -> Maybe NameAsSortOrder
nameAsSortOrder            :: Maybe NameAsSortOrder
  , NameFormat -> Text
nameSortSeparator          :: Text
  } deriving (Int -> NameFormat -> ShowS
[NameFormat] -> ShowS
NameFormat -> String
(Int -> NameFormat -> ShowS)
-> (NameFormat -> String)
-> ([NameFormat] -> ShowS)
-> Show NameFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameFormat -> ShowS
showsPrec :: Int -> NameFormat -> ShowS
$cshow :: NameFormat -> String
show :: NameFormat -> String
$cshowList :: [NameFormat] -> ShowS
showList :: [NameFormat] -> ShowS
Show, NameFormat -> NameFormat -> Bool
(NameFormat -> NameFormat -> Bool)
-> (NameFormat -> NameFormat -> Bool) -> Eq NameFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameFormat -> NameFormat -> Bool
== :: NameFormat -> NameFormat -> Bool
$c/= :: NameFormat -> NameFormat -> Bool
/= :: NameFormat -> NameFormat -> Bool
Eq)

defaultNameFormat :: NameFormat
defaultNameFormat :: NameFormat
defaultNameFormat =
  NameFormat
  { nameGivenFormatting :: Maybe Formatting
nameGivenFormatting          = Maybe Formatting
forall a. Maybe a
Nothing
  , nameFamilyFormatting :: Maybe Formatting
nameFamilyFormatting         =  Maybe Formatting
forall a. Maybe a
Nothing
  , nameAndStyle :: Maybe TermForm
nameAndStyle                 = Maybe TermForm
forall a. Maybe a
Nothing
  , nameDelimiter :: Text
nameDelimiter                = Text
", "
  , nameDelimiterPrecedesEtAl :: DelimiterPrecedes
nameDelimiterPrecedesEtAl    = DelimiterPrecedes
PrecedesContextual
  , nameDelimiterPrecedesLast :: DelimiterPrecedes
nameDelimiterPrecedesLast    = DelimiterPrecedes
PrecedesContextual
  , nameEtAlMin :: Maybe Int
nameEtAlMin                  = Maybe Int
forall a. Maybe a
Nothing
  , nameEtAlUseFirst :: Maybe Int
nameEtAlUseFirst             = Maybe Int
forall a. Maybe a
Nothing
  , nameEtAlSubsequentUseFirst :: Maybe Int
nameEtAlSubsequentUseFirst   = Maybe Int
forall a. Maybe a
Nothing
  , nameEtAlSubsequentMin :: Maybe Int
nameEtAlSubsequentMin        = Maybe Int
forall a. Maybe a
Nothing
  , nameEtAlUseLast :: Bool
nameEtAlUseLast              = Bool
False
  , nameForm :: NameForm
nameForm                     = NameForm
LongName
  , nameInitialize :: Bool
nameInitialize               = Bool
True
  , nameInitializeWith :: Maybe Text
nameInitializeWith           = Maybe Text
forall a. Maybe a
Nothing
  , nameAsSortOrder :: Maybe NameAsSortOrder
nameAsSortOrder              = Maybe NameAsSortOrder
forall a. Maybe a
Nothing
  , nameSortSeparator :: Text
nameSortSeparator            = Text
", "
  }

data NameAsSortOrder =
     NameAsSortOrderFirst
   | NameAsSortOrderAll
   deriving (Int -> NameAsSortOrder -> ShowS
[NameAsSortOrder] -> ShowS
NameAsSortOrder -> String
(Int -> NameAsSortOrder -> ShowS)
-> (NameAsSortOrder -> String)
-> ([NameAsSortOrder] -> ShowS)
-> Show NameAsSortOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameAsSortOrder -> ShowS
showsPrec :: Int -> NameAsSortOrder -> ShowS
$cshow :: NameAsSortOrder -> String
show :: NameAsSortOrder -> String
$cshowList :: [NameAsSortOrder] -> ShowS
showList :: [NameAsSortOrder] -> ShowS
Show, NameAsSortOrder -> NameAsSortOrder -> Bool
(NameAsSortOrder -> NameAsSortOrder -> Bool)
-> (NameAsSortOrder -> NameAsSortOrder -> Bool)
-> Eq NameAsSortOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameAsSortOrder -> NameAsSortOrder -> Bool
== :: NameAsSortOrder -> NameAsSortOrder -> Bool
$c/= :: NameAsSortOrder -> NameAsSortOrder -> Bool
/= :: NameAsSortOrder -> NameAsSortOrder -> Bool
Eq)

data ElementType a =
    EText TextType
  | EDate Variable DateType (Maybe ShowDateParts) [DP]
  | ENumber Variable NumberForm
  | ENames [Variable] NamesFormat [Element a] -- last part is substitutes if any
  | ELabel Variable TermForm Pluralize
  | EGroup Bool [Element a]  -- Bool is true if it's an expanded macro
  | EChoose [(Match, [Condition], [Element a])]
    -- 'else' can be represented by a final trivial match condition
  deriving (Int -> ElementType a -> ShowS
[ElementType a] -> ShowS
ElementType a -> String
(Int -> ElementType a -> ShowS)
-> (ElementType a -> String)
-> ([ElementType a] -> ShowS)
-> Show (ElementType a)
forall a. Int -> ElementType a -> ShowS
forall a. [ElementType a] -> ShowS
forall a. ElementType a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> ElementType a -> ShowS
showsPrec :: Int -> ElementType a -> ShowS
$cshow :: forall a. ElementType a -> String
show :: ElementType a -> String
$cshowList :: forall a. [ElementType a] -> ShowS
showList :: [ElementType a] -> ShowS
Show, ElementType a -> ElementType a -> Bool
(ElementType a -> ElementType a -> Bool)
-> (ElementType a -> ElementType a -> Bool) -> Eq (ElementType a)
forall a. ElementType a -> ElementType a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. ElementType a -> ElementType a -> Bool
== :: ElementType a -> ElementType a -> Bool
$c/= :: forall a. ElementType a -> ElementType a -> Bool
/= :: ElementType a -> ElementType a -> Bool
Eq)

data Formatting =
  Formatting
  { Formatting -> Maybe Lang
formatLang           :: Maybe Lang
  , Formatting -> Maybe FontStyle
formatFontStyle      :: Maybe FontStyle
  , Formatting -> Maybe FontVariant
formatFontVariant    :: Maybe FontVariant
  , Formatting -> Maybe FontWeight
formatFontWeight     :: Maybe FontWeight
  , Formatting -> Maybe TextDecoration
formatTextDecoration :: Maybe TextDecoration
  , Formatting -> Maybe VerticalAlign
formatVerticalAlign  :: Maybe VerticalAlign
  , Formatting -> Maybe Text
formatPrefix         :: Maybe Text
  , Formatting -> Maybe Text
formatSuffix         :: Maybe Text
  , Formatting -> Maybe DisplayStyle
formatDisplay        :: Maybe DisplayStyle
  , Formatting -> Maybe TextCase
formatTextCase       :: Maybe TextCase
  , Formatting -> Maybe Text
formatDelimiter      :: Maybe Text
  , Formatting -> Bool
formatStripPeriods   :: Bool
  , Formatting -> Bool
formatQuotes         :: Bool
  , Formatting -> Bool
formatAffixesInside  :: Bool  -- put affixes inside other formatting
  } deriving (Int -> Formatting -> ShowS
[Formatting] -> ShowS
Formatting -> String
(Int -> Formatting -> ShowS)
-> (Formatting -> String)
-> ([Formatting] -> ShowS)
-> Show Formatting
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Formatting -> ShowS
showsPrec :: Int -> Formatting -> ShowS
$cshow :: Formatting -> String
show :: Formatting -> String
$cshowList :: [Formatting] -> ShowS
showList :: [Formatting] -> ShowS
Show, Formatting -> Formatting -> Bool
(Formatting -> Formatting -> Bool)
-> (Formatting -> Formatting -> Bool) -> Eq Formatting
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Formatting -> Formatting -> Bool
== :: Formatting -> Formatting -> Bool
$c/= :: Formatting -> Formatting -> Bool
/= :: Formatting -> Formatting -> Bool
Eq)

defaultFormatting :: Formatting
defaultFormatting :: Formatting
defaultFormatting = Maybe Lang
-> Maybe FontStyle
-> Maybe FontVariant
-> Maybe FontWeight
-> Maybe TextDecoration
-> Maybe VerticalAlign
-> Maybe Text
-> Maybe Text
-> Maybe DisplayStyle
-> Maybe TextCase
-> Maybe Text
-> Bool
-> Bool
-> Bool
-> Formatting
Formatting Maybe Lang
forall a. Maybe a
Nothing Maybe FontStyle
forall a. Maybe a
Nothing Maybe FontVariant
forall a. Maybe a
Nothing Maybe FontWeight
forall a. Maybe a
Nothing Maybe TextDecoration
forall a. Maybe a
Nothing
  Maybe VerticalAlign
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe DisplayStyle
forall a. Maybe a
Nothing Maybe TextCase
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Bool
False Bool
False Bool
False

combineFormatting :: Formatting -> Formatting -> Formatting
combineFormatting :: Formatting -> Formatting -> Formatting
combineFormatting
  (Formatting Maybe Lang
la1 Maybe FontStyle
a1 Maybe FontVariant
b1 Maybe FontWeight
c1 Maybe TextDecoration
d1 Maybe VerticalAlign
e1 Maybe Text
f1 Maybe Text
g1 Maybe DisplayStyle
h1 Maybe TextCase
i1 Maybe Text
j1 Bool
k1 Bool
l1 Bool
m1)
  (Formatting Maybe Lang
la2 Maybe FontStyle
a2 Maybe FontVariant
b2 Maybe FontWeight
c2 Maybe TextDecoration
d2 Maybe VerticalAlign
e2 Maybe Text
f2 Maybe Text
g2 Maybe DisplayStyle
h2 Maybe TextCase
i2 Maybe Text
j2 Bool
k2 Bool
l2 Bool
m2) =
     Maybe Lang
-> Maybe FontStyle
-> Maybe FontVariant
-> Maybe FontWeight
-> Maybe TextDecoration
-> Maybe VerticalAlign
-> Maybe Text
-> Maybe Text
-> Maybe DisplayStyle
-> Maybe TextCase
-> Maybe Text
-> Bool
-> Bool
-> Bool
-> Formatting
Formatting (Maybe Lang
la1 Maybe Lang -> Maybe Lang -> Maybe Lang
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Lang
la2) (Maybe FontStyle
a1 Maybe FontStyle -> Maybe FontStyle -> Maybe FontStyle
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe FontStyle
a2) (Maybe FontVariant
b1 Maybe FontVariant -> Maybe FontVariant -> Maybe FontVariant
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe FontVariant
b2) (Maybe FontWeight
c1 Maybe FontWeight -> Maybe FontWeight -> Maybe FontWeight
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe FontWeight
c2)
                (Maybe TextDecoration
d1 Maybe TextDecoration
-> Maybe TextDecoration -> Maybe TextDecoration
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe TextDecoration
d2) (Maybe VerticalAlign
e1 Maybe VerticalAlign -> Maybe VerticalAlign -> Maybe VerticalAlign
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe VerticalAlign
e2) (Maybe Text
f1 Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Text
f2)
                (Maybe Text
g1 Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Text
g2) (Maybe DisplayStyle
h1 Maybe DisplayStyle -> Maybe DisplayStyle -> Maybe DisplayStyle
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe DisplayStyle
h2) (Maybe TextCase
i1 Maybe TextCase -> Maybe TextCase -> Maybe TextCase
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe TextCase
i2)
                (Maybe Text
j1 Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Text
j2) (Bool
k1 Bool -> Bool -> Bool
|| Bool
k2) (Bool
l1 Bool -> Bool -> Bool
|| Bool
l2) (Bool
m1 Bool -> Bool -> Bool
|| Bool
m2)

instance Semigroup Formatting where
 <> :: Formatting -> Formatting -> Formatting
(<>) = Formatting -> Formatting -> Formatting
combineFormatting

instance Monoid Formatting where
 mempty :: Formatting
mempty = Formatting
defaultFormatting
 mappend :: Formatting -> Formatting -> Formatting
mappend = Formatting -> Formatting -> Formatting
forall a. Semigroup a => a -> a -> a
(<>)

data TextCase =
     Lowercase
   | Uppercase
   | CapitalizeFirst
   | CapitalizeAll
   | SentenceCase
   | TitleCase
   deriving (Int -> TextCase -> ShowS
[TextCase] -> ShowS
TextCase -> String
(Int -> TextCase -> ShowS)
-> (TextCase -> String) -> ([TextCase] -> ShowS) -> Show TextCase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextCase -> ShowS
showsPrec :: Int -> TextCase -> ShowS
$cshow :: TextCase -> String
show :: TextCase -> String
$cshowList :: [TextCase] -> ShowS
showList :: [TextCase] -> ShowS
Show, TextCase -> TextCase -> Bool
(TextCase -> TextCase -> Bool)
-> (TextCase -> TextCase -> Bool) -> Eq TextCase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextCase -> TextCase -> Bool
== :: TextCase -> TextCase -> Bool
$c/= :: TextCase -> TextCase -> Bool
/= :: TextCase -> TextCase -> Bool
Eq)

data DisplayStyle =
      DisplayBlock
    | DisplayLeftMargin
    | DisplayRightInline
    | DisplayIndent
    deriving (Int -> DisplayStyle -> ShowS
[DisplayStyle] -> ShowS
DisplayStyle -> String
(Int -> DisplayStyle -> ShowS)
-> (DisplayStyle -> String)
-> ([DisplayStyle] -> ShowS)
-> Show DisplayStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DisplayStyle -> ShowS
showsPrec :: Int -> DisplayStyle -> ShowS
$cshow :: DisplayStyle -> String
show :: DisplayStyle -> String
$cshowList :: [DisplayStyle] -> ShowS
showList :: [DisplayStyle] -> ShowS
Show, DisplayStyle -> DisplayStyle -> Bool
(DisplayStyle -> DisplayStyle -> Bool)
-> (DisplayStyle -> DisplayStyle -> Bool) -> Eq DisplayStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DisplayStyle -> DisplayStyle -> Bool
== :: DisplayStyle -> DisplayStyle -> Bool
$c/= :: DisplayStyle -> DisplayStyle -> Bool
/= :: DisplayStyle -> DisplayStyle -> Bool
Eq)

data FontStyle =
       NormalFont
    | ItalicFont
    | ObliqueFont
    deriving (Int -> FontStyle -> ShowS
[FontStyle] -> ShowS
FontStyle -> String
(Int -> FontStyle -> ShowS)
-> (FontStyle -> String)
-> ([FontStyle] -> ShowS)
-> Show FontStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FontStyle -> ShowS
showsPrec :: Int -> FontStyle -> ShowS
$cshow :: FontStyle -> String
show :: FontStyle -> String
$cshowList :: [FontStyle] -> ShowS
showList :: [FontStyle] -> ShowS
Show, FontStyle -> FontStyle -> Bool
(FontStyle -> FontStyle -> Bool)
-> (FontStyle -> FontStyle -> Bool) -> Eq FontStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FontStyle -> FontStyle -> Bool
== :: FontStyle -> FontStyle -> Bool
$c/= :: FontStyle -> FontStyle -> Bool
/= :: FontStyle -> FontStyle -> Bool
Eq)

data FontVariant =
      NormalVariant
    | SmallCapsVariant
    deriving (Int -> FontVariant -> ShowS
[FontVariant] -> ShowS
FontVariant -> String
(Int -> FontVariant -> ShowS)
-> (FontVariant -> String)
-> ([FontVariant] -> ShowS)
-> Show FontVariant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FontVariant -> ShowS
showsPrec :: Int -> FontVariant -> ShowS
$cshow :: FontVariant -> String
show :: FontVariant -> String
$cshowList :: [FontVariant] -> ShowS
showList :: [FontVariant] -> ShowS
Show, FontVariant -> FontVariant -> Bool
(FontVariant -> FontVariant -> Bool)
-> (FontVariant -> FontVariant -> Bool) -> Eq FontVariant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FontVariant -> FontVariant -> Bool
== :: FontVariant -> FontVariant -> Bool
$c/= :: FontVariant -> FontVariant -> Bool
/= :: FontVariant -> FontVariant -> Bool
Eq)

data FontWeight =
      NormalWeight
    | BoldWeight
    | LightWeight
    deriving (Int -> FontWeight -> ShowS
[FontWeight] -> ShowS
FontWeight -> String
(Int -> FontWeight -> ShowS)
-> (FontWeight -> String)
-> ([FontWeight] -> ShowS)
-> Show FontWeight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FontWeight -> ShowS
showsPrec :: Int -> FontWeight -> ShowS
$cshow :: FontWeight -> String
show :: FontWeight -> String
$cshowList :: [FontWeight] -> ShowS
showList :: [FontWeight] -> ShowS
Show, FontWeight -> FontWeight -> Bool
(FontWeight -> FontWeight -> Bool)
-> (FontWeight -> FontWeight -> Bool) -> Eq FontWeight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FontWeight -> FontWeight -> Bool
== :: FontWeight -> FontWeight -> Bool
$c/= :: FontWeight -> FontWeight -> Bool
/= :: FontWeight -> FontWeight -> Bool
Eq)

data TextDecoration =
      NoDecoration
    | UnderlineDecoration
    deriving (Int -> TextDecoration -> ShowS
[TextDecoration] -> ShowS
TextDecoration -> String
(Int -> TextDecoration -> ShowS)
-> (TextDecoration -> String)
-> ([TextDecoration] -> ShowS)
-> Show TextDecoration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextDecoration -> ShowS
showsPrec :: Int -> TextDecoration -> ShowS
$cshow :: TextDecoration -> String
show :: TextDecoration -> String
$cshowList :: [TextDecoration] -> ShowS
showList :: [TextDecoration] -> ShowS
Show, TextDecoration -> TextDecoration -> Bool
(TextDecoration -> TextDecoration -> Bool)
-> (TextDecoration -> TextDecoration -> Bool) -> Eq TextDecoration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextDecoration -> TextDecoration -> Bool
== :: TextDecoration -> TextDecoration -> Bool
$c/= :: TextDecoration -> TextDecoration -> Bool
/= :: TextDecoration -> TextDecoration -> Bool
Eq)

data VerticalAlign =
      BaselineAlign
    | SupAlign
    | SubAlign
    deriving (Int -> VerticalAlign -> ShowS
[VerticalAlign] -> ShowS
VerticalAlign -> String
(Int -> VerticalAlign -> ShowS)
-> (VerticalAlign -> String)
-> ([VerticalAlign] -> ShowS)
-> Show VerticalAlign
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VerticalAlign -> ShowS
showsPrec :: Int -> VerticalAlign -> ShowS
$cshow :: VerticalAlign -> String
show :: VerticalAlign -> String
$cshowList :: [VerticalAlign] -> ShowS
showList :: [VerticalAlign] -> ShowS
Show, VerticalAlign -> VerticalAlign -> Bool
(VerticalAlign -> VerticalAlign -> Bool)
-> (VerticalAlign -> VerticalAlign -> Bool) -> Eq VerticalAlign
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VerticalAlign -> VerticalAlign -> Bool
== :: VerticalAlign -> VerticalAlign -> Bool
$c/= :: VerticalAlign -> VerticalAlign -> Bool
/= :: VerticalAlign -> VerticalAlign -> Bool
Eq)

data Element a = Element (ElementType a) Formatting
  deriving (Int -> Element a -> ShowS
[Element a] -> ShowS
Element a -> String
(Int -> Element a -> ShowS)
-> (Element a -> String)
-> ([Element a] -> ShowS)
-> Show (Element a)
forall a. Int -> Element a -> ShowS
forall a. [Element a] -> ShowS
forall a. Element a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> Element a -> ShowS
showsPrec :: Int -> Element a -> ShowS
$cshow :: forall a. Element a -> String
show :: Element a -> String
$cshowList :: forall a. [Element a] -> ShowS
showList :: [Element a] -> ShowS
Show, Element a -> Element a -> Bool
(Element a -> Element a -> Bool)
-> (Element a -> Element a -> Bool) -> Eq (Element a)
forall a. Element a -> Element a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Element a -> Element a -> Bool
== :: Element a -> Element a -> Bool
$c/= :: forall a. Element a -> Element a -> Bool
/= :: Element a -> Element a -> Bool
Eq)

data SortDirection =
    Ascending
  | Descending
  deriving (Int -> SortDirection -> ShowS
[SortDirection] -> ShowS
SortDirection -> String
(Int -> SortDirection -> ShowS)
-> (SortDirection -> String)
-> ([SortDirection] -> ShowS)
-> Show SortDirection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SortDirection -> ShowS
showsPrec :: Int -> SortDirection -> ShowS
$cshow :: SortDirection -> String
show :: SortDirection -> String
$cshowList :: [SortDirection] -> ShowS
showList :: [SortDirection] -> ShowS
Show, SortDirection -> SortDirection -> Bool
(SortDirection -> SortDirection -> Bool)
-> (SortDirection -> SortDirection -> Bool) -> Eq SortDirection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SortDirection -> SortDirection -> Bool
== :: SortDirection -> SortDirection -> Bool
$c/= :: SortDirection -> SortDirection -> Bool
/= :: SortDirection -> SortDirection -> Bool
Eq)

data SortKey a =
     SortKeyVariable SortDirection Variable
   | SortKeyMacro SortDirection [Element a]
  deriving (Int -> SortKey a -> ShowS
[SortKey a] -> ShowS
SortKey a -> String
(Int -> SortKey a -> ShowS)
-> (SortKey a -> String)
-> ([SortKey a] -> ShowS)
-> Show (SortKey a)
forall a. Int -> SortKey a -> ShowS
forall a. [SortKey a] -> ShowS
forall a. SortKey a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> SortKey a -> ShowS
showsPrec :: Int -> SortKey a -> ShowS
$cshow :: forall a. SortKey a -> String
show :: SortKey a -> String
$cshowList :: forall a. [SortKey a] -> ShowS
showList :: [SortKey a] -> ShowS
Show, SortKey a -> SortKey a -> Bool
(SortKey a -> SortKey a -> Bool)
-> (SortKey a -> SortKey a -> Bool) -> Eq (SortKey a)
forall a. SortKey a -> SortKey a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. SortKey a -> SortKey a -> Bool
== :: SortKey a -> SortKey a -> Bool
$c/= :: forall a. SortKey a -> SortKey a -> Bool
/= :: SortKey a -> SortKey a -> Bool
Eq)

data SortKeyValue =
  SortKeyValue SortDirection (Maybe [Text])
  deriving (Int -> SortKeyValue -> ShowS
[SortKeyValue] -> ShowS
SortKeyValue -> String
(Int -> SortKeyValue -> ShowS)
-> (SortKeyValue -> String)
-> ([SortKeyValue] -> ShowS)
-> Show SortKeyValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SortKeyValue -> ShowS
showsPrec :: Int -> SortKeyValue -> ShowS
$cshow :: SortKeyValue -> String
show :: SortKeyValue -> String
$cshowList :: [SortKeyValue] -> ShowS
showList :: [SortKeyValue] -> ShowS
Show, SortKeyValue -> SortKeyValue -> Bool
(SortKeyValue -> SortKeyValue -> Bool)
-> (SortKeyValue -> SortKeyValue -> Bool) -> Eq SortKeyValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SortKeyValue -> SortKeyValue -> Bool
== :: SortKeyValue -> SortKeyValue -> Bool
$c/= :: SortKeyValue -> SortKeyValue -> Bool
/= :: SortKeyValue -> SortKeyValue -> Bool
Eq)

data Layout a =
  Layout
  { forall a. Layout a -> LayoutOptions
layoutOptions        :: LayoutOptions
  , forall a. Layout a -> Formatting
layoutFormatting     :: Formatting
  , forall a. Layout a -> [Element a]
layoutElements       :: [Element a]
  , forall a. Layout a -> [SortKey a]
layoutSortKeys       :: [SortKey a]
  } deriving (Int -> Layout a -> ShowS
[Layout a] -> ShowS
Layout a -> String
(Int -> Layout a -> ShowS)
-> (Layout a -> String) -> ([Layout a] -> ShowS) -> Show (Layout a)
forall a. Int -> Layout a -> ShowS
forall a. [Layout a] -> ShowS
forall a. Layout a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> Layout a -> ShowS
showsPrec :: Int -> Layout a -> ShowS
$cshow :: forall a. Layout a -> String
show :: Layout a -> String
$cshowList :: forall a. [Layout a] -> ShowS
showList :: [Layout a] -> ShowS
Show, Layout a -> Layout a -> Bool
(Layout a -> Layout a -> Bool)
-> (Layout a -> Layout a -> Bool) -> Eq (Layout a)
forall a. Layout a -> Layout a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Layout a -> Layout a -> Bool
== :: Layout a -> Layout a -> Bool
$c/= :: forall a. Layout a -> Layout a -> Bool
/= :: Layout a -> Layout a -> Bool
Eq)

data LayoutOptions =
  LayoutOptions
  { LayoutOptions -> Maybe Collapsing
layoutCollapse               :: Maybe Collapsing
  , LayoutOptions -> Maybe Text
layoutYearSuffixDelimiter    :: Maybe Text
  , LayoutOptions -> Maybe Text
layoutAfterCollapseDelimiter :: Maybe Text
  } deriving (Int -> LayoutOptions -> ShowS
[LayoutOptions] -> ShowS
LayoutOptions -> String
(Int -> LayoutOptions -> ShowS)
-> (LayoutOptions -> String)
-> ([LayoutOptions] -> ShowS)
-> Show LayoutOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LayoutOptions -> ShowS
showsPrec :: Int -> LayoutOptions -> ShowS
$cshow :: LayoutOptions -> String
show :: LayoutOptions -> String
$cshowList :: [LayoutOptions] -> ShowS
showList :: [LayoutOptions] -> ShowS
Show, LayoutOptions -> LayoutOptions -> Bool
(LayoutOptions -> LayoutOptions -> Bool)
-> (LayoutOptions -> LayoutOptions -> Bool) -> Eq LayoutOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LayoutOptions -> LayoutOptions -> Bool
== :: LayoutOptions -> LayoutOptions -> Bool
$c/= :: LayoutOptions -> LayoutOptions -> Bool
/= :: LayoutOptions -> LayoutOptions -> Bool
Eq)

data Collapsing =
     CollapseCitationNumber
   | CollapseYear
   | CollapseYearSuffix
   | CollapseYearSuffixRanged
   deriving (Int -> Collapsing -> ShowS
[Collapsing] -> ShowS
Collapsing -> String
(Int -> Collapsing -> ShowS)
-> (Collapsing -> String)
-> ([Collapsing] -> ShowS)
-> Show Collapsing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Collapsing -> ShowS
showsPrec :: Int -> Collapsing -> ShowS
$cshow :: Collapsing -> String
show :: Collapsing -> String
$cshowList :: [Collapsing] -> ShowS
showList :: [Collapsing] -> ShowS
Show, Collapsing -> Collapsing -> Bool
(Collapsing -> Collapsing -> Bool)
-> (Collapsing -> Collapsing -> Bool) -> Eq Collapsing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Collapsing -> Collapsing -> Bool
== :: Collapsing -> Collapsing -> Bool
$c/= :: Collapsing -> Collapsing -> Bool
/= :: Collapsing -> Collapsing -> Bool
Eq)

data DisambiguationStrategy =
  DisambiguationStrategy
  { DisambiguationStrategy -> Bool
disambiguateAddNames      :: Bool
  , DisambiguationStrategy -> Maybe GivenNameDisambiguationRule
disambiguateAddGivenNames :: Maybe GivenNameDisambiguationRule
  , DisambiguationStrategy -> Bool
disambiguateAddYearSuffix :: Bool
  } deriving (Int -> DisambiguationStrategy -> ShowS
[DisambiguationStrategy] -> ShowS
DisambiguationStrategy -> String
(Int -> DisambiguationStrategy -> ShowS)
-> (DisambiguationStrategy -> String)
-> ([DisambiguationStrategy] -> ShowS)
-> Show DisambiguationStrategy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DisambiguationStrategy -> ShowS
showsPrec :: Int -> DisambiguationStrategy -> ShowS
$cshow :: DisambiguationStrategy -> String
show :: DisambiguationStrategy -> String
$cshowList :: [DisambiguationStrategy] -> ShowS
showList :: [DisambiguationStrategy] -> ShowS
Show, DisambiguationStrategy -> DisambiguationStrategy -> Bool
(DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> (DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> Eq DisambiguationStrategy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
== :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
$c/= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
/= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
Eq, Eq DisambiguationStrategy
Eq DisambiguationStrategy =>
(DisambiguationStrategy -> DisambiguationStrategy -> Ordering)
-> (DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> (DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> (DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> (DisambiguationStrategy -> DisambiguationStrategy -> Bool)
-> (DisambiguationStrategy
    -> DisambiguationStrategy -> DisambiguationStrategy)
-> (DisambiguationStrategy
    -> DisambiguationStrategy -> DisambiguationStrategy)
-> Ord DisambiguationStrategy
DisambiguationStrategy -> DisambiguationStrategy -> Bool
DisambiguationStrategy -> DisambiguationStrategy -> Ordering
DisambiguationStrategy
-> DisambiguationStrategy -> DisambiguationStrategy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DisambiguationStrategy -> DisambiguationStrategy -> Ordering
compare :: DisambiguationStrategy -> DisambiguationStrategy -> Ordering
$c< :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
< :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
$c<= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
<= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
$c> :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
> :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
$c>= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
>= :: DisambiguationStrategy -> DisambiguationStrategy -> Bool
$cmax :: DisambiguationStrategy
-> DisambiguationStrategy -> DisambiguationStrategy
max :: DisambiguationStrategy
-> DisambiguationStrategy -> DisambiguationStrategy
$cmin :: DisambiguationStrategy
-> DisambiguationStrategy -> DisambiguationStrategy
min :: DisambiguationStrategy
-> DisambiguationStrategy -> DisambiguationStrategy
Ord)

data GivenNameDisambiguationRule =
    AllNames
  | AllNamesWithInitials
  | PrimaryName
  | PrimaryNameWithInitials
  | ByCite
  deriving (Int -> GivenNameDisambiguationRule -> ShowS
[GivenNameDisambiguationRule] -> ShowS
GivenNameDisambiguationRule -> String
(Int -> GivenNameDisambiguationRule -> ShowS)
-> (GivenNameDisambiguationRule -> String)
-> ([GivenNameDisambiguationRule] -> ShowS)
-> Show GivenNameDisambiguationRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GivenNameDisambiguationRule -> ShowS
showsPrec :: Int -> GivenNameDisambiguationRule -> ShowS
$cshow :: GivenNameDisambiguationRule -> String
show :: GivenNameDisambiguationRule -> String
$cshowList :: [GivenNameDisambiguationRule] -> ShowS
showList :: [GivenNameDisambiguationRule] -> ShowS
Show, GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
(GivenNameDisambiguationRule
 -> GivenNameDisambiguationRule -> Bool)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> Bool)
-> Eq GivenNameDisambiguationRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
== :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
$c/= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
/= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
Eq, Eq GivenNameDisambiguationRule
Eq GivenNameDisambiguationRule =>
(GivenNameDisambiguationRule
 -> GivenNameDisambiguationRule -> Ordering)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> Bool)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> Bool)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> Bool)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> Bool)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> GivenNameDisambiguationRule)
-> (GivenNameDisambiguationRule
    -> GivenNameDisambiguationRule -> GivenNameDisambiguationRule)
-> Ord GivenNameDisambiguationRule
GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> Ordering
GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> GivenNameDisambiguationRule
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> Ordering
compare :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> Ordering
$c< :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
< :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
$c<= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
<= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
$c> :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
> :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
$c>= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
>= :: GivenNameDisambiguationRule -> GivenNameDisambiguationRule -> Bool
$cmax :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> GivenNameDisambiguationRule
max :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> GivenNameDisambiguationRule
$cmin :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> GivenNameDisambiguationRule
min :: GivenNameDisambiguationRule
-> GivenNameDisambiguationRule -> GivenNameDisambiguationRule
Ord)

data DemoteNonDroppingParticle =
     DemoteDisplayAndSort
   | DemoteSortOnly
   | DemoteNever
   deriving (Int -> DemoteNonDroppingParticle -> ShowS
[DemoteNonDroppingParticle] -> ShowS
DemoteNonDroppingParticle -> String
(Int -> DemoteNonDroppingParticle -> ShowS)
-> (DemoteNonDroppingParticle -> String)
-> ([DemoteNonDroppingParticle] -> ShowS)
-> Show DemoteNonDroppingParticle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DemoteNonDroppingParticle -> ShowS
showsPrec :: Int -> DemoteNonDroppingParticle -> ShowS
$cshow :: DemoteNonDroppingParticle -> String
show :: DemoteNonDroppingParticle -> String
$cshowList :: [DemoteNonDroppingParticle] -> ShowS
showList :: [DemoteNonDroppingParticle] -> ShowS
Show, DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool
(DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool)
-> (DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool)
-> Eq DemoteNonDroppingParticle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool
== :: DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool
$c/= :: DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool
/= :: DemoteNonDroppingParticle -> DemoteNonDroppingParticle -> Bool
Eq)

data StyleOptions =
  StyleOptions
  { StyleOptions -> Bool
styleIsNoteStyle                :: Bool
  , StyleOptions -> Maybe Lang
styleDefaultLocale              :: Maybe Lang
  , StyleOptions -> DemoteNonDroppingParticle
styleDemoteNonDroppingParticle  :: DemoteNonDroppingParticle
  , StyleOptions -> Bool
styleInitializeWithHyphen       :: Bool
  , StyleOptions -> Maybe PageRangeFormat
stylePageRangeFormat            :: Maybe PageRangeFormat
  , StyleOptions -> Maybe Text
stylePageRangeDelimiter         :: Maybe Text
  , StyleOptions -> DisambiguationStrategy
styleDisambiguation             :: DisambiguationStrategy
  , StyleOptions -> Maybe Int
styleNearNoteDistance           :: Maybe Int
  , StyleOptions -> Maybe Text
styleCiteGroupDelimiter         :: Maybe Text
  , StyleOptions -> Maybe Int
styleLineSpacing                :: Maybe Int
  , StyleOptions -> Maybe Int
styleEntrySpacing               :: Maybe Int
  , StyleOptions -> Bool
styleHangingIndent              :: Bool
  , StyleOptions -> Maybe SecondFieldAlign
styleSecondFieldAlign           :: Maybe SecondFieldAlign
  , StyleOptions -> Maybe SubsequentAuthorSubstitute
styleSubsequentAuthorSubstitute :: Maybe SubsequentAuthorSubstitute
  , StyleOptions -> Bool
styleUsesYearSuffixVariable     :: Bool
  } deriving (Int -> StyleOptions -> ShowS
[StyleOptions] -> ShowS
StyleOptions -> String
(Int -> StyleOptions -> ShowS)
-> (StyleOptions -> String)
-> ([StyleOptions] -> ShowS)
-> Show StyleOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StyleOptions -> ShowS
showsPrec :: Int -> StyleOptions -> ShowS
$cshow :: StyleOptions -> String
show :: StyleOptions -> String
$cshowList :: [StyleOptions] -> ShowS
showList :: [StyleOptions] -> ShowS
Show, StyleOptions -> StyleOptions -> Bool
(StyleOptions -> StyleOptions -> Bool)
-> (StyleOptions -> StyleOptions -> Bool) -> Eq StyleOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StyleOptions -> StyleOptions -> Bool
== :: StyleOptions -> StyleOptions -> Bool
$c/= :: StyleOptions -> StyleOptions -> Bool
/= :: StyleOptions -> StyleOptions -> Bool
Eq)

data SubsequentAuthorSubstitute =
  SubsequentAuthorSubstitute Text SubsequentAuthorSubstituteRule
  deriving (Int -> SubsequentAuthorSubstitute -> ShowS
[SubsequentAuthorSubstitute] -> ShowS
SubsequentAuthorSubstitute -> String
(Int -> SubsequentAuthorSubstitute -> ShowS)
-> (SubsequentAuthorSubstitute -> String)
-> ([SubsequentAuthorSubstitute] -> ShowS)
-> Show SubsequentAuthorSubstitute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubsequentAuthorSubstitute -> ShowS
showsPrec :: Int -> SubsequentAuthorSubstitute -> ShowS
$cshow :: SubsequentAuthorSubstitute -> String
show :: SubsequentAuthorSubstitute -> String
$cshowList :: [SubsequentAuthorSubstitute] -> ShowS
showList :: [SubsequentAuthorSubstitute] -> ShowS
Show, SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool
(SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool)
-> (SubsequentAuthorSubstitute
    -> SubsequentAuthorSubstitute -> Bool)
-> Eq SubsequentAuthorSubstitute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool
== :: SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool
$c/= :: SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool
/= :: SubsequentAuthorSubstitute -> SubsequentAuthorSubstitute -> Bool
Eq)

data SubsequentAuthorSubstituteRule =
      CompleteAll
    | CompleteEach
    | PartialEach
    | PartialFirst
    deriving (Int -> SubsequentAuthorSubstituteRule -> ShowS
[SubsequentAuthorSubstituteRule] -> ShowS
SubsequentAuthorSubstituteRule -> String
(Int -> SubsequentAuthorSubstituteRule -> ShowS)
-> (SubsequentAuthorSubstituteRule -> String)
-> ([SubsequentAuthorSubstituteRule] -> ShowS)
-> Show SubsequentAuthorSubstituteRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubsequentAuthorSubstituteRule -> ShowS
showsPrec :: Int -> SubsequentAuthorSubstituteRule -> ShowS
$cshow :: SubsequentAuthorSubstituteRule -> String
show :: SubsequentAuthorSubstituteRule -> String
$cshowList :: [SubsequentAuthorSubstituteRule] -> ShowS
showList :: [SubsequentAuthorSubstituteRule] -> ShowS
Show, SubsequentAuthorSubstituteRule
-> SubsequentAuthorSubstituteRule -> Bool
(SubsequentAuthorSubstituteRule
 -> SubsequentAuthorSubstituteRule -> Bool)
-> (SubsequentAuthorSubstituteRule
    -> SubsequentAuthorSubstituteRule -> Bool)
-> Eq SubsequentAuthorSubstituteRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SubsequentAuthorSubstituteRule
-> SubsequentAuthorSubstituteRule -> Bool
== :: SubsequentAuthorSubstituteRule
-> SubsequentAuthorSubstituteRule -> Bool
$c/= :: SubsequentAuthorSubstituteRule
-> SubsequentAuthorSubstituteRule -> Bool
/= :: SubsequentAuthorSubstituteRule
-> SubsequentAuthorSubstituteRule -> Bool
Eq)

data SecondFieldAlign =
      SecondFieldAlignFlush
    | SecondFieldAlignMargin
    deriving (Int -> SecondFieldAlign -> ShowS
[SecondFieldAlign] -> ShowS
SecondFieldAlign -> String
(Int -> SecondFieldAlign -> ShowS)
-> (SecondFieldAlign -> String)
-> ([SecondFieldAlign] -> ShowS)
-> Show SecondFieldAlign
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SecondFieldAlign -> ShowS
showsPrec :: Int -> SecondFieldAlign -> ShowS
$cshow :: SecondFieldAlign -> String
show :: SecondFieldAlign -> String
$cshowList :: [SecondFieldAlign] -> ShowS
showList :: [SecondFieldAlign] -> ShowS
Show, SecondFieldAlign -> SecondFieldAlign -> Bool
(SecondFieldAlign -> SecondFieldAlign -> Bool)
-> (SecondFieldAlign -> SecondFieldAlign -> Bool)
-> Eq SecondFieldAlign
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SecondFieldAlign -> SecondFieldAlign -> Bool
== :: SecondFieldAlign -> SecondFieldAlign -> Bool
$c/= :: SecondFieldAlign -> SecondFieldAlign -> Bool
/= :: SecondFieldAlign -> SecondFieldAlign -> Bool
Eq)

data PageRangeFormat =
    PageRangeChicago15
  | PageRangeChicago16
  | PageRangeExpanded
  | PageRangeMinimal
  | PageRangeMinimalTwo
  deriving (Int -> PageRangeFormat -> ShowS
[PageRangeFormat] -> ShowS
PageRangeFormat -> String
(Int -> PageRangeFormat -> ShowS)
-> (PageRangeFormat -> String)
-> ([PageRangeFormat] -> ShowS)
-> Show PageRangeFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PageRangeFormat -> ShowS
showsPrec :: Int -> PageRangeFormat -> ShowS
$cshow :: PageRangeFormat -> String
show :: PageRangeFormat -> String
$cshowList :: [PageRangeFormat] -> ShowS
showList :: [PageRangeFormat] -> ShowS
Show, PageRangeFormat -> PageRangeFormat -> Bool
(PageRangeFormat -> PageRangeFormat -> Bool)
-> (PageRangeFormat -> PageRangeFormat -> Bool)
-> Eq PageRangeFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PageRangeFormat -> PageRangeFormat -> Bool
== :: PageRangeFormat -> PageRangeFormat -> Bool
$c/= :: PageRangeFormat -> PageRangeFormat -> Bool
/= :: PageRangeFormat -> PageRangeFormat -> Bool
Eq, Eq PageRangeFormat
Eq PageRangeFormat =>
(PageRangeFormat -> PageRangeFormat -> Ordering)
-> (PageRangeFormat -> PageRangeFormat -> Bool)
-> (PageRangeFormat -> PageRangeFormat -> Bool)
-> (PageRangeFormat -> PageRangeFormat -> Bool)
-> (PageRangeFormat -> PageRangeFormat -> Bool)
-> (PageRangeFormat -> PageRangeFormat -> PageRangeFormat)
-> (PageRangeFormat -> PageRangeFormat -> PageRangeFormat)
-> Ord PageRangeFormat
PageRangeFormat -> PageRangeFormat -> Bool
PageRangeFormat -> PageRangeFormat -> Ordering
PageRangeFormat -> PageRangeFormat -> PageRangeFormat
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PageRangeFormat -> PageRangeFormat -> Ordering
compare :: PageRangeFormat -> PageRangeFormat -> Ordering
$c< :: PageRangeFormat -> PageRangeFormat -> Bool
< :: PageRangeFormat -> PageRangeFormat -> Bool
$c<= :: PageRangeFormat -> PageRangeFormat -> Bool
<= :: PageRangeFormat -> PageRangeFormat -> Bool
$c> :: PageRangeFormat -> PageRangeFormat -> Bool
> :: PageRangeFormat -> PageRangeFormat -> Bool
$c>= :: PageRangeFormat -> PageRangeFormat -> Bool
>= :: PageRangeFormat -> PageRangeFormat -> Bool
$cmax :: PageRangeFormat -> PageRangeFormat -> PageRangeFormat
max :: PageRangeFormat -> PageRangeFormat -> PageRangeFormat
$cmin :: PageRangeFormat -> PageRangeFormat -> PageRangeFormat
min :: PageRangeFormat -> PageRangeFormat -> PageRangeFormat
Ord)

data Style a =
  Style
  { forall a. Style a -> (Int, Int, Int)
styleCslVersion    :: (Int,Int,Int)
  , forall a. Style a -> StyleOptions
styleOptions       :: StyleOptions
  , forall a. Style a -> Layout a
styleCitation      :: Layout a
  , forall a. Style a -> Maybe (Layout a)
styleBibliography  :: Maybe (Layout a)
  , forall a. Style a -> [Locale]
styleLocales       :: [Locale]
  , forall a. Style a -> Maybe Abbreviations
styleAbbreviations :: Maybe Abbreviations
  } deriving (Int -> Style a -> ShowS
[Style a] -> ShowS
Style a -> String
(Int -> Style a -> ShowS)
-> (Style a -> String) -> ([Style a] -> ShowS) -> Show (Style a)
forall a. Int -> Style a -> ShowS
forall a. [Style a] -> ShowS
forall a. Style a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> Style a -> ShowS
showsPrec :: Int -> Style a -> ShowS
$cshow :: forall a. Style a -> String
show :: Style a -> String
$cshowList :: forall a. [Style a] -> ShowS
showList :: [Style a] -> ShowS
Show, Style a -> Style a -> Bool
(Style a -> Style a -> Bool)
-> (Style a -> Style a -> Bool) -> Eq (Style a)
forall a. Style a -> Style a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Style a -> Style a -> Bool
== :: Style a -> Style a -> Bool
$c/= :: forall a. Style a -> Style a -> Bool
/= :: Style a -> Style a -> Bool
Eq)
-- Note: no macros section, because we
-- expand these after parsing the CSL.

data TermForm =
    Long
  | Short
  | Verb
  | VerbShort
  | Symbol
  deriving (Int -> TermForm -> ShowS
[TermForm] -> ShowS
TermForm -> String
(Int -> TermForm -> ShowS)
-> (TermForm -> String) -> ([TermForm] -> ShowS) -> Show TermForm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermForm -> ShowS
showsPrec :: Int -> TermForm -> ShowS
$cshow :: TermForm -> String
show :: TermForm -> String
$cshowList :: [TermForm] -> ShowS
showList :: [TermForm] -> ShowS
Show, Eq TermForm
Eq TermForm =>
(TermForm -> TermForm -> Ordering)
-> (TermForm -> TermForm -> Bool)
-> (TermForm -> TermForm -> Bool)
-> (TermForm -> TermForm -> Bool)
-> (TermForm -> TermForm -> Bool)
-> (TermForm -> TermForm -> TermForm)
-> (TermForm -> TermForm -> TermForm)
-> Ord TermForm
TermForm -> TermForm -> Bool
TermForm -> TermForm -> Ordering
TermForm -> TermForm -> TermForm
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TermForm -> TermForm -> Ordering
compare :: TermForm -> TermForm -> Ordering
$c< :: TermForm -> TermForm -> Bool
< :: TermForm -> TermForm -> Bool
$c<= :: TermForm -> TermForm -> Bool
<= :: TermForm -> TermForm -> Bool
$c> :: TermForm -> TermForm -> Bool
> :: TermForm -> TermForm -> Bool
$c>= :: TermForm -> TermForm -> Bool
>= :: TermForm -> TermForm -> Bool
$cmax :: TermForm -> TermForm -> TermForm
max :: TermForm -> TermForm -> TermForm
$cmin :: TermForm -> TermForm -> TermForm
min :: TermForm -> TermForm -> TermForm
Ord, TermForm -> TermForm -> Bool
(TermForm -> TermForm -> Bool)
-> (TermForm -> TermForm -> Bool) -> Eq TermForm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermForm -> TermForm -> Bool
== :: TermForm -> TermForm -> Bool
$c/= :: TermForm -> TermForm -> Bool
/= :: TermForm -> TermForm -> Bool
Eq)

data TermNumber =
    Singular
  | Plural
  deriving (Int -> TermNumber -> ShowS
[TermNumber] -> ShowS
TermNumber -> String
(Int -> TermNumber -> ShowS)
-> (TermNumber -> String)
-> ([TermNumber] -> ShowS)
-> Show TermNumber
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermNumber -> ShowS
showsPrec :: Int -> TermNumber -> ShowS
$cshow :: TermNumber -> String
show :: TermNumber -> String
$cshowList :: [TermNumber] -> ShowS
showList :: [TermNumber] -> ShowS
Show, Eq TermNumber
Eq TermNumber =>
(TermNumber -> TermNumber -> Ordering)
-> (TermNumber -> TermNumber -> Bool)
-> (TermNumber -> TermNumber -> Bool)
-> (TermNumber -> TermNumber -> Bool)
-> (TermNumber -> TermNumber -> Bool)
-> (TermNumber -> TermNumber -> TermNumber)
-> (TermNumber -> TermNumber -> TermNumber)
-> Ord TermNumber
TermNumber -> TermNumber -> Bool
TermNumber -> TermNumber -> Ordering
TermNumber -> TermNumber -> TermNumber
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TermNumber -> TermNumber -> Ordering
compare :: TermNumber -> TermNumber -> Ordering
$c< :: TermNumber -> TermNumber -> Bool
< :: TermNumber -> TermNumber -> Bool
$c<= :: TermNumber -> TermNumber -> Bool
<= :: TermNumber -> TermNumber -> Bool
$c> :: TermNumber -> TermNumber -> Bool
> :: TermNumber -> TermNumber -> Bool
$c>= :: TermNumber -> TermNumber -> Bool
>= :: TermNumber -> TermNumber -> Bool
$cmax :: TermNumber -> TermNumber -> TermNumber
max :: TermNumber -> TermNumber -> TermNumber
$cmin :: TermNumber -> TermNumber -> TermNumber
min :: TermNumber -> TermNumber -> TermNumber
Ord, TermNumber -> TermNumber -> Bool
(TermNumber -> TermNumber -> Bool)
-> (TermNumber -> TermNumber -> Bool) -> Eq TermNumber
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermNumber -> TermNumber -> Bool
== :: TermNumber -> TermNumber -> Bool
$c/= :: TermNumber -> TermNumber -> Bool
/= :: TermNumber -> TermNumber -> Bool
Eq)

data TermGender =
    Masculine
  | Feminine
  deriving (Int -> TermGender -> ShowS
[TermGender] -> ShowS
TermGender -> String
(Int -> TermGender -> ShowS)
-> (TermGender -> String)
-> ([TermGender] -> ShowS)
-> Show TermGender
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermGender -> ShowS
showsPrec :: Int -> TermGender -> ShowS
$cshow :: TermGender -> String
show :: TermGender -> String
$cshowList :: [TermGender] -> ShowS
showList :: [TermGender] -> ShowS
Show, Eq TermGender
Eq TermGender =>
(TermGender -> TermGender -> Ordering)
-> (TermGender -> TermGender -> Bool)
-> (TermGender -> TermGender -> Bool)
-> (TermGender -> TermGender -> Bool)
-> (TermGender -> TermGender -> Bool)
-> (TermGender -> TermGender -> TermGender)
-> (TermGender -> TermGender -> TermGender)
-> Ord TermGender
TermGender -> TermGender -> Bool
TermGender -> TermGender -> Ordering
TermGender -> TermGender -> TermGender
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TermGender -> TermGender -> Ordering
compare :: TermGender -> TermGender -> Ordering
$c< :: TermGender -> TermGender -> Bool
< :: TermGender -> TermGender -> Bool
$c<= :: TermGender -> TermGender -> Bool
<= :: TermGender -> TermGender -> Bool
$c> :: TermGender -> TermGender -> Bool
> :: TermGender -> TermGender -> Bool
$c>= :: TermGender -> TermGender -> Bool
>= :: TermGender -> TermGender -> Bool
$cmax :: TermGender -> TermGender -> TermGender
max :: TermGender -> TermGender -> TermGender
$cmin :: TermGender -> TermGender -> TermGender
min :: TermGender -> TermGender -> TermGender
Ord, TermGender -> TermGender -> Bool
(TermGender -> TermGender -> Bool)
-> (TermGender -> TermGender -> Bool) -> Eq TermGender
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermGender -> TermGender -> Bool
== :: TermGender -> TermGender -> Bool
$c/= :: TermGender -> TermGender -> Bool
/= :: TermGender -> TermGender -> Bool
Eq)

data TermMatch =
    LastDigit
  | LastTwoDigits
  | WholeNumber
  deriving (Int -> TermMatch -> ShowS
[TermMatch] -> ShowS
TermMatch -> String
(Int -> TermMatch -> ShowS)
-> (TermMatch -> String)
-> ([TermMatch] -> ShowS)
-> Show TermMatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TermMatch -> ShowS
showsPrec :: Int -> TermMatch -> ShowS
$cshow :: TermMatch -> String
show :: TermMatch -> String
$cshowList :: [TermMatch] -> ShowS
showList :: [TermMatch] -> ShowS
Show, Eq TermMatch
Eq TermMatch =>
(TermMatch -> TermMatch -> Ordering)
-> (TermMatch -> TermMatch -> Bool)
-> (TermMatch -> TermMatch -> Bool)
-> (TermMatch -> TermMatch -> Bool)
-> (TermMatch -> TermMatch -> Bool)
-> (TermMatch -> TermMatch -> TermMatch)
-> (TermMatch -> TermMatch -> TermMatch)
-> Ord TermMatch
TermMatch -> TermMatch -> Bool
TermMatch -> TermMatch -> Ordering
TermMatch -> TermMatch -> TermMatch
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TermMatch -> TermMatch -> Ordering
compare :: TermMatch -> TermMatch -> Ordering
$c< :: TermMatch -> TermMatch -> Bool
< :: TermMatch -> TermMatch -> Bool
$c<= :: TermMatch -> TermMatch -> Bool
<= :: TermMatch -> TermMatch -> Bool
$c> :: TermMatch -> TermMatch -> Bool
> :: TermMatch -> TermMatch -> Bool
$c>= :: TermMatch -> TermMatch -> Bool
>= :: TermMatch -> TermMatch -> Bool
$cmax :: TermMatch -> TermMatch -> TermMatch
max :: TermMatch -> TermMatch -> TermMatch
$cmin :: TermMatch -> TermMatch -> TermMatch
min :: TermMatch -> TermMatch -> TermMatch
Ord, TermMatch -> TermMatch -> Bool
(TermMatch -> TermMatch -> Bool)
-> (TermMatch -> TermMatch -> Bool) -> Eq TermMatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TermMatch -> TermMatch -> Bool
== :: TermMatch -> TermMatch -> Bool
$c/= :: TermMatch -> TermMatch -> Bool
/= :: TermMatch -> TermMatch -> Bool
Eq)

data Term =
  Term
  { Term -> Text
termName          :: Text
  , Term -> TermForm
termForm          :: TermForm
  , Term -> Maybe TermNumber
termNumber        :: Maybe TermNumber
  , Term -> Maybe TermGender
termGender        :: Maybe TermGender
  , Term -> Maybe TermGender
termGenderForm    :: Maybe TermGender
  , Term -> Maybe TermMatch
termMatch         :: Maybe TermMatch
  } deriving (Int -> Term -> ShowS
[Term] -> ShowS
Term -> String
(Int -> Term -> ShowS)
-> (Term -> String) -> ([Term] -> ShowS) -> Show Term
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Term -> ShowS
showsPrec :: Int -> Term -> ShowS
$cshow :: Term -> String
show :: Term -> String
$cshowList :: [Term] -> ShowS
showList :: [Term] -> ShowS
Show, Term -> Term -> Bool
(Term -> Term -> Bool) -> (Term -> Term -> Bool) -> Eq Term
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Term -> Term -> Bool
== :: Term -> Term -> Bool
$c/= :: Term -> Term -> Bool
/= :: Term -> Term -> Bool
Eq)

emptyTerm :: Term
emptyTerm :: Term
emptyTerm = Text
-> TermForm
-> Maybe TermNumber
-> Maybe TermGender
-> Maybe TermGender
-> Maybe TermMatch
-> Term
Term Text
forall a. Monoid a => a
mempty TermForm
Long Maybe TermNumber
forall a. Maybe a
Nothing Maybe TermGender
forall a. Maybe a
Nothing Maybe TermGender
forall a. Maybe a
Nothing Maybe TermMatch
forall a. Maybe a
Nothing

instance Ord Term where
   <= :: Term -> Term -> Bool
(<=)(Term Text
name1 TermForm
form1 Maybe TermNumber
num1 Maybe TermGender
gen1 Maybe TermGender
gf1 Maybe TermMatch
match1)
       (Term Text
name2 TermForm
form2 Maybe TermNumber
num2 Maybe TermGender
gen2 Maybe TermGender
gf2 Maybe TermMatch
match2) =
     Text
name1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
name2 Bool -> Bool -> Bool
&&
     TermForm
form1 TermForm -> TermForm -> Bool
forall a. Eq a => a -> a -> Bool
== TermForm
form2 Bool -> Bool -> Bool
&&
     (Maybe TermNumber -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermNumber
num1   Bool -> Bool -> Bool
|| Maybe TermNumber -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermNumber
num2   Bool -> Bool -> Bool
|| Maybe TermNumber
num1 Maybe TermNumber -> Maybe TermNumber -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe TermNumber
num2) Bool -> Bool -> Bool
&&
     (Maybe TermGender -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermGender
gen1   Bool -> Bool -> Bool
|| Maybe TermGender -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermGender
gen2   Bool -> Bool -> Bool
|| Maybe TermGender
gen1 Maybe TermGender -> Maybe TermGender -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe TermGender
gen2) Bool -> Bool -> Bool
&&
     (Maybe TermGender -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermGender
gf1    Bool -> Bool -> Bool
|| Maybe TermGender -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermGender
gf2    Bool -> Bool -> Bool
|| Maybe TermGender
gf1  Maybe TermGender -> Maybe TermGender -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe TermGender
gf2 ) Bool -> Bool -> Bool
&&
     (Maybe TermMatch -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermMatch
match1 Bool -> Bool -> Bool
|| Maybe TermMatch -> Bool
forall a. Maybe a -> Bool
isNothing Maybe TermMatch
match2 Bool -> Bool -> Bool
|| Maybe TermMatch
match1 Maybe TermMatch -> Maybe TermMatch -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe TermMatch
match2)

-- | Defines locale-specific terms, punctuation styles, and date
-- formats.
data Locale =
  Locale
  { Locale -> Maybe Lang
localeLanguage               :: Maybe Lang
  , Locale -> Maybe Bool
localePunctuationInQuote     :: Maybe Bool
  , Locale -> Maybe Bool
localeLimitDayOrdinalsToDay1 :: Maybe Bool
  , Locale -> Map DateType (Element Text)
localeDate                   :: M.Map DateType (Element Text)
  , Locale -> Map Text [(Term, Text)]
localeTerms                  :: M.Map Text [(Term, Text)]
  }
  deriving (Int -> Locale -> ShowS
[Locale] -> ShowS
Locale -> String
(Int -> Locale -> ShowS)
-> (Locale -> String) -> ([Locale] -> ShowS) -> Show Locale
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Locale -> ShowS
showsPrec :: Int -> Locale -> ShowS
$cshow :: Locale -> String
show :: Locale -> String
$cshowList :: [Locale] -> ShowS
showList :: [Locale] -> ShowS
Show, Locale -> Locale -> Bool
(Locale -> Locale -> Bool)
-> (Locale -> Locale -> Bool) -> Eq Locale
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Locale -> Locale -> Bool
== :: Locale -> Locale -> Bool
$c/= :: Locale -> Locale -> Bool
/= :: Locale -> Locale -> Bool
Eq)

-- in x <> y, x values take precedence
instance Semigroup Locale where
 Locale Maybe Lang
lang1 Maybe Bool
pq1 Maybe Bool
ldo1 Map DateType (Element Text)
date1 Map Text [(Term, Text)]
ts1 <> :: Locale -> Locale -> Locale
<>
   Locale Maybe Lang
lang2 Maybe Bool
pq2 Maybe Bool
ldo2 Map DateType (Element Text)
date2 Map Text [(Term, Text)]
ts2 =
   Maybe Lang
-> Maybe Bool
-> Maybe Bool
-> Map DateType (Element Text)
-> Map Text [(Term, Text)]
-> Locale
Locale (Maybe Lang
lang1 Maybe Lang -> Maybe Lang -> Maybe Lang
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Lang
lang2)
          (Maybe Bool
pq1 Maybe Bool -> Maybe Bool -> Maybe Bool
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Bool
pq2)
          (Maybe Bool
ldo1 Maybe Bool -> Maybe Bool -> Maybe Bool
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Bool
ldo2)
          (Map DateType (Element Text)
date1 Map DateType (Element Text)
-> Map DateType (Element Text) -> Map DateType (Element Text)
forall a. Semigroup a => a -> a -> a
<> Map DateType (Element Text)
date2)
          (([(Term, Text)] -> [(Term, Text)] -> [(Term, Text)])
-> Map Text [(Term, Text)]
-> Map Text [(Term, Text)]
-> Map Text [(Term, Text)]
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
M.unionWith [(Term, Text)] -> [(Term, Text)] -> [(Term, Text)]
forall a. Semigroup a => a -> a -> a
(<>) Map Text [(Term, Text)]
ts1 Map Text [(Term, Text)]
ts2)

instance Monoid Locale where
 mempty :: Locale
mempty = Maybe Lang
-> Maybe Bool
-> Maybe Bool
-> Map DateType (Element Text)
-> Map Text [(Term, Text)]
-> Locale
Locale Maybe Lang
forall a. Maybe a
Nothing Maybe Bool
forall a. Maybe a
Nothing Maybe Bool
forall a. Maybe a
Nothing Map DateType (Element Text)
forall a. Monoid a => a
mempty Map Text [(Term, Text)]
forall a. Monoid a => a
mempty
 mappend :: Locale -> Locale -> Locale
mappend = Locale -> Locale -> Locale
forall a. Semigroup a => a -> a -> a
(<>)

newtype Variable = Variable (CI.CI Text)
  deriving (Int -> Variable -> ShowS
[Variable] -> ShowS
Variable -> String
(Int -> Variable -> ShowS)
-> (Variable -> String) -> ([Variable] -> ShowS) -> Show Variable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Variable -> ShowS
showsPrec :: Int -> Variable -> ShowS
$cshow :: Variable -> String
show :: Variable -> String
$cshowList :: [Variable] -> ShowS
showList :: [Variable] -> ShowS
Show, Eq Variable
Eq Variable =>
(Variable -> Variable -> Ordering)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool)
-> (Variable -> Variable -> Variable)
-> (Variable -> Variable -> Variable)
-> Ord Variable
Variable -> Variable -> Bool
Variable -> Variable -> Ordering
Variable -> Variable -> Variable
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Variable -> Variable -> Ordering
compare :: Variable -> Variable -> Ordering
$c< :: Variable -> Variable -> Bool
< :: Variable -> Variable -> Bool
$c<= :: Variable -> Variable -> Bool
<= :: Variable -> Variable -> Bool
$c> :: Variable -> Variable -> Bool
> :: Variable -> Variable -> Bool
$c>= :: Variable -> Variable -> Bool
>= :: Variable -> Variable -> Bool
$cmax :: Variable -> Variable -> Variable
max :: Variable -> Variable -> Variable
$cmin :: Variable -> Variable -> Variable
min :: Variable -> Variable -> Variable
Ord, Variable -> Variable -> Bool
(Variable -> Variable -> Bool)
-> (Variable -> Variable -> Bool) -> Eq Variable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Variable -> Variable -> Bool
== :: Variable -> Variable -> Bool
$c/= :: Variable -> Variable -> Bool
/= :: Variable -> Variable -> Bool
Eq, String -> Variable
(String -> Variable) -> IsString Variable
forall a. (String -> a) -> IsString a
$cfromString :: String -> Variable
fromString :: String -> Variable
IsString)

toVariable :: Text -> Variable
toVariable :: Text -> Variable
toVariable = CI Text -> Variable
Variable (CI Text -> Variable) -> (Text -> CI Text) -> Text -> Variable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> CI Text
forall s. FoldCase s => s -> CI s
CI.mk

fromVariable :: Variable -> Text
fromVariable :: Variable -> Text
fromVariable (Variable CI Text
x) = CI Text -> Text
forall s. CI s -> s
CI.original CI Text
x

instance Semigroup Variable where
  Variable CI Text
x <> :: Variable -> Variable -> Variable
<> Variable CI Text
y = CI Text -> Variable
Variable (CI Text
x CI Text -> CI Text -> CI Text
forall a. Semigroup a => a -> a -> a
<> CI Text
y)

instance Monoid Variable where
  mappend :: Variable -> Variable -> Variable
mappend = Variable -> Variable -> Variable
forall a. Semigroup a => a -> a -> a
(<>)
  mempty :: Variable
mempty = CI Text -> Variable
Variable CI Text
forall a. Monoid a => a
mempty

instance FromJSON Variable where
  parseJSON :: Value -> Parser Variable
parseJSON = (Text -> Variable) -> Parser Text -> Parser Variable
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (CI Text -> Variable
Variable (CI Text -> Variable) -> (Text -> CI Text) -> Text -> Variable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> CI Text
forall s. FoldCase s => s -> CI s
CI.mk) (Parser Text -> Parser Variable)
-> (Value -> Parser Text) -> Value -> Parser Variable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON

instance FromJSONKey Variable where
  fromJSONKey :: FromJSONKeyFunction Variable
fromJSONKey = (Text -> Variable) -> FromJSONKeyFunction Variable
forall a. (Text -> a) -> FromJSONKeyFunction a
FromJSONKeyText Text -> Variable
toVariable

instance ToJSON Variable where
  toJSON :: Variable -> Value
toJSON (Variable CI Text
v) = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ CI Text -> Text
forall s. CI s -> s
CI.original CI Text
v

instance ToJSONKey Variable where
  toJSONKey :: ToJSONKeyFunction Variable
toJSONKey = (Variable -> Text) -> ToJSONKeyFunction Variable
forall a. (a -> Text) -> ToJSONKeyFunction a
toJSONKeyText Variable -> Text
fromVariable

-- | Encodes bibliographic data for a single work.
data Reference a =
  Reference
  { forall a. Reference a -> ItemId
referenceId             :: ItemId
  , forall a. Reference a -> Text
referenceType           :: Text
  , forall a. Reference a -> Maybe DisambiguationData
referenceDisambiguation :: Maybe DisambiguationData
           -- ^ This is added in processing; if you are constructing
           -- a Reference, set to Nothing
  , forall a. Reference a -> Map Variable (Val a)
referenceVariables      :: M.Map Variable (Val a)
  } deriving (Int -> Reference a -> ShowS
[Reference a] -> ShowS
Reference a -> String
(Int -> Reference a -> ShowS)
-> (Reference a -> String)
-> ([Reference a] -> ShowS)
-> Show (Reference a)
forall a. Show a => Int -> Reference a -> ShowS
forall a. Show a => [Reference a] -> ShowS
forall a. Show a => Reference a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Reference a -> ShowS
showsPrec :: Int -> Reference a -> ShowS
$cshow :: forall a. Show a => Reference a -> String
show :: Reference a -> String
$cshowList :: forall a. Show a => [Reference a] -> ShowS
showList :: [Reference a] -> ShowS
Show, Eq (Reference a)
Eq (Reference a) =>
(Reference a -> Reference a -> Ordering)
-> (Reference a -> Reference a -> Bool)
-> (Reference a -> Reference a -> Bool)
-> (Reference a -> Reference a -> Bool)
-> (Reference a -> Reference a -> Bool)
-> (Reference a -> Reference a -> Reference a)
-> (Reference a -> Reference a -> Reference a)
-> Ord (Reference a)
Reference a -> Reference a -> Bool
Reference a -> Reference a -> Ordering
Reference a -> Reference a -> Reference a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Reference a)
forall a. Ord a => Reference a -> Reference a -> Bool
forall a. Ord a => Reference a -> Reference a -> Ordering
forall a. Ord a => Reference a -> Reference a -> Reference a
$ccompare :: forall a. Ord a => Reference a -> Reference a -> Ordering
compare :: Reference a -> Reference a -> Ordering
$c< :: forall a. Ord a => Reference a -> Reference a -> Bool
< :: Reference a -> Reference a -> Bool
$c<= :: forall a. Ord a => Reference a -> Reference a -> Bool
<= :: Reference a -> Reference a -> Bool
$c> :: forall a. Ord a => Reference a -> Reference a -> Bool
> :: Reference a -> Reference a -> Bool
$c>= :: forall a. Ord a => Reference a -> Reference a -> Bool
>= :: Reference a -> Reference a -> Bool
$cmax :: forall a. Ord a => Reference a -> Reference a -> Reference a
max :: Reference a -> Reference a -> Reference a
$cmin :: forall a. Ord a => Reference a -> Reference a -> Reference a
min :: Reference a -> Reference a -> Reference a
Ord, Reference a -> Reference a -> Bool
(Reference a -> Reference a -> Bool)
-> (Reference a -> Reference a -> Bool) -> Eq (Reference a)
forall a. Eq a => Reference a -> Reference a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Reference a -> Reference a -> Bool
== :: Reference a -> Reference a -> Bool
$c/= :: forall a. Eq a => Reference a -> Reference a -> Bool
/= :: Reference a -> Reference a -> Bool
Eq, (forall a b. (a -> b) -> Reference a -> Reference b)
-> (forall a b. a -> Reference b -> Reference a)
-> Functor Reference
forall a b. a -> Reference b -> Reference a
forall a b. (a -> b) -> Reference a -> Reference b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Reference a -> Reference b
fmap :: forall a b. (a -> b) -> Reference a -> Reference b
$c<$ :: forall a b. a -> Reference b -> Reference a
<$ :: forall a b. a -> Reference b -> Reference a
Functor, (forall m. Monoid m => Reference m -> m)
-> (forall m a. Monoid m => (a -> m) -> Reference a -> m)
-> (forall m a. Monoid m => (a -> m) -> Reference a -> m)
-> (forall a b. (a -> b -> b) -> b -> Reference a -> b)
-> (forall a b. (a -> b -> b) -> b -> Reference a -> b)
-> (forall b a. (b -> a -> b) -> b -> Reference a -> b)
-> (forall b a. (b -> a -> b) -> b -> Reference a -> b)
-> (forall a. (a -> a -> a) -> Reference a -> a)
-> (forall a. (a -> a -> a) -> Reference a -> a)
-> (forall a. Reference a -> [a])
-> (forall a. Reference a -> Bool)
-> (forall a. Reference a -> Int)
-> (forall a. Eq a => a -> Reference a -> Bool)
-> (forall a. Ord a => Reference a -> a)
-> (forall a. Ord a => Reference a -> a)
-> (forall a. Num a => Reference a -> a)
-> (forall a. Num a => Reference a -> a)
-> Foldable Reference
forall a. Eq a => a -> Reference a -> Bool
forall a. Num a => Reference a -> a
forall a. Ord a => Reference a -> a
forall m. Monoid m => Reference m -> m
forall a. Reference a -> Bool
forall a. Reference a -> Int
forall a. Reference a -> [a]
forall a. (a -> a -> a) -> Reference a -> a
forall m a. Monoid m => (a -> m) -> Reference a -> m
forall b a. (b -> a -> b) -> b -> Reference a -> b
forall a b. (a -> b -> b) -> b -> Reference a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Reference m -> m
fold :: forall m. Monoid m => Reference m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Reference a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Reference a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Reference a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Reference a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Reference a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Reference a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Reference a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Reference a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Reference a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Reference a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Reference a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Reference a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Reference a -> a
foldr1 :: forall a. (a -> a -> a) -> Reference a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Reference a -> a
foldl1 :: forall a. (a -> a -> a) -> Reference a -> a
$ctoList :: forall a. Reference a -> [a]
toList :: forall a. Reference a -> [a]
$cnull :: forall a. Reference a -> Bool
null :: forall a. Reference a -> Bool
$clength :: forall a. Reference a -> Int
length :: forall a. Reference a -> Int
$celem :: forall a. Eq a => a -> Reference a -> Bool
elem :: forall a. Eq a => a -> Reference a -> Bool
$cmaximum :: forall a. Ord a => Reference a -> a
maximum :: forall a. Ord a => Reference a -> a
$cminimum :: forall a. Ord a => Reference a -> a
minimum :: forall a. Ord a => Reference a -> a
$csum :: forall a. Num a => Reference a -> a
sum :: forall a. Num a => Reference a -> a
$cproduct :: forall a. Num a => Reference a -> a
product :: forall a. Num a => Reference a -> a
Foldable, Functor Reference
Foldable Reference
(Functor Reference, Foldable Reference) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Reference a -> f (Reference b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Reference (f a) -> f (Reference a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Reference a -> m (Reference b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Reference (m a) -> m (Reference a))
-> Traversable Reference
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Reference (m a) -> m (Reference a)
forall (f :: * -> *) a.
Applicative f =>
Reference (f a) -> f (Reference a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Reference a -> m (Reference b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Reference a -> f (Reference b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Reference a -> f (Reference b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Reference a -> f (Reference b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Reference (f a) -> f (Reference a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Reference (f a) -> f (Reference a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Reference a -> m (Reference b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Reference a -> m (Reference b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
Reference (m a) -> m (Reference a)
sequence :: forall (m :: * -> *) a.
Monad m =>
Reference (m a) -> m (Reference a)
Traversable)

instance ToJSON a => ToJSON (Reference a) where
  toJSON :: Reference a -> Value
toJSON Reference a
r = Map Variable (Val a) -> Value
forall a. ToJSON a => a -> Value
toJSON (Map Variable (Val a) -> Value) -> Map Variable (Val a) -> Value
forall a b. (a -> b) -> a -> b
$
               Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
"id" (Text -> Val a
forall a. Text -> Val a
TextVal (Text -> Val a) -> Text -> Val a
forall a b. (a -> b) -> a -> b
$ ItemId -> Text
forall a b. Coercible a b => a -> b
coerce (Reference a -> ItemId
forall a. Reference a -> ItemId
referenceId Reference a
r)) (Map Variable (Val a) -> Map Variable (Val a))
-> Map Variable (Val a) -> Map Variable (Val a)
forall a b. (a -> b) -> a -> b
$
               Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
"type" (Text -> Val a
forall a. Text -> Val a
TextVal (Text -> Val a) -> Text -> Val a
forall a b. (a -> b) -> a -> b
$ Reference a -> Text
forall a. Reference a -> Text
referenceType Reference a
r) (Map Variable (Val a) -> Map Variable (Val a))
-> Map Variable (Val a) -> Map Variable (Val a)
forall a b. (a -> b) -> a -> b
$
               Reference a -> Map Variable (Val a)
forall a. Reference a -> Map Variable (Val a)
referenceVariables Reference a
r

data DisambiguationData =
  DisambiguationData
  { DisambiguationData -> Maybe Int
disambYearSuffix  :: Maybe Int
  , DisambiguationData -> Map Name NameHints
disambNameMap     :: M.Map Name NameHints
  , DisambiguationData -> Maybe Int
disambEtAlNames   :: Maybe Int
  , DisambiguationData -> Bool
disambCondition   :: Bool
  } deriving (Int -> DisambiguationData -> ShowS
[DisambiguationData] -> ShowS
DisambiguationData -> String
(Int -> DisambiguationData -> ShowS)
-> (DisambiguationData -> String)
-> ([DisambiguationData] -> ShowS)
-> Show DisambiguationData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DisambiguationData -> ShowS
showsPrec :: Int -> DisambiguationData -> ShowS
$cshow :: DisambiguationData -> String
show :: DisambiguationData -> String
$cshowList :: [DisambiguationData] -> ShowS
showList :: [DisambiguationData] -> ShowS
Show, Eq DisambiguationData
Eq DisambiguationData =>
(DisambiguationData -> DisambiguationData -> Ordering)
-> (DisambiguationData -> DisambiguationData -> Bool)
-> (DisambiguationData -> DisambiguationData -> Bool)
-> (DisambiguationData -> DisambiguationData -> Bool)
-> (DisambiguationData -> DisambiguationData -> Bool)
-> (DisambiguationData -> DisambiguationData -> DisambiguationData)
-> (DisambiguationData -> DisambiguationData -> DisambiguationData)
-> Ord DisambiguationData
DisambiguationData -> DisambiguationData -> Bool
DisambiguationData -> DisambiguationData -> Ordering
DisambiguationData -> DisambiguationData -> DisambiguationData
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DisambiguationData -> DisambiguationData -> Ordering
compare :: DisambiguationData -> DisambiguationData -> Ordering
$c< :: DisambiguationData -> DisambiguationData -> Bool
< :: DisambiguationData -> DisambiguationData -> Bool
$c<= :: DisambiguationData -> DisambiguationData -> Bool
<= :: DisambiguationData -> DisambiguationData -> Bool
$c> :: DisambiguationData -> DisambiguationData -> Bool
> :: DisambiguationData -> DisambiguationData -> Bool
$c>= :: DisambiguationData -> DisambiguationData -> Bool
>= :: DisambiguationData -> DisambiguationData -> Bool
$cmax :: DisambiguationData -> DisambiguationData -> DisambiguationData
max :: DisambiguationData -> DisambiguationData -> DisambiguationData
$cmin :: DisambiguationData -> DisambiguationData -> DisambiguationData
min :: DisambiguationData -> DisambiguationData -> DisambiguationData
Ord, DisambiguationData -> DisambiguationData -> Bool
(DisambiguationData -> DisambiguationData -> Bool)
-> (DisambiguationData -> DisambiguationData -> Bool)
-> Eq DisambiguationData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DisambiguationData -> DisambiguationData -> Bool
== :: DisambiguationData -> DisambiguationData -> Bool
$c/= :: DisambiguationData -> DisambiguationData -> Bool
/= :: DisambiguationData -> DisambiguationData -> Bool
Eq)

data NameHints =
    AddInitials
  | AddGivenName
  | AddInitialsIfPrimary
  | AddGivenNameIfPrimary
  deriving (Int -> NameHints -> ShowS
[NameHints] -> ShowS
NameHints -> String
(Int -> NameHints -> ShowS)
-> (NameHints -> String)
-> ([NameHints] -> ShowS)
-> Show NameHints
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NameHints -> ShowS
showsPrec :: Int -> NameHints -> ShowS
$cshow :: NameHints -> String
show :: NameHints -> String
$cshowList :: [NameHints] -> ShowS
showList :: [NameHints] -> ShowS
Show, Eq NameHints
Eq NameHints =>
(NameHints -> NameHints -> Ordering)
-> (NameHints -> NameHints -> Bool)
-> (NameHints -> NameHints -> Bool)
-> (NameHints -> NameHints -> Bool)
-> (NameHints -> NameHints -> Bool)
-> (NameHints -> NameHints -> NameHints)
-> (NameHints -> NameHints -> NameHints)
-> Ord NameHints
NameHints -> NameHints -> Bool
NameHints -> NameHints -> Ordering
NameHints -> NameHints -> NameHints
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NameHints -> NameHints -> Ordering
compare :: NameHints -> NameHints -> Ordering
$c< :: NameHints -> NameHints -> Bool
< :: NameHints -> NameHints -> Bool
$c<= :: NameHints -> NameHints -> Bool
<= :: NameHints -> NameHints -> Bool
$c> :: NameHints -> NameHints -> Bool
> :: NameHints -> NameHints -> Bool
$c>= :: NameHints -> NameHints -> Bool
>= :: NameHints -> NameHints -> Bool
$cmax :: NameHints -> NameHints -> NameHints
max :: NameHints -> NameHints -> NameHints
$cmin :: NameHints -> NameHints -> NameHints
min :: NameHints -> NameHints -> NameHints
Ord, NameHints -> NameHints -> Bool
(NameHints -> NameHints -> Bool)
-> (NameHints -> NameHints -> Bool) -> Eq NameHints
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NameHints -> NameHints -> Bool
== :: NameHints -> NameHints -> Bool
$c/= :: NameHints -> NameHints -> Bool
/= :: NameHints -> NameHints -> Bool
Eq)

instance (Eq a, FromJSON a)  => FromJSON (Reference a) where
  parseJSON :: Value -> Parser (Reference a)
parseJSON Value
v = Value -> Parser (Map Variable Value)
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v Parser (Map Variable Value)
-> (Map Variable Value -> Parser (Reference a))
-> Parser (Reference a)
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Map Variable Value -> Parser (Reference a)
forall a. FromJSON a => Map Variable Value -> Parser (Reference a)
parseReference

lookupVariable :: CiteprocOutput a => Variable -> Reference a -> Maybe (Val a)
lookupVariable :: forall a.
CiteprocOutput a =>
Variable -> Reference a -> Maybe (Val a)
lookupVariable Variable
"id" Reference a
r =
  case Reference a -> ItemId
forall a. Reference a -> ItemId
referenceId Reference a
r of
    ItemId Text
"" -> Maybe (Val a)
forall a. Maybe a
Nothing
    ItemId Text
t  -> Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Text -> Val a
forall a. Text -> Val a
TextVal Text
t)
lookupVariable Variable
"type" Reference a
r =
  case Reference a -> Text
forall a. Reference a -> Text
referenceType Reference a
r of
    Text
"" -> Maybe (Val a)
forall a. Maybe a
Nothing
    Text
t  -> Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Text -> Val a
forall a. Text -> Val a
TextVal Text
t)
lookupVariable Variable
"page-first" Reference a
r =  -- compute "page-first" if not set
  Variable -> Map Variable (Val a) -> Maybe (Val a)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Variable
"page-first" (Reference a -> Map Variable (Val a)
forall a. Reference a -> Map Variable (Val a)
referenceVariables Reference a
r) Maybe (Val a) -> Maybe (Val a) -> Maybe (Val a)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    case Variable -> Map Variable (Val a) -> Maybe (Val a)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Variable
"pages" (Reference a -> Map Variable (Val a)
forall a. Reference a -> Map Variable (Val a)
referenceVariables Reference a
r) of
      Maybe (Val a)
Nothing           -> Maybe (Val a)
forall a. Maybe a
Nothing
      Just (NumVal Int
n)   -> Val a -> Maybe (Val a)
forall a. a -> Maybe a
Just (Int -> Val a
forall a. Int -> Val a
NumVal Int
n)
      Just (TextVal Text
t)  -> Int -> Val a
forall a. Int -> Val a
NumVal (Int -> Val a) -> Maybe Int -> Maybe (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe Int
forall a. Read a => String -> Maybe a
readMay (Text -> String
T.unpack (Text -> Text
takeDigits Text
t))
      Just (FancyVal a
x) -> Int -> Val a
forall a. Int -> Val a
NumVal (Int -> Val a) -> Maybe Int -> Maybe (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe Int
forall a. Read a => String -> Maybe a
readMay (Text -> String
T.unpack
                                           (Text -> Text
takeDigits (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x))
      Maybe (Val a)
_                 -> Maybe (Val a)
forall a. Maybe a
Nothing
 where
  takeDigits :: Text -> Text
takeDigits = (Char -> Bool) -> Text -> Text
T.takeWhile Char -> Bool
isDigit
lookupVariable Variable
v Reference a
r = Variable -> Map Variable (Val a) -> Maybe (Val a)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Variable
v (Map Variable (Val a) -> Maybe (Val a))
-> Map Variable (Val a) -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ Reference a -> Map Variable (Val a)
forall a. Reference a -> Map Variable (Val a)
referenceVariables Reference a
r

parseReference :: FromJSON a
               => M.Map Variable Value -> Parser (Reference a)
parseReference :: forall a. FromJSON a => Map Variable Value -> Parser (Reference a)
parseReference Map Variable Value
rawmap =
  (Reference a -> (Variable, Value) -> Parser (Reference a))
-> Reference a -> [(Variable, Value)] -> Parser (Reference a)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM Reference a -> (Variable, Value) -> Parser (Reference a)
forall {a}.
FromJSON a =>
Reference a -> (Variable, Value) -> Parser (Reference a)
go (ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
forall a. Monoid a => a
mempty Text
forall a. Monoid a => a
mempty Maybe DisambiguationData
forall a. Maybe a
Nothing Map Variable (Val a)
forall a. Monoid a => a
mempty) (Map Variable Value -> [(Variable, Value)]
forall k a. Map k a -> [(k, a)]
M.toList Map Variable Value
rawmap)
 where
  go :: Reference a -> (Variable, Value) -> Parser (Reference a)
go (Reference ItemId
i Text
t Maybe DisambiguationData
d Map Variable (Val a)
m) (Variable
k, Value
v)
    | Variable
k Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
"id"   = do
        ItemId
id' <- Text -> ItemId
ItemId (Text -> ItemId) -> Parser Text -> Parser ItemId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
readString Value
v
        Reference a -> Parser (Reference a)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Reference a -> Parser (Reference a))
-> Reference a -> Parser (Reference a)
forall a b. (a -> b) -> a -> b
$ ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
id' Text
t Maybe DisambiguationData
d Map Variable (Val a)
m
    | Variable
k Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
"type" = do
        Text
type' <- Value -> Parser Text
readString Value
v
        Reference a -> Parser (Reference a)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Reference a -> Parser (Reference a))
-> Reference a -> Parser (Reference a)
forall a b. (a -> b) -> a -> b
$ ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
i Text
type' Maybe DisambiguationData
d Map Variable (Val a)
m
    | Variable
k Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
"journalAbbreviation" Bool -> Bool -> Bool
|| Variable
k Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
"shortTitle" = -- legacy citeproc-js
      Reference a -> (Variable, Value) -> Parser (Reference a)
go (ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
i Text
t Maybe DisambiguationData
d Map Variable (Val a)
m) (Variable
"container-title-short", Value
v)
    | Variable
k Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
"note" = do
        Text
t' <- Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
        let ([(Variable, Text)]
kvs, Text
rest) = Text -> ([(Variable, Text)], Text)
parseNote Text
t'
         in (if Text -> Bool
T.null Text
rest
                then Reference a -> Reference a
forall a. a -> a
id
                else \(Reference ItemId
i' Text
t'' Maybe DisambiguationData
d' Map Variable (Val a)
m') ->
                       ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
i' Text
t'' Maybe DisambiguationData
d' (Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
"note" (Text -> Val a
forall a. Text -> Val a
TextVal Text
rest) Map Variable (Val a)
m'))
             (Reference a -> Reference a)
-> Parser (Reference a) -> Parser (Reference a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reference a -> (Variable, Value) -> Parser (Reference a))
-> Reference a -> [(Variable, Value)] -> Parser (Reference a)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM Reference a -> (Variable, Value) -> Parser (Reference a)
go (ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
i Text
t Maybe DisambiguationData
d Map Variable (Val a)
m) ([(Variable, Text)] -> [(Variable, Value)]
consolidateNameVariables [(Variable, Text)]
kvs)
    | Bool
otherwise   = ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
forall a.
ItemId
-> Text
-> Maybe DisambiguationData
-> Map Variable (Val a)
-> Reference a
Reference ItemId
i Text
t Maybe DisambiguationData
d (Map Variable (Val a) -> Reference a)
-> Parser (Map Variable (Val a)) -> Parser (Reference a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        case Variable -> VariableType
variableType Variable
k of
          VariableType
StringVariable -> do
            Val a
v' <- a -> Val a
forall a. a -> Val a
FancyVal (a -> Val a) -> Parser a -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v Parser (Val a) -> Parser (Val a) -> Parser (Val a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Val a
forall a. Text -> Val a
TextVal (Text -> Val a) -> Parser Text -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
readString Value
v
            Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Map Variable (Val a) -> Parser (Map Variable (Val a)))
-> Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a b. (a -> b) -> a -> b
$ Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k Val a
v' Map Variable (Val a)
m
          VariableType
NumberVariable -> do
            Text
v' <- case Value
v of
                    String{} -> Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
                    Number{} -> String -> Text
T.pack (String -> Text) -> (Int -> String) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Text) -> Parser Int -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> Parser Int
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v :: Parser Int)
                    Value
_        -> String -> Value -> Parser Text
forall a. String -> Value -> Parser a
typeMismatch String
"String or Number" Value
v
            Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Map Variable (Val a) -> Parser (Map Variable (Val a)))
-> Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a b. (a -> b) -> a -> b
$ Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k (Text -> Val a
forall a. Text -> Val a
TextVal Text
v') Map Variable (Val a)
m
          VariableType
DateVariable -> do
            Date
v' <- Value -> Parser Date
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
            Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Map Variable (Val a) -> Parser (Map Variable (Val a)))
-> Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a b. (a -> b) -> a -> b
$ Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k (Date -> Val a
forall a. Date -> Val a
DateVal Date
v') Map Variable (Val a)
m
          VariableType
NameVariable -> do
            [Name]
v' <- Value -> Parser [Name]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
            Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Map Variable (Val a) -> Parser (Map Variable (Val a)))
-> Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a b. (a -> b) -> a -> b
$ Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k ([Name] -> Val a
forall a. [Name] -> Val a
NamesVal [Name]
v') Map Variable (Val a)
m
          VariableType
UnknownVariable -> -- treat as string variable if possible
            case Value
v of
              String{}  -> (\Val a
x -> Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k Val a
x Map Variable (Val a)
m) (Val a -> Map Variable (Val a))
-> Parser (Val a) -> Parser (Map Variable (Val a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                    (a -> Val a
forall a. a -> Val a
FancyVal (a -> Val a) -> Parser a -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v Parser (Val a) -> Parser (Val a) -> Parser (Val a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Val a
forall a. Text -> Val a
TextVal (Text -> Val a) -> Parser Text -> Parser (Val a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
readString Value
v)
              Number{}  -> (\Text
x -> Variable -> Val a -> Map Variable (Val a) -> Map Variable (Val a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Variable
k (Text -> Val a
forall a. Text -> Val a
TextVal Text
x) Map Variable (Val a)
m) (Text -> Map Variable (Val a))
-> Parser Text -> Parser (Map Variable (Val a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Text
readString Value
v
              Value
_         -> Map Variable (Val a) -> Parser (Map Variable (Val a))
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Map Variable (Val a)
m -- silently ignore
  readString :: Value -> Parser Text
readString Value
v =
    case Value
v of
       String{} -> Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
       Number{} -> String -> Text
T.pack (String -> Text) -> (Int -> String) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> Text) -> Parser Int -> Parser Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> Parser Int
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v :: Parser Int)
       Value
_        -> String -> Value -> Parser Text
forall a. String -> Value -> Parser a
typeMismatch String
"String or Number" Value
v

-- name variables are cumulative and should be packed into an array
consolidateNameVariables :: [(Variable, Text)] -> [(Variable, Value)]
consolidateNameVariables :: [(Variable, Text)] -> [(Variable, Value)]
consolidateNameVariables [] = []
consolidateNameVariables ((Variable
k,Text
v):[(Variable, Text)]
kvs)
  = case Variable -> VariableType
variableType Variable
k of
      VariableType
NameVariable
        -> (Variable
k, Array -> Value
Array
                 ([Value] -> Array
forall a. [a] -> Vector a
V.fromList [Text -> Value
String Text
t | (Variable
k',Text
t) <- (Variable
k,Text
v)(Variable, Text) -> [(Variable, Text)] -> [(Variable, Text)]
forall a. a -> [a] -> [a]
:[(Variable, Text)]
kvs, Variable
k' Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
== Variable
k])) (Variable, Value) -> [(Variable, Value)] -> [(Variable, Value)]
forall a. a -> [a] -> [a]
:
            [(Variable, Text)] -> [(Variable, Value)]
consolidateNameVariables (((Variable, Text) -> Bool)
-> [(Variable, Text)] -> [(Variable, Text)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Variable -> Variable -> Bool
forall a. Eq a => a -> a -> Bool
/= Variable
k) (Variable -> Bool)
-> ((Variable, Text) -> Variable) -> (Variable, Text) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Variable, Text) -> Variable
forall a b. (a, b) -> a
fst) [(Variable, Text)]
kvs)
      VariableType
_ -> (Variable
k, Text -> Value
String Text
v) (Variable, Value) -> [(Variable, Value)] -> [(Variable, Value)]
forall a. a -> [a] -> [a]
: [(Variable, Text)] -> [(Variable, Value)]
consolidateNameVariables [(Variable, Text)]
kvs

parseNote :: Text
          -> ([(Variable, Text)], Text)
parseNote :: Text -> ([(Variable, Text)], Text)
parseNote Text
t =
  (String -> ([(Variable, Text)], Text))
-> (([(Variable, Text)], Text) -> ([(Variable, Text)], Text))
-> Either String ([(Variable, Text)], Text)
-> ([(Variable, Text)], Text)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (([(Variable, Text)], Text) -> String -> ([(Variable, Text)], Text)
forall a b. a -> b -> a
const ([],Text
t)) ([(Variable, Text)], Text) -> ([(Variable, Text)], Text)
forall a. a -> a
id (Either String ([(Variable, Text)], Text)
 -> ([(Variable, Text)], Text))
-> Either String ([(Variable, Text)], Text)
-> ([(Variable, Text)], Text)
forall a b. (a -> b) -> a -> b
$
    Parser ([(Variable, Text)], Text)
-> Text -> Either String ([(Variable, Text)], Text)
forall a. Parser a -> Text -> Either String a
P.parseOnly ((,) ([(Variable, Text)] -> Text -> ([(Variable, Text)], Text))
-> Parser Text [(Variable, Text)]
-> Parser Text (Text -> ([(Variable, Text)], Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text (Variable, Text) -> Parser Text [(Variable, Text)]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
P.many' Parser Text (Variable, Text)
pNoteField Parser Text (Text -> ([(Variable, Text)], Text))
-> Parser Text Text -> Parser ([(Variable, Text)], Text)
forall a b. Parser Text (a -> b) -> Parser Text a -> Parser Text b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Text Text
P.takeText) Text
t
 where
  pNoteField :: Parser Text (Variable, Text)
pNoteField = Parser Text (Variable, Text)
pBracedField Parser Text (Variable, Text)
-> Parser Text (Variable, Text) -> Parser Text (Variable, Text)
forall a. Parser Text a -> Parser Text a -> Parser Text a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Text (Variable, Text)
pLineField
  pLineField :: Parser Text (Variable, Text)
pLineField = do
    Text
name <- Parser Text Text
pVarname
    Char
_ <- Char -> Parser Char
P.char Char
':'
    Text
val <- (Char -> Bool) -> Parser Text Text
P.takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'\n')
    () () -> Parser Char -> Parser Text ()
forall a b. a -> Parser Text b -> Parser Text a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser Char
P.char Char
'\n' Parser Text () -> Parser Text () -> Parser Text ()
forall a. Parser Text a -> Parser Text a -> Parser Text a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Text ()
forall t. Chunk t => Parser t ()
P.endOfInput
    (Variable, Text) -> Parser Text (Variable, Text)
forall a. a -> Parser Text a
forall (m :: * -> *) a. Monad m => a -> m a
return (CI Text -> Variable
Variable (CI Text -> Variable) -> CI Text -> Variable
forall a b. (a -> b) -> a -> b
$ Text -> CI Text
forall s. FoldCase s => s -> CI s
CI.mk Text
name, Text -> Text
T.strip Text
val)
  pBracedField :: Parser Text (Variable, Text)
pBracedField = do
    Text
_ <- Text -> Parser Text Text
P.string Text
"{:"
    Text
name <- Parser Text Text
pVarname
    Char
_ <- Char -> Parser Char
P.char Char
':'
    Text
val <- (Char -> Bool) -> Parser Text Text
P.takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'}')
    Char
_ <- Char -> Parser Char
P.char Char
'}'
    (Variable, Text) -> Parser Text (Variable, Text)
forall a. a -> Parser Text a
forall (m :: * -> *) a. Monad m => a -> m a
return (CI Text -> Variable
Variable (CI Text -> Variable) -> CI Text -> Variable
forall a b. (a -> b) -> a -> b
$ Text -> CI Text
forall s. FoldCase s => s -> CI s
CI.mk Text
name, Text -> Text
T.strip Text
val)
  pVarname :: Parser Text Text
pVarname = (Char -> Bool) -> Parser Text Text
P.takeWhile1 (\Char
c -> Char -> Bool
isLetter Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-')

data VariableType =
    DateVariable
  | NameVariable
  | NumberVariable
  | StringVariable
  | UnknownVariable
  deriving (Int -> VariableType -> ShowS
[VariableType] -> ShowS
VariableType -> String
(Int -> VariableType -> ShowS)
-> (VariableType -> String)
-> ([VariableType] -> ShowS)
-> Show VariableType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VariableType -> ShowS
showsPrec :: Int -> VariableType -> ShowS
$cshow :: VariableType -> String
show :: VariableType -> String
$cshowList :: [VariableType] -> ShowS
showList :: [VariableType] -> ShowS
Show, VariableType -> VariableType -> Bool
(VariableType -> VariableType -> Bool)
-> (VariableType -> VariableType -> Bool) -> Eq VariableType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VariableType -> VariableType -> Bool
== :: VariableType -> VariableType -> Bool
$c/= :: VariableType -> VariableType -> Bool
/= :: VariableType -> VariableType -> Bool
Eq)

variableType :: Variable -> VariableType
variableType :: Variable -> VariableType
variableType Variable
"accessed" = VariableType
DateVariable
variableType Variable
"available-date" = VariableType
DateVariable
variableType Variable
"container" = VariableType
DateVariable
variableType Variable
"event-date" = VariableType
DateVariable
variableType Variable
"issued" = VariableType
DateVariable
variableType Variable
"original-date" = VariableType
DateVariable
variableType Variable
"submitted" = VariableType
DateVariable
variableType Variable
"author" = VariableType
NameVariable
variableType Variable
"chair" = VariableType
NameVariable
variableType Variable
"collection-editor" = VariableType
NameVariable
variableType Variable
"composer" = VariableType
NameVariable
variableType Variable
"compiler" = VariableType
NameVariable
variableType Variable
"container-author" = VariableType
NameVariable
variableType Variable
"contributor" = VariableType
NameVariable
variableType Variable
"curator" = VariableType
NameVariable
variableType Variable
"director" = VariableType
NameVariable
variableType Variable
"editor" = VariableType
NameVariable
variableType Variable
"editor-translator" = VariableType
NameVariable
variableType Variable
"editorial-director" = VariableType
NameVariable
variableType Variable
"executive-producer" = VariableType
NameVariable
variableType Variable
"guest" = VariableType
NameVariable
variableType Variable
"host" = VariableType
NameVariable
variableType Variable
"illustrator" = VariableType
NameVariable
variableType Variable
"interviewer" = VariableType
NameVariable
variableType Variable
"narrator" = VariableType
NameVariable
variableType Variable
"original-author" = VariableType
NameVariable
variableType Variable
"organizer" = VariableType
NameVariable
variableType Variable
"performer" = VariableType
NameVariable
variableType Variable
"producer" = VariableType
NameVariable
variableType Variable
"recipient" = VariableType
NameVariable
variableType Variable
"reviewed-author" = VariableType
NameVariable
variableType Variable
"script-writer" = VariableType
NameVariable
variableType Variable
"series-creator" = VariableType
NameVariable
variableType Variable
"translator" = VariableType
NameVariable
variableType Variable
"chapter-number" = VariableType
NumberVariable
variableType Variable
"citation-number" = VariableType
NumberVariable
variableType Variable
"collection-number" = VariableType
NumberVariable
variableType Variable
"edition" = VariableType
NumberVariable
variableType Variable
"first-reference-note-number" = VariableType
NumberVariable
variableType Variable
"issue" = VariableType
NumberVariable
variableType Variable
"locator" = VariableType
NumberVariable
variableType Variable
"number" = VariableType
NumberVariable
variableType Variable
"number-of-pages" = VariableType
NumberVariable
variableType Variable
"number-of-volumes" = VariableType
NumberVariable
variableType Variable
"page" = VariableType
NumberVariable
variableType Variable
"page-first" = VariableType
NumberVariable
variableType Variable
"part-number" = VariableType
NumberVariable
variableType Variable
"printing-number" = VariableType
NumberVariable
variableType Variable
"section" = VariableType
NumberVariable
variableType Variable
"supplement-number" = VariableType
NumberVariable
variableType Variable
"version" = VariableType
NumberVariable
variableType Variable
"volume" = VariableType
NumberVariable
variableType Variable
"abstract" = VariableType
StringVariable
variableType Variable
"annote" = VariableType
StringVariable
variableType Variable
"archive" = VariableType
StringVariable
variableType Variable
"archive_collection"  = VariableType
StringVariable
variableType Variable
"archive_location" = VariableType
StringVariable
variableType Variable
"archive-place" = VariableType
StringVariable
variableType Variable
"authority" = VariableType
StringVariable
variableType Variable
"call-number" = VariableType
StringVariable
variableType Variable
"citation-key" = VariableType
StringVariable
variableType Variable
"citation-label" = VariableType
StringVariable
variableType Variable
"collection-title" = VariableType
StringVariable
variableType Variable
"container-title" = VariableType
StringVariable
variableType Variable
"container-title-short" = VariableType
StringVariable
variableType Variable
"dimensions" = VariableType
StringVariable
variableType Variable
"division" = VariableType
StringVariable
variableType Variable
"DOI" = VariableType
StringVariable
variableType Variable
"event" = VariableType
StringVariable
variableType Variable
"event-place" = VariableType
StringVariable
variableType Variable
"event-title" = VariableType
StringVariable --(new name for "event" to avoid confusion with new "event" type) 
variableType Variable
"genre" = VariableType
StringVariable
variableType Variable
"ISBN" = VariableType
StringVariable
variableType Variable
"ISSN" = VariableType
StringVariable
variableType Variable
"jurisdiction" = VariableType
StringVariable
variableType Variable
"keyword" = VariableType
StringVariable
variableType Variable
"language" = VariableType
StringVariable
variableType Variable
"license" = VariableType
StringVariable
variableType Variable
"medium" = VariableType
StringVariable
variableType Variable
"note" = VariableType
StringVariable
variableType Variable
"original-publisher" = VariableType
StringVariable
variableType Variable
"original-publisher-place" = VariableType
StringVariable
variableType Variable
"original-title" = VariableType
StringVariable
variableType Variable
"part-title" = VariableType
StringVariable
variableType Variable
"PMID" = VariableType
StringVariable
variableType Variable
"PMCID" = VariableType
StringVariable
variableType Variable
"publisher" = VariableType
StringVariable
variableType Variable
"publisher-place" = VariableType
StringVariable
variableType Variable
"references" = VariableType
StringVariable
variableType Variable
"reviewed-genre" = VariableType
StringVariable
variableType Variable
"reviewed-title" = VariableType
StringVariable
variableType Variable
"scale" = VariableType
StringVariable
variableType Variable
"source" = VariableType
StringVariable
variableType Variable
"status" = VariableType
StringVariable
variableType Variable
"title" = VariableType
StringVariable
variableType Variable
"title-short" = VariableType
StringVariable
variableType Variable
"URL" = VariableType
StringVariable
variableType Variable
"volume-title" = VariableType
StringVariable
variableType Variable
"year-suffix" = VariableType
StringVariable
variableType Variable
_ = VariableType
UnknownVariable

newtype (ReferenceMap a) =
  ReferenceMap { forall a. ReferenceMap a -> Map ItemId (Reference a)
unReferenceMap :: M.Map ItemId (Reference a) }
  deriving (Int -> ReferenceMap a -> ShowS
[ReferenceMap a] -> ShowS
ReferenceMap a -> String
(Int -> ReferenceMap a -> ShowS)
-> (ReferenceMap a -> String)
-> ([ReferenceMap a] -> ShowS)
-> Show (ReferenceMap a)
forall a. Show a => Int -> ReferenceMap a -> ShowS
forall a. Show a => [ReferenceMap a] -> ShowS
forall a. Show a => ReferenceMap a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ReferenceMap a -> ShowS
showsPrec :: Int -> ReferenceMap a -> ShowS
$cshow :: forall a. Show a => ReferenceMap a -> String
show :: ReferenceMap a -> String
$cshowList :: forall a. Show a => [ReferenceMap a] -> ShowS
showList :: [ReferenceMap a] -> ShowS
Show)

-- | Returns a pair consisting of the cleaned up list of
-- references and a reference map.  If the original reference
-- list contains items with the same id, then the one that
-- occurs last in the list is retained, and the others are
-- omittedfrom the cleaned-up list.
makeReferenceMap :: [Reference a] -> ([Reference a], ReferenceMap a)
makeReferenceMap :: forall a. [Reference a] -> ([Reference a], ReferenceMap a)
makeReferenceMap = (Set ItemId, ([Reference a], ReferenceMap a))
-> ([Reference a], ReferenceMap a)
forall a b. (a, b) -> b
snd ((Set ItemId, ([Reference a], ReferenceMap a))
 -> ([Reference a], ReferenceMap a))
-> ([Reference a] -> (Set ItemId, ([Reference a], ReferenceMap a)))
-> [Reference a]
-> ([Reference a], ReferenceMap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Reference a
 -> (Set ItemId, ([Reference a], ReferenceMap a))
 -> (Set ItemId, ([Reference a], ReferenceMap a)))
-> (Set ItemId, ([Reference a], ReferenceMap a))
-> [Reference a]
-> (Set ItemId, ([Reference a], ReferenceMap a))
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Reference a
-> (Set ItemId, ([Reference a], ReferenceMap a))
-> (Set ItemId, ([Reference a], ReferenceMap a))
forall {a}.
Reference a
-> (Set ItemId, ([Reference a], ReferenceMap a))
-> (Set ItemId, ([Reference a], ReferenceMap a))
go (Set ItemId
forall a. Monoid a => a
mempty, ([], Map ItemId (Reference a) -> ReferenceMap a
forall a. Map ItemId (Reference a) -> ReferenceMap a
ReferenceMap Map ItemId (Reference a)
forall a. Monoid a => a
mempty))
  where
   go :: Reference a
-> (Set ItemId, ([Reference a], ReferenceMap a))
-> (Set ItemId, ([Reference a], ReferenceMap a))
go Reference a
ref (Set ItemId
ids, ([Reference a]
rs, ReferenceMap Map ItemId (Reference a)
refmap)) =
     let rid :: ItemId
rid = Reference a -> ItemId
forall a. Reference a -> ItemId
referenceId Reference a
ref
      in if ItemId -> Set ItemId -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member ItemId
rid Set ItemId
ids
            then (Set ItemId
ids, ([Reference a]
rs, Map ItemId (Reference a) -> ReferenceMap a
forall a. Map ItemId (Reference a) -> ReferenceMap a
ReferenceMap Map ItemId (Reference a)
refmap))
            else (ItemId -> Set ItemId -> Set ItemId
forall a. Ord a => a -> Set a -> Set a
Set.insert ItemId
rid Set ItemId
ids,
                   (Reference a
refReference a -> [Reference a] -> [Reference a]
forall a. a -> [a] -> [a]
:[Reference a]
rs, Map ItemId (Reference a) -> ReferenceMap a
forall a. Map ItemId (Reference a) -> ReferenceMap a
ReferenceMap (ItemId
-> Reference a
-> Map ItemId (Reference a)
-> Map ItemId (Reference a)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert ItemId
rid Reference a
ref Map ItemId (Reference a)
refmap)))

lookupReference :: ItemId -> ReferenceMap a -> Maybe (Reference a)
lookupReference :: forall a. ItemId -> ReferenceMap a -> Maybe (Reference a)
lookupReference ItemId
ident (ReferenceMap Map ItemId (Reference a)
m) = ItemId -> Map ItemId (Reference a) -> Maybe (Reference a)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup ItemId
ident Map ItemId (Reference a)
m

-- | Value associated with a certain variable in a bibliographic
-- entry.
data Val a =
    TextVal Text      -- ^ Plain text value
  | FancyVal a        -- ^ Formatted value with parameterized type
  | NumVal  Int       -- ^ Numerical value
  | NamesVal [Name]   -- ^ Structured names
  | DateVal Date      -- ^ Structured date
  | SubstitutedVal    -- ^ Value suppressed through substitution
  deriving (Int -> Val a -> ShowS
[Val a] -> ShowS
Val a -> String
(Int -> Val a -> ShowS)
-> (Val a -> String) -> ([Val a] -> ShowS) -> Show (Val a)
forall a. Show a => Int -> Val a -> ShowS
forall a. Show a => [Val a] -> ShowS
forall a. Show a => Val a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Val a -> ShowS
showsPrec :: Int -> Val a -> ShowS
$cshow :: forall a. Show a => Val a -> String
show :: Val a -> String
$cshowList :: forall a. Show a => [Val a] -> ShowS
showList :: [Val a] -> ShowS
Show, Eq (Val a)
Eq (Val a) =>
(Val a -> Val a -> Ordering)
-> (Val a -> Val a -> Bool)
-> (Val a -> Val a -> Bool)
-> (Val a -> Val a -> Bool)
-> (Val a -> Val a -> Bool)
-> (Val a -> Val a -> Val a)
-> (Val a -> Val a -> Val a)
-> Ord (Val a)
Val a -> Val a -> Bool
Val a -> Val a -> Ordering
Val a -> Val a -> Val a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Val a)
forall a. Ord a => Val a -> Val a -> Bool
forall a. Ord a => Val a -> Val a -> Ordering
forall a. Ord a => Val a -> Val a -> Val a
$ccompare :: forall a. Ord a => Val a -> Val a -> Ordering
compare :: Val a -> Val a -> Ordering
$c< :: forall a. Ord a => Val a -> Val a -> Bool
< :: Val a -> Val a -> Bool
$c<= :: forall a. Ord a => Val a -> Val a -> Bool
<= :: Val a -> Val a -> Bool
$c> :: forall a. Ord a => Val a -> Val a -> Bool
> :: Val a -> Val a -> Bool
$c>= :: forall a. Ord a => Val a -> Val a -> Bool
>= :: Val a -> Val a -> Bool
$cmax :: forall a. Ord a => Val a -> Val a -> Val a
max :: Val a -> Val a -> Val a
$cmin :: forall a. Ord a => Val a -> Val a -> Val a
min :: Val a -> Val a -> Val a
Ord, Val a -> Val a -> Bool
(Val a -> Val a -> Bool) -> (Val a -> Val a -> Bool) -> Eq (Val a)
forall a. Eq a => Val a -> Val a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Val a -> Val a -> Bool
== :: Val a -> Val a -> Bool
$c/= :: forall a. Eq a => Val a -> Val a -> Bool
/= :: Val a -> Val a -> Bool
Eq, (forall a b. (a -> b) -> Val a -> Val b)
-> (forall a b. a -> Val b -> Val a) -> Functor Val
forall a b. a -> Val b -> Val a
forall a b. (a -> b) -> Val a -> Val b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Val a -> Val b
fmap :: forall a b. (a -> b) -> Val a -> Val b
$c<$ :: forall a b. a -> Val b -> Val a
<$ :: forall a b. a -> Val b -> Val a
Functor, (forall m. Monoid m => Val m -> m)
-> (forall m a. Monoid m => (a -> m) -> Val a -> m)
-> (forall m a. Monoid m => (a -> m) -> Val a -> m)
-> (forall a b. (a -> b -> b) -> b -> Val a -> b)
-> (forall a b. (a -> b -> b) -> b -> Val a -> b)
-> (forall b a. (b -> a -> b) -> b -> Val a -> b)
-> (forall b a. (b -> a -> b) -> b -> Val a -> b)
-> (forall a. (a -> a -> a) -> Val a -> a)
-> (forall a. (a -> a -> a) -> Val a -> a)
-> (forall a. Val a -> [a])
-> (forall a. Val a -> Bool)
-> (forall a. Val a -> Int)
-> (forall a. Eq a => a -> Val a -> Bool)
-> (forall a. Ord a => Val a -> a)
-> (forall a. Ord a => Val a -> a)
-> (forall a. Num a => Val a -> a)
-> (forall a. Num a => Val a -> a)
-> Foldable Val
forall a. Eq a => a -> Val a -> Bool
forall a. Num a => Val a -> a
forall a. Ord a => Val a -> a
forall m. Monoid m => Val m -> m
forall a. Val a -> Bool
forall a. Val a -> Int
forall a. Val a -> [a]
forall a. (a -> a -> a) -> Val a -> a
forall m a. Monoid m => (a -> m) -> Val a -> m
forall b a. (b -> a -> b) -> b -> Val a -> b
forall a b. (a -> b -> b) -> b -> Val a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Val m -> m
fold :: forall m. Monoid m => Val m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Val a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Val a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Val a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Val a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Val a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Val a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Val a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Val a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Val a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Val a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Val a -> a
foldr1 :: forall a. (a -> a -> a) -> Val a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Val a -> a
foldl1 :: forall a. (a -> a -> a) -> Val a -> a
$ctoList :: forall a. Val a -> [a]
toList :: forall a. Val a -> [a]
$cnull :: forall a. Val a -> Bool
null :: forall a. Val a -> Bool
$clength :: forall a. Val a -> Int
length :: forall a. Val a -> Int
$celem :: forall a. Eq a => a -> Val a -> Bool
elem :: forall a. Eq a => a -> Val a -> Bool
$cmaximum :: forall a. Ord a => Val a -> a
maximum :: forall a. Ord a => Val a -> a
$cminimum :: forall a. Ord a => Val a -> a
minimum :: forall a. Ord a => Val a -> a
$csum :: forall a. Num a => Val a -> a
sum :: forall a. Num a => Val a -> a
$cproduct :: forall a. Num a => Val a -> a
product :: forall a. Num a => Val a -> a
Foldable, Functor Val
Foldable Val
(Functor Val, Foldable Val) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Val a -> f (Val b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Val (f a) -> f (Val a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Val a -> m (Val b))
-> (forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a))
-> Traversable Val
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Val a -> f (Val b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Val (f a) -> f (Val a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Val a -> m (Val b)
$csequence :: forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
sequence :: forall (m :: * -> *) a. Monad m => Val (m a) -> m (Val a)
Traversable)

instance ToJSON a => ToJSON (Val a) where
  toJSON :: Val a -> Value
toJSON (TextVal Text
t) = Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
t
  toJSON (FancyVal a
x) = a -> Value
forall a. ToJSON a => a -> Value
toJSON a
x
  toJSON (NumVal Int
n) = Int -> Value
forall a. ToJSON a => a -> Value
toJSON Int
n
  toJSON (NamesVal [Name]
ns) = [Name] -> Value
forall a. ToJSON a => a -> Value
toJSON [Name]
ns
  toJSON (DateVal Date
d) = Date -> Value
forall a. ToJSON a => a -> Value
toJSON Date
d
  toJSON Val a
SubstitutedVal = () -> Value
forall a. ToJSON a => a -> Value
toJSON ()

valToText :: CiteprocOutput a => Val a -> Maybe Text
valToText :: forall a. CiteprocOutput a => Val a -> Maybe Text
valToText (TextVal Text
x)  = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
x
valToText (FancyVal a
x) = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x
valToText (NumVal Int
n)   = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show Int
n
valToText Val a
_            = Maybe Text
forall a. Maybe a
Nothing

data Name =
  Name
  { Name -> Maybe Text
nameFamily              :: Maybe Text
  , Name -> Maybe Text
nameGiven               :: Maybe Text
  , Name -> Maybe Text
nameDroppingParticle    :: Maybe Text
  , Name -> Maybe Text
nameNonDroppingParticle :: Maybe Text
  , Name -> Maybe Text
nameSuffix              :: Maybe Text
  , Name -> Bool
nameCommaSuffix         :: Bool
  , Name -> Bool
nameStaticOrdering      :: Bool
  , Name -> Maybe Text
nameLiteral             :: Maybe Text
  }
  deriving (Int -> Name -> ShowS
[Name] -> ShowS
Name -> String
(Int -> Name -> ShowS)
-> (Name -> String) -> ([Name] -> ShowS) -> Show Name
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Name -> ShowS
showsPrec :: Int -> Name -> ShowS
$cshow :: Name -> String
show :: Name -> String
$cshowList :: [Name] -> ShowS
showList :: [Name] -> ShowS
Show, Name -> Name -> Bool
(Name -> Name -> Bool) -> (Name -> Name -> Bool) -> Eq Name
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Name -> Name -> Bool
== :: Name -> Name -> Bool
$c/= :: Name -> Name -> Bool
/= :: Name -> Name -> Bool
Eq, Eq Name
Eq Name =>
(Name -> Name -> Ordering)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Bool)
-> (Name -> Name -> Name)
-> (Name -> Name -> Name)
-> Ord Name
Name -> Name -> Bool
Name -> Name -> Ordering
Name -> Name -> Name
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Name -> Name -> Ordering
compare :: Name -> Name -> Ordering
$c< :: Name -> Name -> Bool
< :: Name -> Name -> Bool
$c<= :: Name -> Name -> Bool
<= :: Name -> Name -> Bool
$c> :: Name -> Name -> Bool
> :: Name -> Name -> Bool
$c>= :: Name -> Name -> Bool
>= :: Name -> Name -> Bool
$cmax :: Name -> Name -> Name
max :: Name -> Name -> Name
$cmin :: Name -> Name -> Name
min :: Name -> Name -> Name
Ord)

instance ToJSON Name where
  toJSON :: Name -> Value
toJSON Name
n =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"family", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)) (Name -> Maybe Text
nameFamily Name
n) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"given", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)) (Name -> Maybe Text
nameGiven Name
n) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"dropping-particle", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:))
         (Name -> Maybe Text
nameDroppingParticle Name
n) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"non-dropping-particle", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:))
         (Name -> Maybe Text
nameNonDroppingParticle Name
n) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"suffix", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)) (Name -> Maybe Text
nameSuffix Name
n) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      (if Name -> Bool
nameCommaSuffix Name
n
          then ((Key
"comma-suffix", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON Bool
True)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)
          else [Pair] -> [Pair]
forall a. a -> a
id) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      (if Name -> Bool
nameStaticOrdering Name
n
          then ((Key
"static-ordering", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON Bool
True)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)
          else [Pair] -> [Pair]
forall a. a -> a
id) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      ([Pair] -> [Pair])
-> (Text -> [Pair] -> [Pair]) -> Maybe Text -> [Pair] -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Pair] -> [Pair]
forall a. a -> a
id (\Text
x -> ((Key
"literal", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)) (Name -> Maybe Text
nameLiteral Name
n) ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall a b. (a -> b) -> a -> b
$
      []

fixApos :: Text -> Text
fixApos :: Text -> Text
fixApos = (Char -> Char) -> Text -> Text
T.map Char -> Char
fixAposC
 where
  fixAposC :: Char -> Char
fixAposC Char
'\'' = Char
'\x2019'
  fixAposC Char
c    = Char
c

instance FromJSON Name where
  parseJSON :: Value -> Parser Name
parseJSON (String Text
t) = Text -> Parser Name
parseCheaterName Text
t
  parseJSON Value
x =
    Name -> Name
extractParticles (Name -> Name) -> Parser Name -> Parser Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
     (String -> (Object -> Parser Name) -> Value -> Parser Name
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Name" ((Object -> Parser Name) -> Value -> Parser Name)
-> (Object -> Parser Name) -> Value -> Parser Name
forall a b. (a -> b) -> a -> b
$ \Object
v -> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Bool
-> Bool
-> Maybe Text
-> Name
Name
      (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Bool
 -> Bool
 -> Maybe Text
 -> Name)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Bool
      -> Bool
      -> Maybe Text
      -> Name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"family")
      Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Bool
   -> Bool
   -> Maybe Text
   -> Name)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"given")
      Parser
  (Maybe Text
   -> Maybe Text -> Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"dropping-particle")
      Parser
  (Maybe Text -> Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"non-dropping-particle")
      Parser (Maybe Text -> Bool -> Bool -> Maybe Text -> Name)
-> Parser (Maybe Text)
-> Parser (Bool -> Bool -> Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"suffix")
      Parser (Bool -> Bool -> Maybe Text -> Name)
-> Parser Bool -> Parser (Bool -> Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comma-suffix" Parser (Maybe Value) -> (Maybe Value -> Parser Bool) -> Parser Bool
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Parser Bool -> (Value -> Parser Bool) -> Maybe Value -> Parser Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False) Value -> Parser Bool
asBool)
      Parser (Bool -> Maybe Text -> Name)
-> Parser Bool -> Parser (Maybe Text -> Name)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
v Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"static-ordering" Parser (Maybe Value) -> (Maybe Value -> Parser Bool) -> Parser Bool
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Parser Bool -> (Value -> Parser Bool) -> Maybe Value -> Parser Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False) Value -> Parser Bool
asBool)
      Parser (Maybe Text -> Name) -> Parser (Maybe Text) -> Parser Name
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Text -> Text) -> Maybe Text -> Maybe Text
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
fixApos (Maybe Text -> Maybe Text)
-> Parser (Maybe Text) -> Parser (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"literal")
     ) Value
x

-- "lowercase elements before the family name are treated as “non-dropping”
-- particles, and lowercase elements following the given name as “dropping”
-- particles"
extractParticles :: Name -> Name
extractParticles :: Name -> Name
extractParticles =
  Name -> Name
extractNonDroppingParticle (Name -> Name) -> (Name -> Name) -> Name -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Name
extractDroppingParticle (Name -> Name) -> (Name -> Name) -> Name -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Name
extractSuffix
 where
  extractSuffix :: Name -> Name
extractSuffix Name
name =
    case Name -> Maybe Text
nameSuffix Name
name of
      Maybe Text
Nothing ->
        case Name -> Maybe Text
nameGiven Name
name of
          Maybe Text
Nothing -> Name
name
          Just Text
t
            -- in CSL JSON you can put double quotes around something
            -- to make it a unit (not subject to splitting).
            | Text
"\"" Text -> Text -> Bool
`T.isPrefixOf` Text
t
            , Text
"\"" Text -> Text -> Bool
`T.isSuffixOf` Text
t
            -> Name
name { nameGiven = Just $ T.drop 1 $ T.dropEnd 1 t }
           | Bool
otherwise->
            let (Text
a,Text
b) = (Char -> Bool) -> Text -> (Text, Text)
T.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
',') Text
t
             in if Text -> Bool
T.null Text
a Bool -> Bool -> Bool
|| Text -> Bool
T.null Text
b
                   then Name
name
                   else
                     if Int -> Text -> Text
T.take Int
2 Text
b Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
",!"
                        then Name
name{ nameGiven  = Just a
                                 , nameSuffix = Just $ T.strip $ T.drop 2 b
                                 , nameCommaSuffix = True }
                        else Name
name{ nameGiven  = Just a
                                 , nameSuffix = Just $ T.strip $ T.drop 1 b }
      Just Text
_  -> Name
name
  extractNonDroppingParticle :: Name -> Name
extractNonDroppingParticle Name
name =
    case Name -> Maybe Text
nameNonDroppingParticle Name
name of
      Maybe Text
Nothing ->
        case Name -> Maybe Text
nameFamily Name
name of
          Maybe Text
Nothing -> Name
name
          Just Text
t
            | Text
"\"" Text -> Text -> Bool
`T.isPrefixOf` Text
t
            , Text
"\"" Text -> Text -> Bool
`T.isSuffixOf` Text
t
              -> Name
name { nameFamily = Just $ T.drop 1 $ T.dropEnd 1 t }
            | Bool
otherwise ->
              case (Text -> Bool) -> [Text] -> ([Text], [Text])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isParticleChar) (Text -> [Text]
T.words Text
t) of
                ([],[Text]
_)
                    -> case (Char -> Bool) -> Text -> [Text]
T.split Char -> Bool
isParticlePunct Text
t of
                         [Text
x,Text
y] | (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isParticleChar Text
x ->
                              Name
name{ nameFamily = Just y
                                  , nameNonDroppingParticle = Just $ x <>
                                      T.take 1
                                      (T.dropWhile (not . isParticlePunct) t) }
                         [Text]
_ -> Name
name
                ([Text]
_,[])  -> Name
name
                ([Text]
as,[Text]
bs) -> Name
name{ nameFamily = Just (T.unwords bs)
                               , nameNonDroppingParticle = Just (T.unwords as) }
      Just Text
_  -> Name
name
  extractDroppingParticle :: Name -> Name
extractDroppingParticle Name
name =
    case Name -> Maybe Text
nameDroppingParticle Name
name of
      Just Text
_  -> Name
name
      Maybe Text
Nothing ->
        case Name -> Maybe Text
nameGiven Name
name of
          Maybe Text
Nothing -> Name
name
          Just Text
t  ->
            case (Text -> Bool) -> [Text] -> ([Text], [Text])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isParticleChar) (Text -> [Text]
T.words Text
t) of
              ([Text]
_,[])  -> Name
name
              ([],[Text]
_)  -> Name
name
              ([Text]
as,[Text]
bs)
                | (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isParticleChar) [Text]
bs
                      -> Name
name{ nameGiven = Just (T.unwords as)
                             , nameDroppingParticle = Just (T.unwords bs) }
                | Bool
otherwise -> Name
name
  isParticlePunct :: Char -> Bool
isParticlePunct Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\'' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'’' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\x2013' Bool -> Bool -> Bool
||
                      Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.'
  isParticleChar :: Char -> Bool
isParticleChar Char
c = Char -> Bool
isLower Char
c Bool -> Bool -> Bool
|| Char -> Bool
isParticlePunct Char
c

-- cheater syntax for name: used in parsing note:
--  editor: Thompson || Hunter S.
parseCheaterName :: Text -> Parser Name
parseCheaterName :: Text -> Parser Name
parseCheaterName Text
t = do
  let (Maybe Text
family, Maybe Text
given) = case HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
T.splitOn Text
"||" Text
t of
                           (Text
f:Text
g:[Text]
_) -> (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Text
T.strip Text
f), Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Text
T.strip Text
g))
                           [Text
f]     -> (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Text
T.strip Text
f), Maybe Text
forall a. Maybe a
Nothing)
                           []      -> (Maybe Text
forall a. Maybe a
Nothing, Maybe Text
forall a. Maybe a
Nothing)
  Name -> Parser Name
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Name -> Parser Name) -> Name -> Parser Name
forall a b. (a -> b) -> a -> b
$ Name -> Name
extractParticles (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$
      Name
      { nameFamily :: Maybe Text
nameFamily              = Maybe Text
family
      , nameGiven :: Maybe Text
nameGiven               = Maybe Text
given
      , nameDroppingParticle :: Maybe Text
nameDroppingParticle    = Maybe Text
forall a. Maybe a
Nothing
      , nameNonDroppingParticle :: Maybe Text
nameNonDroppingParticle = Maybe Text
forall a. Maybe a
Nothing
      , nameSuffix :: Maybe Text
nameSuffix              = Maybe Text
forall a. Maybe a
Nothing
      , nameCommaSuffix :: Bool
nameCommaSuffix         = Bool
False
      , nameStaticOrdering :: Bool
nameStaticOrdering      = Bool
False
      , nameLiteral :: Maybe Text
nameLiteral             = if Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Text
family Bool -> Bool -> Bool
&& Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Text
given
                                     then Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t
                                     else Maybe Text
forall a. Maybe a
Nothing
      }

isByzantineName :: Name -> Bool
isByzantineName :: Name -> Bool
isByzantineName Name
name = Bool -> (Text -> Bool) -> Maybe Text -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False Text -> Bool
isByzantine (Name -> Maybe Text
nameFamily Name
name)

-- detect latin/cyrillic names
-- see src/load.js ROMANESQUE_REGEX in citeproc-js:
-- /[-0-9a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0370-\u03ff\u0400-\u052f\u0590-\u05d4\u05d6-\u05ff\u1f00-\u1fff\u0600-\u06ff\u200c\u200d\u200e\u0218\u0219\u021a\u021b\u202a-\u202e]/
isByzantineChar :: Char -> Bool
isByzantineChar :: Char -> Bool
isByzantineChar Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'z') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'Z') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x0e01' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x0e5b') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x00c0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x017f') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x0370' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x03ff') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x0400' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x052f') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x0590' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x05d4') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x05d6' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x05ff') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x1f00' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x1fff') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x0600' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x06ff') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x200c' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x200e') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x2018' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x2019') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x021a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x021b') Bool -> Bool -> Bool
||
                (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x202a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x202e')

isByzantine :: Text -> Bool
isByzantine :: Text -> Bool
isByzantine = (Char -> Bool) -> Text -> Bool
T.any Char -> Bool
isByzantineChar

asBool :: Value -> Parser Bool
asBool :: Value -> Parser Bool
asBool (String Text
t) = Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Parser Bool) -> Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$ Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"true"
asBool (Bool Bool
b)   = Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
b
asBool (Number Scientific
n) = Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Parser Bool) -> Bool -> Parser Bool
forall a b. (a -> b) -> a -> b
$ Scientific
n Scientific -> Scientific -> Bool
forall a. Eq a => a -> a -> Bool
== Scientific
1
asBool Value
x          = String -> Value -> Parser Bool
forall a. String -> Value -> Parser a
typeMismatch String
"Bool" Value
x

asText :: Value -> Parser Text
asText :: Value -> Parser Text
asText (String Text
t)   = Text -> Parser Text
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
t
asText (Number Scientific
n)   = Text -> Parser Text
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Parser Text) -> Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ case Scientific -> Either Double Int
forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
S.floatingOrInteger Scientific
n of
                                 Left Double
r -> String -> Text
T.pack (Double -> String
forall a. Show a => a -> String
show (Double
r :: Double))
                                 Right Int
i -> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show (Int
i :: Int))
asText Value
x            = String -> Value -> Parser Text
forall a. String -> Value -> Parser a
typeMismatch String
"String" Value
x

asInt :: Value -> Parser Int
asInt :: Value -> Parser Int
asInt (String Text
t) =
  case Text -> Maybe Int
readAsInt Text
t of
    Just Int
x  -> Int -> Parser Int
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
x
    Maybe Int
Nothing -> String -> Parser Int
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"not a number"
asInt v :: Value
v@Number{} = Value -> Parser Int
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
asInt Value
v = String -> Value -> Parser Int
forall a. String -> Value -> Parser a
typeMismatch String
"Number" Value
v

data Date =
  Date
  { Date -> [DateParts]
dateParts     :: [DateParts]
  , Date -> Bool
dateCirca     :: Bool
  , Date -> Maybe Int
dateSeason    :: Maybe Int
  , Date -> Maybe Text
dateLiteral   :: Maybe Text
  } deriving (Int -> Date -> ShowS
[Date] -> ShowS
Date -> String
(Int -> Date -> ShowS)
-> (Date -> String) -> ([Date] -> ShowS) -> Show Date
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Date -> ShowS
showsPrec :: Int -> Date -> ShowS
$cshow :: Date -> String
show :: Date -> String
$cshowList :: [Date] -> ShowS
showList :: [Date] -> ShowS
Show, Date -> Date -> Bool
(Date -> Date -> Bool) -> (Date -> Date -> Bool) -> Eq Date
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Date -> Date -> Bool
== :: Date -> Date -> Bool
$c/= :: Date -> Date -> Bool
/= :: Date -> Date -> Bool
Eq, Eq Date
Eq Date =>
(Date -> Date -> Ordering)
-> (Date -> Date -> Bool)
-> (Date -> Date -> Bool)
-> (Date -> Date -> Bool)
-> (Date -> Date -> Bool)
-> (Date -> Date -> Date)
-> (Date -> Date -> Date)
-> Ord Date
Date -> Date -> Bool
Date -> Date -> Ordering
Date -> Date -> Date
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Date -> Date -> Ordering
compare :: Date -> Date -> Ordering
$c< :: Date -> Date -> Bool
< :: Date -> Date -> Bool
$c<= :: Date -> Date -> Bool
<= :: Date -> Date -> Bool
$c> :: Date -> Date -> Bool
> :: Date -> Date -> Bool
$c>= :: Date -> Date -> Bool
>= :: Date -> Date -> Bool
$cmax :: Date -> Date -> Date
max :: Date -> Date -> Date
$cmin :: Date -> Date -> Date
min :: Date -> Date -> Date
Ord)

instance ToJSON Date where
  toJSON :: Date -> Value
toJSON Date
d =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      (if Date -> Bool
dateCirca Date
d then ((Key
"circa", Bool -> Value
forall a. ToJSON a => a -> Value
toJSON Bool
True)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:) else [Pair] -> [Pair]
forall a. a -> a
id) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      (case Date -> Maybe Int
dateSeason Date
d of
        Just Int
s -> ((Key
"season", Int -> Value
forall a. ToJSON a => a -> Value
toJSON Int
s)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)
        Maybe Int
Nothing -> [Pair] -> [Pair]
forall a. a -> a
id) ([Pair] -> [Pair]) -> ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      (case Date -> Maybe Text
dateLiteral Date
d of
        Just Text
l -> ((Key
"literal", Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
l)Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
:)
        Maybe Text
Nothing -> [Pair] -> [Pair]
forall a. a -> a
id) ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall a b. (a -> b) -> a -> b
$
      [ (Key
"date-parts", [DateParts] -> Value
forall a. ToJSON a => a -> Value
toJSON (Date -> [DateParts]
dateParts Date
d)) ]

instance FromJSON Date where
 parseJSON :: Value -> Parser Date
parseJSON (String Text
t) = Text -> Parser Date
rawDate Text
t  -- cheater dates
 parseJSON Value
x = String -> (Object -> Parser Date) -> Value -> Parser Date
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Date" (\Object
v ->
   (Object
vObject -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"raw" Parser Text -> (Text -> Parser Date) -> Parser Date
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Parser Date
rawDate)
   Parser Date -> Parser Date -> Parser Date
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
   ([DateParts] -> Bool -> Maybe Int -> Maybe Text -> Date
Date ([DateParts] -> Bool -> Maybe Int -> Maybe Text -> Date)
-> Parser [DateParts]
-> Parser (Bool -> Maybe Int -> Maybe Text -> Date)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe [DateParts])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"date-parts" Parser (Maybe [DateParts]) -> [DateParts] -> Parser [DateParts]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
         Parser (Bool -> Maybe Int -> Maybe Text -> Date)
-> Parser Bool -> Parser (Maybe Int -> Maybe Text -> Date)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"circa" Parser Value -> (Value -> Parser Bool) -> Parser Bool
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Parser Bool
asBool) Parser Bool -> Parser Bool -> Parser Bool
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Parser Bool
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False)
         Parser (Maybe Int -> Maybe Text -> Date)
-> Parser (Maybe Int) -> Parser (Maybe Text -> Date)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"season" Parser Value -> (Value -> Parser (Maybe Int)) -> Parser (Maybe Int)
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Int -> Maybe Int) -> Parser Int -> Parser (Maybe Int)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Maybe Int
forall a. a -> Maybe a
Just (Parser Int -> Parser (Maybe Int))
-> (Value -> Parser Int) -> Value -> Parser (Maybe Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Parser Int
asInt) Parser (Maybe Int) -> Parser (Maybe Int) -> Parser (Maybe Int)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Int -> Parser (Maybe Int)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Int
forall a. Maybe a
Nothing)
         Parser (Maybe Text -> Date) -> Parser (Maybe Text) -> Parser Date
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"literal")) Value
x

newtype DateParts = DateParts [Int]
  deriving (Int -> DateParts -> ShowS
[DateParts] -> ShowS
DateParts -> String
(Int -> DateParts -> ShowS)
-> (DateParts -> String)
-> ([DateParts] -> ShowS)
-> Show DateParts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DateParts -> ShowS
showsPrec :: Int -> DateParts -> ShowS
$cshow :: DateParts -> String
show :: DateParts -> String
$cshowList :: [DateParts] -> ShowS
showList :: [DateParts] -> ShowS
Show, DateParts -> DateParts -> Bool
(DateParts -> DateParts -> Bool)
-> (DateParts -> DateParts -> Bool) -> Eq DateParts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DateParts -> DateParts -> Bool
== :: DateParts -> DateParts -> Bool
$c/= :: DateParts -> DateParts -> Bool
/= :: DateParts -> DateParts -> Bool
Eq, Eq DateParts
Eq DateParts =>
(DateParts -> DateParts -> Ordering)
-> (DateParts -> DateParts -> Bool)
-> (DateParts -> DateParts -> Bool)
-> (DateParts -> DateParts -> Bool)
-> (DateParts -> DateParts -> Bool)
-> (DateParts -> DateParts -> DateParts)
-> (DateParts -> DateParts -> DateParts)
-> Ord DateParts
DateParts -> DateParts -> Bool
DateParts -> DateParts -> Ordering
DateParts -> DateParts -> DateParts
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DateParts -> DateParts -> Ordering
compare :: DateParts -> DateParts -> Ordering
$c< :: DateParts -> DateParts -> Bool
< :: DateParts -> DateParts -> Bool
$c<= :: DateParts -> DateParts -> Bool
<= :: DateParts -> DateParts -> Bool
$c> :: DateParts -> DateParts -> Bool
> :: DateParts -> DateParts -> Bool
$c>= :: DateParts -> DateParts -> Bool
>= :: DateParts -> DateParts -> Bool
$cmax :: DateParts -> DateParts -> DateParts
max :: DateParts -> DateParts -> DateParts
$cmin :: DateParts -> DateParts -> DateParts
min :: DateParts -> DateParts -> DateParts
Ord, [DateParts] -> Value
[DateParts] -> Encoding
DateParts -> Bool
DateParts -> Value
DateParts -> Encoding
(DateParts -> Value)
-> (DateParts -> Encoding)
-> ([DateParts] -> Value)
-> ([DateParts] -> Encoding)
-> (DateParts -> Bool)
-> ToJSON DateParts
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: DateParts -> Value
toJSON :: DateParts -> Value
$ctoEncoding :: DateParts -> Encoding
toEncoding :: DateParts -> Encoding
$ctoJSONList :: [DateParts] -> Value
toJSONList :: [DateParts] -> Value
$ctoEncodingList :: [DateParts] -> Encoding
toEncodingList :: [DateParts] -> Encoding
$comitField :: DateParts -> Bool
omitField :: DateParts -> Bool
ToJSON)

instance FromJSON DateParts where
  parseJSON :: Value -> Parser DateParts
parseJSON Value
v =
    [Int] -> DateParts
DateParts ([Int] -> DateParts) -> Parser [Int] -> Parser DateParts
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> Parser [Value]
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v Parser [Value] -> ([Value] -> Parser [Int]) -> Parser [Int]
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Value -> Parser Int) -> [Value] -> Parser [Int]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Value -> Parser Int
asInt ([Value] -> Parser [Int])
-> ([Value] -> [Value]) -> [Value] -> Parser [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Value] -> [Value]
removeEmptyStrings)

rawDate :: Text -> Parser Date
rawDate :: Text -> Parser Date
rawDate Text
t = case Text -> Maybe Date
rawDateEDTF Text
t Maybe Date -> Maybe Date -> Maybe Date
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Maybe Date
rawDateOld Text
t of
              Just Date
d  -> Date -> Parser Date
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Date
d
              Maybe Date
Nothing -> Date -> Parser Date
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Date -> Parser Date) -> Date -> Parser Date
forall a b. (a -> b) -> a -> b
$ Date { dateParts :: [DateParts]
dateParts = []
                                       , dateCirca :: Bool
dateCirca = Bool
False
                                       , dateSeason :: Maybe Int
dateSeason = Maybe Int
forall a. Maybe a
Nothing
                                       , dateLiteral :: Maybe Text
dateLiteral = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
t }

rawDateEDTF :: Text -> Maybe Date
rawDateEDTF :: Text -> Maybe Date
rawDateEDTF = Text -> Maybe Date
rawDateISO (Text -> Maybe Date) -> (Text -> Text) -> Text -> Maybe Date
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
handleRanges
 where
  handleRanges :: Text -> Text
handleRanges Text
t =
    case (Char -> Bool) -> Text -> [Text]
T.split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'/') Text
t of
         -- 199u EDTF format for a range
         [Text
x] | (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'u') Text
x ->
               (Char -> Char) -> Text -> Text
T.map (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'u' then Char
'0' else Char
c) Text
x
               Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
               (Char -> Char) -> Text -> Text
T.map (\Char
c -> if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'u' then Char
'9' else Char
c) Text
x
         [Text
x, Text
"open"] -> Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/"    -- EDTF
         [Text
x, Text
"unknown"] -> Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" -- EDTF
         [Text]
_  -> Text
t

rawDateISO :: Text -> Maybe Date
rawDateISO :: Text -> Maybe Date
rawDateISO Text
raw = do
  let ranges :: [Text]
ranges = (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
T.strip ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> [Text]
T.split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'/') Text
raw
  let circa :: Bool
circa = (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text
"~" Text -> Text -> Bool
`T.isSuffixOf`) [Text]
ranges
  let isSpecial :: Char -> Bool
isSpecial Char
'~' = Bool
True
      isSpecial Char
'?' = Bool
True
      isSpecial Char
'%' = Bool
True
      isSpecial Char
'T' = Bool
True
      isSpecial Char
_   = Bool
False
  let dparts :: Text -> Maybe DateParts
dparts Text
t = do
        (Bool
hasY, Text
t') <- if Int -> Text -> Text
T.take Int
1 Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"y"
                         then (Bool, Text) -> Maybe (Bool, Text)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
True, Int -> Text -> Text
T.drop Int
1 Text
t)
                         else (Bool, Text) -> Maybe (Bool, Text)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, Text
t)
        (Bool
isNeg, Text
t'') <- if Int -> Text -> Text
T.take Int
1 Text
t' Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"-"
                           then (Bool, Text) -> Maybe (Bool, Text)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
True, Int -> Text -> Text
T.drop Int
1 Text
t')
                           else (Bool, Text) -> Maybe (Bool, Text)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, Text
t')
        let t''' :: Text
t''' = (Char -> Bool) -> Text -> Text
T.takeWhile (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpecial) Text
t''
        case (Char -> Bool) -> Text -> [Text]
T.split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'-') Text
t''' of
          [Text
""]         -> DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
0]
          [Text
y', Text
m', Text
d'] -> do
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 Bool -> Bool -> Bool
|| Bool
hasY Bool -> Bool -> Bool
&& Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
4
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
m' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
d' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2
            Int
y <- (if Bool
isNeg
                     then (\Int
x -> (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
* (-Int
1)) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) -- 0 = 1 BC
                     else Int -> Int
forall a. a -> a
id) (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Int
readAsInt Text
y'
            Int
m <- Text -> Maybe Int
readAsInt Text
m'
            Int
d <- Text -> Maybe Int
readAsInt Text
d'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y, Int
m, Int
d]
          [Text
y', Text
m'] -> do
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 Bool -> Bool -> Bool
|| Bool
hasY Bool -> Bool -> Bool
&& Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
4
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
m' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2
            Int
y <- (if Bool
isNeg
                     then (\Int
x -> (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
* (-Int
1)) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) -- 0 = 1 BC
                     else Int -> Int
forall a. a -> a
id) (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Int
readAsInt Text
y'
            Int
m <- Text -> Maybe Int
readAsInt Text
m'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y, Int
m]
          [Text
y'] -> do
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 Bool -> Bool -> Bool
|| Bool
hasY Bool -> Bool -> Bool
&& Text -> Int
T.length Text
y' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
4
            Int
y <- (if Bool
isNeg
                     then (\Int
x -> (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
* (-Int
1)) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) -- 0 = 1 BC
                     else Int -> Int
forall a. a -> a
id) (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Int
readAsInt Text
y'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y]
          [Text]
_ -> Maybe DateParts
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  [DateParts]
dps <- (Text -> Maybe DateParts) -> [Text] -> Maybe [DateParts]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text -> Maybe DateParts
dparts [Text]
ranges
  Date -> Maybe Date
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Date -> Maybe Date) -> Date -> Maybe Date
forall a b. (a -> b) -> a -> b
$ Date
    { dateParts :: [DateParts]
dateParts     = [DateParts]
dps
    , dateCirca :: Bool
dateCirca     = Bool
circa
    , dateSeason :: Maybe Int
dateSeason    = Maybe Int
forall a. Maybe a
Nothing
    , dateLiteral :: Maybe Text
dateLiteral   = Maybe Text
forall a. Maybe a
Nothing
    }


rawDateOld :: Text -> Maybe Date
rawDateOld :: Text -> Maybe Date
rawDateOld Text
raw = do
  let months :: [Text]
months   = [Text
"jan",Text
"feb",Text
"mar",Text
"apr",Text
"may",Text
"jun",Text
"jul",Text
"aug",
                  Text
"sep",Text
"oct",Text
"nov",Text
"dec"]
  let seasons :: [Text]
seasons  = [Text
"spr",Text
"sum",Text
"fal",Text
"win"]
  let ranges :: [Text]
ranges = (Char -> Bool) -> Text -> [Text]
T.split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'-') Text
raw
  let readTextMonth :: Text -> m Int
readTextMonth Text
t = do
        let key :: Text
key = Text -> Text
T.toLower (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.take Int
3 Text
t
        case Text -> [Text] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Text
key [Text]
months of
             Just Int
n  -> Int -> m Int
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
             Maybe Int
Nothing -> case Text -> [Text] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Text
key [Text]
seasons of
                          Just Int
n -> Int -> m Int
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
13)
                          Maybe Int
Nothing -> String -> m Int
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Improper month"
  let dparts :: Text -> Maybe DateParts
dparts Text
t =
        case (Char -> Bool) -> Text -> [Text]
T.split (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',') (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.strip Text
t of
          [Text
m', Text
d', Text
y'] -> do
            Int
y <- Text -> Maybe Int
readAsInt Text
y'
            Int
m <- Text -> Maybe Int
readAsInt Text
m' Maybe Int -> Maybe Int -> Maybe Int
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Maybe Int
forall {m :: * -> *}. MonadFail m => Text -> m Int
readTextMonth Text
m'
            Int
d <- Text -> Maybe Int
readAsInt Text
d'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y, Int
m, Int
d]
          [Text
m', Text
y']     -> do
            Int
y <- Text -> Maybe Int
readAsInt Text
y'
            Int
m <- Text -> Maybe Int
readAsInt Text
m' Maybe Int -> Maybe Int -> Maybe Int
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> Maybe Int
forall {m :: * -> *}. MonadFail m => Text -> m Int
readTextMonth Text
m'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y, Int
m]
          [Text
y']         -> do
            Int
y <- Text -> Maybe Int
readAsInt Text
y'
            DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts [Int
y]
          []           -> DateParts -> Maybe DateParts
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (DateParts -> Maybe DateParts) -> DateParts -> Maybe DateParts
forall a b. (a -> b) -> a -> b
$ [Int] -> DateParts
DateParts []
          [Text]
_            -> Maybe DateParts
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  [DateParts]
dps <- (Text -> Maybe DateParts) -> [Text] -> Maybe [DateParts]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Text -> Maybe DateParts
dparts [Text]
ranges
  Date -> Maybe Date
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Date -> Maybe Date) -> Date -> Maybe Date
forall a b. (a -> b) -> a -> b
$ Date
    { dateParts :: [DateParts]
dateParts     = [DateParts]
dps
    , dateCirca :: Bool
dateCirca     = Bool
False
    , dateSeason :: Maybe Int
dateSeason    = Maybe Int
forall a. Maybe a
Nothing
    , dateLiteral :: Maybe Text
dateLiteral   = Maybe Text
forall a. Maybe a
Nothing
    }



removeEmptyStrings :: [Value] -> [Value]
removeEmptyStrings :: [Value] -> [Value]
removeEmptyStrings = (Value -> Bool) -> [Value] -> [Value]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Value -> Bool) -> Value -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Bool
isEmptyString)
  where
   isEmptyString :: Value -> Bool
isEmptyString (String Text
t) = Text -> Bool
T.null Text
t
   isEmptyString Value
_ = Bool
False

data Output a =
    Formatted Formatting [Output a]
  | Linked Text [Output a]
  | InNote (Output a)
  | Literal a
  | Tagged Tag (Output a)
  | NullOutput
  deriving (Int -> Output a -> ShowS
[Output a] -> ShowS
Output a -> String
(Int -> Output a -> ShowS)
-> (Output a -> String) -> ([Output a] -> ShowS) -> Show (Output a)
forall a. Show a => Int -> Output a -> ShowS
forall a. Show a => [Output a] -> ShowS
forall a. Show a => Output a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Output a -> ShowS
showsPrec :: Int -> Output a -> ShowS
$cshow :: forall a. Show a => Output a -> String
show :: Output a -> String
$cshowList :: forall a. Show a => [Output a] -> ShowS
showList :: [Output a] -> ShowS
Show, Output a -> Output a -> Bool
(Output a -> Output a -> Bool)
-> (Output a -> Output a -> Bool) -> Eq (Output a)
forall a. Eq a => Output a -> Output a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Output a -> Output a -> Bool
== :: Output a -> Output a -> Bool
$c/= :: forall a. Eq a => Output a -> Output a -> Bool
/= :: Output a -> Output a -> Bool
Eq)

instance Uniplate (Output a) where
  uniplate :: Output a -> (Str (Output a), Str (Output a) -> Output a)
uniplate (Formatted Formatting
f [Output a]
xs) = (Formatting -> [Output a] -> Output a)
-> Type (Formatting -> [Output a] -> Output a) (Output a)
forall from to. from -> Type from to
plate Formatting -> [Output a] -> Output a
forall a. Formatting -> [Output a] -> Output a
Formatted Type (Formatting -> [Output a] -> Output a) (Output a)
-> Formatting -> Type ([Output a] -> Output a) (Output a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- Formatting
f Type ([Output a] -> Output a) (Output a)
-> [Output a] -> (Str (Output a), Str (Output a) -> Output a)
forall to from. Type ([to] -> from) to -> [to] -> Type from to
||* [Output a]
xs
  uniplate (Linked Text
u [Output a]
xs)  = (Text -> [Output a] -> Output a)
-> Type (Text -> [Output a] -> Output a) (Output a)
forall from to. from -> Type from to
plate Text -> [Output a] -> Output a
forall a. Text -> [Output a] -> Output a
Linked Type (Text -> [Output a] -> Output a) (Output a)
-> Text -> Type ([Output a] -> Output a) (Output a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- Text
u Type ([Output a] -> Output a) (Output a)
-> [Output a] -> (Str (Output a), Str (Output a) -> Output a)
forall to from. Type ([to] -> from) to -> [to] -> Type from to
||* [Output a]
xs
  uniplate (InNote Output a
x)       = (Output a -> Output a) -> Type (Output a -> Output a) (Output a)
forall from to. from -> Type from to
plate Output a -> Output a
forall a. Output a -> Output a
InNote Type (Output a -> Output a) (Output a)
-> Output a -> (Str (Output a), Str (Output a) -> Output a)
forall to from. Type (to -> from) to -> to -> Type from to
|* Output a
x
  uniplate (Literal a
x)      = (a -> Output a) -> Type (a -> Output a) (Output a)
forall from to. from -> Type from to
plate a -> Output a
forall a. a -> Output a
Literal Type (a -> Output a) (Output a)
-> a -> (Str (Output a), Str (Output a) -> Output a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- a
x
  uniplate (Tagged Tag
t Output a
x)     = (Tag -> Output a -> Output a)
-> Type (Tag -> Output a -> Output a) (Output a)
forall from to. from -> Type from to
plate Tag -> Output a -> Output a
forall a. Tag -> Output a -> Output a
Tagged Type (Tag -> Output a -> Output a) (Output a)
-> Tag -> Type (Output a -> Output a) (Output a)
forall item from to. Type (item -> from) to -> item -> Type from to
|- Tag
t Type (Output a -> Output a) (Output a)
-> Output a -> (Str (Output a), Str (Output a) -> Output a)
forall to from. Type (to -> from) to -> to -> Type from to
|* Output a
x
  uniplate Output a
NullOutput       = Output a -> (Str (Output a), Str (Output a) -> Output a)
forall from to. from -> Type from to
plate Output a
forall a. Output a
NullOutput

instance Biplate (Output a) (Output a) where
  biplate :: Output a -> (Str (Output a), Str (Output a) -> Output a)
biplate = Output a -> (Str (Output a), Str (Output a) -> Output a)
forall to. to -> Type to to
plateSelf

data Identifier =
      IdentDOI Text
    | IdentPMCID Text
    | IdentPMID Text
    | IdentURL Text
  deriving (Int -> Identifier -> ShowS
[Identifier] -> ShowS
Identifier -> String
(Int -> Identifier -> ShowS)
-> (Identifier -> String)
-> ([Identifier] -> ShowS)
-> Show Identifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Identifier -> ShowS
showsPrec :: Int -> Identifier -> ShowS
$cshow :: Identifier -> String
show :: Identifier -> String
$cshowList :: [Identifier] -> ShowS
showList :: [Identifier] -> ShowS
Show, Identifier -> Identifier -> Bool
(Identifier -> Identifier -> Bool)
-> (Identifier -> Identifier -> Bool) -> Eq Identifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Identifier -> Identifier -> Bool
== :: Identifier -> Identifier -> Bool
$c/= :: Identifier -> Identifier -> Bool
/= :: Identifier -> Identifier -> Bool
Eq)

identifierToURL :: Identifier -> Text
identifierToURL :: Identifier -> Text
identifierToURL Identifier
ident =
    case Identifier
ident of
      IdentDOI Text
t   -> Text -> Text -> Text
tolink Text
"https://doi.org/" Text
t
      IdentPMCID Text
t -> Text -> Text -> Text
tolink Text
"https://www.ncbi.nlm.nih.gov/pmc/articles/" Text
t
      IdentPMID Text
t  -> Text -> Text -> Text
tolink Text
"https://www.ncbi.nlm.nih.gov/pubmed/" Text
t
      IdentURL Text
t   -> Text -> Text -> Text
tolink Text
"https://" Text
t
    where
        tolink :: Text -> Text -> Text
tolink Text
pref Text
x = if Text -> Bool
T.null Text
x Bool -> Bool -> Bool
|| (Text
"://" Text -> Text -> Bool
`T.isInfixOf` Text
x)
                           then Text
x
                           else Text
pref Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x

{-# DEPRECATED fixShortDOI
   "This function is no longer used and will be removed." #-}
-- see https://shortdoi.org
fixShortDOI :: Text -> Text
fixShortDOI :: Text -> Text
fixShortDOI Text
x = if Text
"10/" Text -> Text -> Bool
`T.isPrefixOf` Text
x
                   then Int -> Text -> Text
T.drop Int
3 Text
x
                   else Text
x

data Tag =
      TagTerm Term
    | TagCitationNumber Int
    | TagCitationLabel
    | TagTitle
    -- ^ marks the title of an entry, so it can be hyperlinked later
    | TagItem CitationItemType ItemId
    | TagName Name
    | TagNames Variable NamesFormat [Name]
    | TagDate Date
    | TagYearSuffix Int
    | TagLocator
    | TagPrefix
    | TagSuffix
  deriving (Int -> Tag -> ShowS
[Tag] -> ShowS
Tag -> String
(Int -> Tag -> ShowS)
-> (Tag -> String) -> ([Tag] -> ShowS) -> Show Tag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Tag -> ShowS
showsPrec :: Int -> Tag -> ShowS
$cshow :: Tag -> String
show :: Tag -> String
$cshowList :: [Tag] -> ShowS
showList :: [Tag] -> ShowS
Show, Tag -> Tag -> Bool
(Tag -> Tag -> Bool) -> (Tag -> Tag -> Bool) -> Eq Tag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Tag -> Tag -> Bool
== :: Tag -> Tag -> Bool
$c/= :: Tag -> Tag -> Bool
/= :: Tag -> Tag -> Bool
Eq)

outputToText :: CiteprocOutput a => Output a -> Text
outputToText :: forall a. CiteprocOutput a => Output a -> Text
outputToText Output a
NullOutput = Text
forall a. Monoid a => a
mempty
outputToText (Literal a
x ) = a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x
outputToText (Tagged Tag
_ Output a
x) = Output a -> Text
forall a. CiteprocOutput a => Output a -> Text
outputToText Output a
x
outputToText (Formatted Formatting
_ [Output a]
xs) = [Text] -> Text
T.unwords ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Output a -> Text) -> [Output a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Output a -> Text
forall a. CiteprocOutput a => Output a -> Text
outputToText [Output a]
xs
outputToText (Linked Text
_ [Output a]
xs) = [Text] -> Text
T.unwords ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Output a -> Text) -> [Output a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Output a -> Text
forall a. CiteprocOutput a => Output a -> Text
outputToText [Output a]
xs
outputToText (InNote Output a
x)   = Output a -> Text
forall a. CiteprocOutput a => Output a -> Text
outputToText Output a
x

renderOutput :: CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput :: forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
_ Output a
NullOutput = a
forall a. Monoid a => a
mempty
renderOutput CiteprocOptions
_ (Literal a
x) = a
x
renderOutput CiteprocOptions
opts (Tagged (TagItem CitationItemType
itemtype ItemId
ident) Output a
x)
  | CiteprocOptions -> Bool
linkCitations CiteprocOptions
opts
  , CitationItemType
itemtype CitationItemType -> CitationItemType -> Bool
forall a. Eq a => a -> a -> Bool
/= CitationItemType
AuthorOnly
  = Text -> a -> a
forall a. CiteprocOutput a => Text -> a -> a
addHyperlink (Text
"#ref-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ItemId -> Text
unItemId ItemId
ident) (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts Output a
x
renderOutput CiteprocOptions
opts (Tagged Tag
_ Output a
x) = CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts Output a
x
renderOutput CiteprocOptions
opts (Formatted Formatting
f [Linked Text
url [Output a]
xs])
  | CiteprocOptions -> Bool
linkBibliography CiteprocOptions
opts
  , Text
url Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
prefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
anchor
  -- ensure correct handling of link prefixes like (https://doi.org/)
  -- when a link's prefix+anchor=target, ensure the link includes the prefix
  -- (see pandoc#6723 and citeproc#88)
  = CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts (Output a -> a) -> Output a -> a
forall a b. (a -> b) -> a -> b
$ Text -> [Output a] -> Output a
forall a. Text -> [Output a] -> Output a
Linked Text
url [Formatting -> [Output a] -> Output a
forall a. Formatting -> [Output a] -> Output a
Formatted Formatting
f [Output a]
xs]
  where
    anchor :: Text
anchor = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ((Output a -> Text) -> [Output a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Output a -> Text
forall a. CiteprocOutput a => Output a -> Text
outputToText [Output a]
xs)
    prefix :: Text
prefix = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" (Formatting -> Maybe Text
formatPrefix Formatting
f)
renderOutput CiteprocOptions
opts (Formatted Formatting
formatting [Output a]
xs) =
  Formatting -> a -> a
forall a. CiteprocOutput a => Formatting -> a -> a
addFormatting Formatting
formatting (a -> a) -> ([a] -> a) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> a
forall a. Monoid a => [a] -> a
mconcat ([a] -> a) -> ([a] -> [a]) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    (case Formatting -> Maybe Text
formatDelimiter Formatting
formatting of
       Just Text
d  -> a -> [a] -> [a]
forall a. CiteprocOutput a => a -> [a] -> [a]
addDelimiters (Text -> a
forall a. CiteprocOutput a => Text -> a
fromText Text
d)
       Maybe Text
Nothing -> [a] -> [a]
forall a. a -> a
id) ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
forall a. Monoid a => a
mempty) ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (Output a -> a) -> [Output a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts) [Output a]
xs
renderOutput CiteprocOptions
opts (Linked Text
url [Output a]
xs)
  = (if CiteprocOptions -> Bool
linkBibliography CiteprocOptions
opts
       then Text -> a -> a
forall a. CiteprocOutput a => Text -> a -> a
addHyperlink Text
url
       else a -> a
forall a. a -> a
id) (a -> a) -> ([a] -> a) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> a
forall a. Monoid a => [a] -> a
mconcat ([a] -> a) -> ([a] -> [a]) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$ (Output a -> a) -> [Output a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts) [Output a]
xs
renderOutput CiteprocOptions
opts (InNote Output a
x) = a -> a
forall {a}. CiteprocOutput a => a -> a
inNote (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$
  (Char -> Bool) -> a -> a
forall a. CiteprocOutput a => (Char -> Bool) -> a -> a
dropTextWhile Char -> Bool
isSpace (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$
  (Char -> Bool) -> a -> a
forall a. CiteprocOutput a => (Char -> Bool) -> a -> a
dropTextWhile (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
';' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':') (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$
  CiteprocOptions -> Output a -> a
forall a. CiteprocOutput a => CiteprocOptions -> Output a -> a
renderOutput CiteprocOptions
opts Output a
x

addDelimiters :: CiteprocOutput a => a -> [a] -> [a]
addDelimiters :: forall a. CiteprocOutput a => a -> [a] -> [a]
addDelimiters a
delim =
  (a -> [a] -> [a]) -> [a] -> [a] -> [a]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> [a] -> [a]
addDelim []
 where
  addDelim :: a -> [a] -> [a]
addDelim a
x []     = [a
x]
  addDelim a
x (a
a:[a]
as) = case Text -> Maybe (Char, Text)
T.uncons (a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
a) of
                         Just (Char
c,Text
_)
                           | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
',' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
';' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.' -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as
                         Maybe (Char, Text)
_ -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
delim a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as

fixPunct :: CiteprocOutput a => [a] -> [a]
fixPunct :: forall a. CiteprocOutput a => [a] -> [a]
fixPunct (a
x:a
y:[a]
zs) =
  case (Char
xEnd, Char
yStart) of
    -- https://github.com/Juris-M/citeproc-js/blob/master/src/queue.js#L724
    (Char
'!',Char
'.') -> [a]
keepFirst
    (Char
'!',Char
'?') -> [a]
keepBoth
    (Char
'!',Char
':') -> [a]
keepFirst
    (Char
'!',Char
',') -> [a]
keepBoth
    (Char
'!',Char
';') -> [a]
keepBoth
    (Char
'?',Char
'!') -> [a]
keepBoth
    (Char
'?',Char
'.') -> [a]
keepFirst
    (Char
'?',Char
':') -> [a]
keepFirst
    (Char
'?',Char
',') -> [a]
keepBoth
    (Char
'?',Char
';') -> [a]
keepBoth
    (Char
'.',Char
'!') -> [a]
keepBoth
    (Char
'.',Char
'?') -> [a]
keepBoth
    (Char
'.',Char
':') -> [a]
keepBoth
    (Char
'.',Char
',') -> [a]
keepBoth
    (Char
'.',Char
';') -> [a]
keepBoth
    (Char
':',Char
'!') -> [a]
keepSecond
    (Char
':',Char
'?') -> [a]
keepSecond
    (Char
':',Char
'.') -> [a]
keepFirst
    (Char
':',Char
',') -> [a]
keepBoth
    (Char
':',Char
';') -> [a]
keepBoth
    (Char
',',Char
'!') -> [a]
keepBoth
    (Char
',',Char
'?') -> [a]
keepBoth
    (Char
',',Char
':') -> [a]
keepBoth
    (Char
',',Char
'.') -> [a]
keepBoth
    (Char
',',Char
';') -> [a]
keepBoth
    (Char
';',Char
'!') -> [a]
keepSecond
    (Char
';',Char
'?') -> [a]
keepSecond
    (Char
';',Char
':') -> [a]
keepFirst
    (Char
';',Char
'.') -> [a]
keepFirst
    (Char
';',Char
',') -> [a]
keepBoth
    (Char
'!',Char
'!') -> [a]
keepFirst
    (Char
'?',Char
'?') -> [a]
keepFirst
    (Char
'.',Char
'.') -> [a]
keepFirst
    (Char
':',Char
':') -> [a]
keepFirst
    (Char
';',Char
';') -> [a]
keepFirst
    (Char
',',Char
',') -> [a]
keepFirst
    (Char
' ',Char
' ') -> [a]
keepSecond
    (Char
' ',Char
',') -> [a]
keepSecond
    (Char
' ',Char
'.') -> [a]
keepSecond
    (Char, Char)
_ -> [a]
keepBoth
 where
  xText :: Text
xText = a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x
  yText :: Text
yText = a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
y
  xEnd :: Char
xEnd = if Text -> Bool
T.null Text
xText then Char
'\xFFFD' else HasCallStack => Text -> Char
Text -> Char
T.last Text
xText
  yStart :: Char
yStart = if Text -> Bool
T.null Text
yText then Char
'\xFFFD' else HasCallStack => Text -> Char
Text -> Char
T.head Text
yText
  xTrimmed :: a
xTrimmed = (Char -> Bool) -> a -> a
forall a. CiteprocOutput a => (Char -> Bool) -> a -> a
dropTextWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
xEnd) a
x
  yTrimmed :: a
yTrimmed = (Char -> Bool) -> a -> a
forall a. CiteprocOutput a => (Char -> Bool) -> a -> a
dropTextWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
yStart) a
y
  keepFirst :: [a]
keepFirst = if a
yTrimmed a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y -- see #49
                 then a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
                 else [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
yTrimmed a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs
  keepSecond :: [a]
keepSecond = if a
xTrimmed a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x -- see #49
                  then a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
                  else [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct (a
xTrimmed a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
  keepBoth :: [a]
keepBoth = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
forall a. CiteprocOutput a => [a] -> [a]
fixPunct (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
zs)
fixPunct [a]
zs = [a]
zs


grouped :: [Output a] -> Output a
grouped :: forall a. [Output a] -> Output a
grouped = Formatting -> [Output a] -> Output a
forall a. Formatting -> [Output a] -> Output a
formatted Formatting
forall a. Monoid a => a
mempty

formatted :: Formatting -> [Output a] -> Output a
formatted :: forall a. Formatting -> [Output a] -> Output a
formatted Formatting
formatting = [Output a] -> Output a
forall a. [Output a] -> Output a
grouped' ([Output a] -> Output a)
-> ([Output a] -> [Output a]) -> [Output a] -> Output a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Output a -> Bool) -> [Output a] -> [Output a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Output a -> Bool) -> Output a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Output a -> Bool
forall {a}. Output a -> Bool
isNullOutput)
 where
  isNullOutput :: Output a -> Bool
isNullOutput Output a
NullOutput = Bool
True
  isNullOutput Output a
_          = Bool
False
  grouped' :: [Output a] -> Output a
grouped' []  = Output a
forall a. Output a
NullOutput
  grouped' [Output a
x] | Formatting
formatting Formatting -> Formatting -> Bool
forall a. Eq a => a -> a -> Bool
== Formatting
forall a. Monoid a => a
mempty = Output a
x
  grouped' [Output a]
xs  = Formatting -> [Output a] -> Output a
forall a. Formatting -> [Output a] -> Output a
Formatted Formatting
formatting [Output a]
xs

readAsInt :: Text -> Maybe Int
readAsInt :: Text -> Maybe Int
readAsInt Text
t =
  case Reader Int
forall a. Integral a => Reader a
TR.decimal Text
t of
      Right (Int
x,Text
t') | Text -> Bool
T.null Text
t' -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x
      Either String (Int, Text)
_                        -> Maybe Int
forall a. Maybe a
Nothing

-- | An abbreviations map.  These are typically stored in a JSON
-- serialization: for examples of the format, see
-- <https://github.com/citation-style-language/abbreviations>.
-- Abbreviations are substituted in the output when the variable
-- and its content are matched by something in the abbreviations map.
newtype Abbreviations =
  Abbreviations (M.Map Variable (M.Map Variable Text))
  deriving (Int -> Abbreviations -> ShowS
[Abbreviations] -> ShowS
Abbreviations -> String
(Int -> Abbreviations -> ShowS)
-> (Abbreviations -> String)
-> ([Abbreviations] -> ShowS)
-> Show Abbreviations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Abbreviations -> ShowS
showsPrec :: Int -> Abbreviations -> ShowS
$cshow :: Abbreviations -> String
show :: Abbreviations -> String
$cshowList :: [Abbreviations] -> ShowS
showList :: [Abbreviations] -> ShowS
Show, Abbreviations -> Abbreviations -> Bool
(Abbreviations -> Abbreviations -> Bool)
-> (Abbreviations -> Abbreviations -> Bool) -> Eq Abbreviations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Abbreviations -> Abbreviations -> Bool
== :: Abbreviations -> Abbreviations -> Bool
$c/= :: Abbreviations -> Abbreviations -> Bool
/= :: Abbreviations -> Abbreviations -> Bool
Eq, Eq Abbreviations
Eq Abbreviations =>
(Abbreviations -> Abbreviations -> Ordering)
-> (Abbreviations -> Abbreviations -> Bool)
-> (Abbreviations -> Abbreviations -> Bool)
-> (Abbreviations -> Abbreviations -> Bool)
-> (Abbreviations -> Abbreviations -> Bool)
-> (Abbreviations -> Abbreviations -> Abbreviations)
-> (Abbreviations -> Abbreviations -> Abbreviations)
-> Ord Abbreviations
Abbreviations -> Abbreviations -> Bool
Abbreviations -> Abbreviations -> Ordering
Abbreviations -> Abbreviations -> Abbreviations
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Abbreviations -> Abbreviations -> Ordering
compare :: Abbreviations -> Abbreviations -> Ordering
$c< :: Abbreviations -> Abbreviations -> Bool
< :: Abbreviations -> Abbreviations -> Bool
$c<= :: Abbreviations -> Abbreviations -> Bool
<= :: Abbreviations -> Abbreviations -> Bool
$c> :: Abbreviations -> Abbreviations -> Bool
> :: Abbreviations -> Abbreviations -> Bool
$c>= :: Abbreviations -> Abbreviations -> Bool
>= :: Abbreviations -> Abbreviations -> Bool
$cmax :: Abbreviations -> Abbreviations -> Abbreviations
max :: Abbreviations -> Abbreviations -> Abbreviations
$cmin :: Abbreviations -> Abbreviations -> Abbreviations
min :: Abbreviations -> Abbreviations -> Abbreviations
Ord)
-- NOTE: We use 'Variable' in the second map for the contents of the
-- variable, because we want it to be treated case-insensitively,
-- and we need a wrapper around 'CI' that has To/FromJSON instances.

instance FromJSON Abbreviations where
  parseJSON :: Value -> Parser Abbreviations
parseJSON = String
-> (Object -> Parser Abbreviations)
-> Value
-> Parser Abbreviations
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Abbreviations" ((Object -> Parser Abbreviations) -> Value -> Parser Abbreviations)
-> (Object -> Parser Abbreviations)
-> Value
-> Parser Abbreviations
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Map Variable (Map Variable Text) -> Abbreviations
Abbreviations (Map Variable (Map Variable Text) -> Abbreviations)
-> Parser (Map Variable (Map Variable Text))
-> Parser Abbreviations
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Map Variable (Map Variable Text))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"default"

instance ToJSON Abbreviations where
  toJSON :: Abbreviations -> Value
toJSON (Abbreviations Map Variable (Map Variable Text)
m) =
    [Pair] -> Value
object [(Key
"default", Map Variable (Map Variable Text) -> Value
forall a. ToJSON a => a -> Value
toJSON Map Variable (Map Variable Text)
m)]

-- | Returns an abbreviation if the variable and its value match
-- something in the abbreviations map.
lookupAbbreviation :: CiteprocOutput a
                   => Variable -> Val a -> Abbreviations -> Maybe (Val a)
lookupAbbreviation :: forall a.
CiteprocOutput a =>
Variable -> Val a -> Abbreviations -> Maybe (Val a)
lookupAbbreviation Variable
var Val a
val (Abbreviations Map Variable (Map Variable Text)
abbrevmap) = do
  Map Variable Text
abbrvs <- Variable
-> Map Variable (Map Variable Text) -> Maybe (Map Variable Text)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (if Variable -> VariableType
variableType Variable
var VariableType -> VariableType -> Bool
forall a. Eq a => a -> a -> Bool
== VariableType
NumberVariable
                         then Variable
"number"
                         else Variable
var) Map Variable (Map Variable Text)
abbrevmap
  case Val a
val of
    TextVal Text
t  -> Maybe (Val a)
-> (Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Maybe (Val a)
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero (Val a -> Maybe (Val a)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Maybe (Val a))
-> (Text -> Val a) -> Text -> Maybe (Val a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Val a
forall a. Text -> Val a
TextVal)
                         (Maybe Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ Variable -> Map Variable Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (Text -> Variable
toVariable Text
t) Map Variable Text
abbrvs
    FancyVal a
x -> Maybe (Val a)
-> (Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Maybe (Val a)
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero (Val a -> Maybe (Val a)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Maybe (Val a))
-> (Text -> Val a) -> Text -> Maybe (Val a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Val a
forall a. Text -> Val a
TextVal)
                         (Maybe Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ Variable -> Map Variable Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (Text -> Variable
toVariable (a -> Text
forall a. CiteprocOutput a => a -> Text
toText a
x)) Map Variable Text
abbrvs
    NumVal Int
n   -> Maybe (Val a)
-> (Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Maybe (Val a)
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero (Val a -> Maybe (Val a)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Val a -> Maybe (Val a))
-> (Text -> Val a) -> Text -> Maybe (Val a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Val a
forall a. Text -> Val a
TextVal)
                         (Maybe Text -> Maybe (Val a)) -> Maybe Text -> Maybe (Val a)
forall a b. (a -> b) -> a -> b
$ Variable -> Map Variable Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (Text -> Variable
toVariable (String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
n))) Map Variable Text
abbrvs
    Val a
_          -> Maybe (Val a)
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero

-- | Result of citation processing.
data Result a =
  Result
  { forall a. Result a -> [a]
resultCitations     :: [a]          -- ^ List of formatted citations
                    -- corresponding to the citations given to 'citeproc'
  , forall a. Result a -> [(Text, a)]
resultBibliography  :: [(Text, a)]  -- ^ List of formatted bibliography
                    -- entries (if the style calls for a bibliography),
                    -- each a pair consisting of the item identifier and
                    -- the formatted entry
  , forall a. Result a -> [Text]
resultWarnings      :: [Text]       -- ^ Warnings from citation processing
  } deriving (Int -> Result a -> ShowS
[Result a] -> ShowS
Result a -> String
(Int -> Result a -> ShowS)
-> (Result a -> String) -> ([Result a] -> ShowS) -> Show (Result a)
forall a. Show a => Int -> Result a -> ShowS
forall a. Show a => [Result a] -> ShowS
forall a. Show a => Result a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Result a -> ShowS
showsPrec :: Int -> Result a -> ShowS
$cshow :: forall a. Show a => Result a -> String
show :: Result a -> String
$cshowList :: forall a. Show a => [Result a] -> ShowS
showList :: [Result a] -> ShowS
Show, (forall a b. (a -> b) -> Result a -> Result b)
-> (forall a b. a -> Result b -> Result a) -> Functor Result
forall a b. a -> Result b -> Result a
forall a b. (a -> b) -> Result a -> Result b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Result a -> Result b
fmap :: forall a b. (a -> b) -> Result a -> Result b
$c<$ :: forall a b. a -> Result b -> Result a
<$ :: forall a b. a -> Result b -> Result a
Functor, Functor Result
Foldable Result
(Functor Result, Foldable Result) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Result a -> f (Result b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Result (f a) -> f (Result a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Result a -> m (Result b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Result (m a) -> m (Result a))
-> Traversable Result
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Result (m a) -> m (Result a)
forall (f :: * -> *) a.
Applicative f =>
Result (f a) -> f (Result a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Result a -> m (Result b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Result a -> f (Result b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Result a -> f (Result b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Result a -> f (Result b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Result (f a) -> f (Result a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Result (f a) -> f (Result a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Result a -> m (Result b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Result a -> m (Result b)
$csequence :: forall (m :: * -> *) a. Monad m => Result (m a) -> m (Result a)
sequence :: forall (m :: * -> *) a. Monad m => Result (m a) -> m (Result a)
Traversable, (forall m. Monoid m => Result m -> m)
-> (forall m a. Monoid m => (a -> m) -> Result a -> m)
-> (forall m a. Monoid m => (a -> m) -> Result a -> m)
-> (forall a b. (a -> b -> b) -> b -> Result a -> b)
-> (forall a b. (a -> b -> b) -> b -> Result a -> b)
-> (forall b a. (b -> a -> b) -> b -> Result a -> b)
-> (forall b a. (b -> a -> b) -> b -> Result a -> b)
-> (forall a. (a -> a -> a) -> Result a -> a)
-> (forall a. (a -> a -> a) -> Result a -> a)
-> (forall a. Result a -> [a])
-> (forall a. Result a -> Bool)
-> (forall a. Result a -> Int)
-> (forall a. Eq a => a -> Result a -> Bool)
-> (forall a. Ord a => Result a -> a)
-> (forall a. Ord a => Result a -> a)
-> (forall a. Num a => Result a -> a)
-> (forall a. Num a => Result a -> a)
-> Foldable Result
forall a. Eq a => a -> Result a -> Bool
forall a. Num a => Result a -> a
forall a. Ord a => Result a -> a
forall m. Monoid m => Result m -> m
forall a. Result a -> Bool
forall a. Result a -> Int
forall a. Result a -> [a]
forall a. (a -> a -> a) -> Result a -> a
forall m a. Monoid m => (a -> m) -> Result a -> m
forall b a. (b -> a -> b) -> b -> Result a -> b
forall a b. (a -> b -> b) -> b -> Result a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Result m -> m
fold :: forall m. Monoid m => Result m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Result a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Result a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Result a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Result a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Result a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Result a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Result a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Result a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Result a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Result a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Result a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Result a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Result a -> a
foldr1 :: forall a. (a -> a -> a) -> Result a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Result a -> a
foldl1 :: forall a. (a -> a -> a) -> Result a -> a
$ctoList :: forall a. Result a -> [a]
toList :: forall a. Result a -> [a]
$cnull :: forall a. Result a -> Bool
null :: forall a. Result a -> Bool
$clength :: forall a. Result a -> Int
length :: forall a. Result a -> Int
$celem :: forall a. Eq a => a -> Result a -> Bool
elem :: forall a. Eq a => a -> Result a -> Bool
$cmaximum :: forall a. Ord a => Result a -> a
maximum :: forall a. Ord a => Result a -> a
$cminimum :: forall a. Ord a => Result a -> a
minimum :: forall a. Ord a => Result a -> a
$csum :: forall a. Num a => Result a -> a
sum :: forall a. Num a => Result a -> a
$cproduct :: forall a. Num a => Result a -> a
product :: forall a. Num a => Result a -> a
Foldable)

instance ToJSON a => ToJSON (Result a) where
  toJSON :: Result a -> Value
toJSON Result a
res = [Pair] -> Value
object
    [ (Key
"citations", [a] -> Value
forall a. ToJSON a => a -> Value
toJSON ([a] -> Value) -> [a] -> Value
forall a b. (a -> b) -> a -> b
$ Result a -> [a]
forall a. Result a -> [a]
resultCitations Result a
res)
    , (Key
"bibliography", [(Text, a)] -> Value
forall a. ToJSON a => a -> Value
toJSON ([(Text, a)] -> Value) -> [(Text, a)] -> Value
forall a b. (a -> b) -> a -> b
$ Result a -> [(Text, a)]
forall a. Result a -> [(Text, a)]
resultBibliography Result a
res)
    , (Key
"warnings", [Text] -> Value
forall a. ToJSON a => a -> Value
toJSON ([Text] -> Value) -> [Text] -> Value
forall a b. (a -> b) -> a -> b
$ Result a -> [Text]
forall a. Result a -> [Text]
resultWarnings Result a
res)
    ]

instance FromJSON a => FromJSON (Result a) where
  parseJSON :: Value -> Parser (Result a)
parseJSON = String
-> (Object -> Parser (Result a)) -> Value -> Parser (Result a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Result" ((Object -> Parser (Result a)) -> Value -> Parser (Result a))
-> (Object -> Parser (Result a)) -> Value -> Parser (Result a)
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    [a] -> [(Text, a)] -> [Text] -> Result a
forall a. [a] -> [(Text, a)] -> [Text] -> Result a
Result ([a] -> [(Text, a)] -> [Text] -> Result a)
-> Parser [a] -> Parser ([(Text, a)] -> [Text] -> Result a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser [a]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"citations"
           Parser ([(Text, a)] -> [Text] -> Result a)
-> Parser [(Text, a)] -> Parser ([Text] -> Result a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser [(Text, a)]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bibliography"
           Parser ([Text] -> Result a) -> Parser [Text] -> Parser (Result a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser [Text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"warnings"

-- | Inputs for citation processing.
data Inputs a =
  Inputs
  { forall a. Inputs a -> Maybe [Citation a]
inputsCitations     :: Maybe [Citation a]
  , forall a. Inputs a -> Maybe [Reference a]
inputsReferences    :: Maybe [Reference a]
  , forall a. Inputs a -> Maybe Text
inputsStyle         :: Maybe Text
  , forall a. Inputs a -> Maybe Abbreviations
inputsAbbreviations :: Maybe Abbreviations
  , forall a. Inputs a -> Maybe Lang
inputsLang          :: Maybe Lang
  } deriving (Int -> Inputs a -> ShowS
[Inputs a] -> ShowS
Inputs a -> String
(Int -> Inputs a -> ShowS)
-> (Inputs a -> String) -> ([Inputs a] -> ShowS) -> Show (Inputs a)
forall a. Show a => Int -> Inputs a -> ShowS
forall a. Show a => [Inputs a] -> ShowS
forall a. Show a => Inputs a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Inputs a -> ShowS
showsPrec :: Int -> Inputs a -> ShowS
$cshow :: forall a. Show a => Inputs a -> String
show :: Inputs a -> String
$cshowList :: forall a. Show a => [Inputs a] -> ShowS
showList :: [Inputs a] -> ShowS
Show)

instance ToJSON a => ToJSON (Inputs a) where
  toJSON :: Inputs a -> Value
toJSON Inputs a
inp = [Pair] -> Value
object
    [ (Key
"citations",     Maybe [Citation a] -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe [Citation a] -> Value) -> Maybe [Citation a] -> Value
forall a b. (a -> b) -> a -> b
$ Inputs a -> Maybe [Citation a]
forall a. Inputs a -> Maybe [Citation a]
inputsCitations Inputs a
inp)
    , (Key
"references",    Maybe [Reference a] -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe [Reference a] -> Value) -> Maybe [Reference a] -> Value
forall a b. (a -> b) -> a -> b
$ Inputs a -> Maybe [Reference a]
forall a. Inputs a -> Maybe [Reference a]
inputsReferences Inputs a
inp)
    , (Key
"style",         Maybe Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe Text -> Value) -> Maybe Text -> Value
forall a b. (a -> b) -> a -> b
$ Inputs a -> Maybe Text
forall a. Inputs a -> Maybe Text
inputsStyle Inputs a
inp)
    , (Key
"abbreviations", Maybe Abbreviations -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe Abbreviations -> Value) -> Maybe Abbreviations -> Value
forall a b. (a -> b) -> a -> b
$ Inputs a -> Maybe Abbreviations
forall a. Inputs a -> Maybe Abbreviations
inputsAbbreviations Inputs a
inp)
    , (Key
"lang",          Maybe Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Maybe Text -> Value) -> Maybe Text -> Value
forall a b. (a -> b) -> a -> b
$ Lang -> Text
renderLang (Lang -> Text) -> Maybe Lang -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Inputs a -> Maybe Lang
forall a. Inputs a -> Maybe Lang
inputsLang Inputs a
inp)
    ]

instance (FromJSON a, Eq a) => FromJSON (Inputs a) where
  parseJSON :: Value -> Parser (Inputs a)
parseJSON = String
-> (Object -> Parser (Inputs a)) -> Value -> Parser (Inputs a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Inputs" ((Object -> Parser (Inputs a)) -> Value -> Parser (Inputs a))
-> (Object -> Parser (Inputs a)) -> Value -> Parser (Inputs a)
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe [Citation a]
-> Maybe [Reference a]
-> Maybe Text
-> Maybe Abbreviations
-> Maybe Lang
-> Inputs a
forall a.
Maybe [Citation a]
-> Maybe [Reference a]
-> Maybe Text
-> Maybe Abbreviations
-> Maybe Lang
-> Inputs a
Inputs (Maybe [Citation a]
 -> Maybe [Reference a]
 -> Maybe Text
 -> Maybe Abbreviations
 -> Maybe Lang
 -> Inputs a)
-> Parser (Maybe [Citation a])
-> Parser
     (Maybe [Reference a]
      -> Maybe Text -> Maybe Abbreviations -> Maybe Lang -> Inputs a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe [Citation a])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"citations"
           Parser
  (Maybe [Reference a]
   -> Maybe Text -> Maybe Abbreviations -> Maybe Lang -> Inputs a)
-> Parser (Maybe [Reference a])
-> Parser
     (Maybe Text -> Maybe Abbreviations -> Maybe Lang -> Inputs a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe [Reference a])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"references"
           Parser
  (Maybe Text -> Maybe Abbreviations -> Maybe Lang -> Inputs a)
-> Parser (Maybe Text)
-> Parser (Maybe Abbreviations -> Maybe Lang -> Inputs a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"style"
           Parser (Maybe Abbreviations -> Maybe Lang -> Inputs a)
-> Parser (Maybe Abbreviations) -> Parser (Maybe Lang -> Inputs a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Abbreviations)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"abbreviations"
           Parser (Maybe Lang -> Inputs a)
-> Parser (Maybe Lang) -> Parser (Inputs a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (do Maybe Text
mbl <- Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"lang"
                   case Maybe Text
mbl of
                     Maybe Text
Nothing -> Maybe Lang -> Parser (Maybe Lang)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Lang
forall a. Maybe a
Nothing
                     Just Text
l  ->
                       case Text -> Either String Lang
parseLang Text
l of
                         Left String
_     -> Maybe Lang -> Parser (Maybe Lang)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Lang
forall a. Maybe a
Nothing
                         Right Lang
lang -> Maybe Lang -> Parser (Maybe Lang)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Lang -> Parser (Maybe Lang))
-> Maybe Lang -> Parser (Maybe Lang)
forall a b. (a -> b) -> a -> b
$ Lang -> Maybe Lang
forall a. a -> Maybe a
Just Lang
lang)