module Language.Drasil.Printing.Helpers where
import Prelude hiding ((<>))
import Text.PrettyPrint (text, Doc, (<>), ($$))
import Data.Char (toUpper, toLower)
import Language.Drasil.Printing.Citation ( CiteField(HowPublished), HP (..) )
infixl 5 $^$
($^$) :: Doc -> Doc -> Doc
$^$ :: Doc -> Doc -> Doc
($^$) Doc
a Doc
b = Doc
a Doc -> Doc -> Doc
$$ Doc
emptyline Doc -> Doc -> Doc
$$ Doc
b
vsep :: [Doc] -> Doc
vsep :: [Doc] -> Doc
vsep = (Doc -> Doc -> Doc) -> [Doc] -> Doc
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 Doc -> Doc -> Doc
($^$)
bslash,dbs,assign,eq,lt,gt,leq,geq,dlr,ast,pls,hat,slash,hyph,unders,pipe,emptyline :: Doc
bslash :: Doc
bslash = String -> Doc
text String
"\\"
dbs :: Doc
dbs = String -> Doc
text String
"\\\\"
assign :: Doc
assign = String -> Doc
text String
"="
eq :: Doc
eq = String -> Doc
text String
"=="
lt :: Doc
lt = String -> Doc
text String
"<"
gt :: Doc
gt = String -> Doc
text String
">"
leq :: Doc
leq = String -> Doc
text String
"<="
geq :: Doc
geq = String -> Doc
text String
">="
dlr :: Doc
dlr = String -> Doc
text String
"$"
ast :: Doc
ast = String -> Doc
text String
"*"
pls :: Doc
pls = String -> Doc
text String
"+"
hat :: Doc
hat = String -> Doc
text String
"^"
slash :: Doc
slash = String -> Doc
text String
"/"
hyph :: Doc
hyph = String -> Doc
text String
"-"
unders :: Doc
unders = String -> Doc
text String
"_"
pipe :: Doc
pipe = String -> Doc
text String
"|"
emptyline :: Doc
emptyline = String -> Doc
text String
""
sq,br :: String -> Doc
sq :: String -> Doc
sq String
t = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]"
br :: String -> Doc
br String
t = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"{" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"}"
dot, comm :: Doc -> Doc
dot :: Doc -> Doc
dot = (Doc -> Doc -> Doc
<> String -> Doc
text String
".")
comm :: Doc -> Doc
comm = (Doc -> Doc -> Doc
<> String -> Doc
text String
",")
dollarDoc :: Doc -> Doc
dollarDoc :: Doc -> Doc
dollarDoc Doc
x = Doc
dlr Doc -> Doc -> Doc
<> Doc
x Doc -> Doc -> Doc
<> Doc
dlr
paren, brace, dollar, sqbrac, angbrac :: String -> String
paren :: String -> String
paren String
x = String
"(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")"
brace :: String -> String
brace String
x = String
"{" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"}"
dollar :: String -> String
dollar String
x = String
"$" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"$"
sqbrac :: String -> String
sqbrac String
x = String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]"
angbrac :: String -> String
angbrac String
x = String
"<" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">"
upcase, lowcase :: String -> Doc
upcase :: String -> Doc
upcase [] = String -> Doc
text []
upcase (Char
c:String
cs) = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Char -> Char
toUpper Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:String
cs
lowcase :: String -> Doc
lowcase [] = String -> Doc
text []
lowcase (Char
c:String
cs) = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ Char -> Char
toLower Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:String
cs
sufx :: Int -> String
sufx :: Int -> String
sufx Int
1 = String
"st"
sufx Int
2 = String
"nd"
sufx Int
3 = String
"rd"
sufx Int
_ = String
"th"
sufxer :: Int -> String
sufxer :: Int -> String
sufxer Int
x = Int -> String
sufx Int
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"."
where
r :: Int
r = if Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
x Int
100 Int -> [Int] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Int
11, Int
12, Int
13] then Int
0 else Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
x Int
10
sufxPrint :: [CiteField] -> String
sufxPrint :: [CiteField] -> String
sufxPrint [CiteField]
fields = if (CiteField -> Bool) -> [CiteField] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any CiteField -> Bool
isUrl [CiteField]
fields then String
"" else String
" Print."
where
isUrl :: CiteField -> Bool
isUrl (HowPublished (URL Spec
_)) = Bool
True
isUrl CiteField
_ = Bool
False