{-# LANGUAGE GADTs, PostfixOperators #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Language.Drasil.Sentence (
Sentence(..),
SentenceStyle(..), RefInfo(..), TermCapitalization(..),
(+:+), (+:+.), (+:), (!.), capSent, ch, eS, eS', sC, sDash, sParen,
sentencePlural, sentenceShort,
sentenceSymb, sentenceTerm) where
import Language.Drasil.UID (HasUID(..), UID)
import Language.Drasil.Symbol (HasSymbol, Symbol)
import Language.Drasil.ModelExpr.Lang (ModelExpr)
import Language.Drasil.ExprClasses (Express(express))
import Language.Drasil.UnitLang (USymb)
import Control.Lens ((^.))
import Data.Char (toUpper)
data SentenceStyle = PluralTerm
| TermStyle
| ShortStyle
data TermCapitalization = CapF | CapW | NoCap
data RefInfo = None
| Equation [Int]
| Page [Int]
| RefNote String
infixr 5 :+:
data Sentence where
Ch :: SentenceStyle -> TermCapitalization -> UID -> Sentence
SyCh :: UID -> Sentence
Sy :: USymb -> Sentence
S :: String -> Sentence
P :: Symbol -> Sentence
E :: ModelExpr -> Sentence
Ref :: UID -> Sentence -> RefInfo -> Sentence
Quote :: Sentence -> Sentence
Percent :: Sentence
(:+:) :: Sentence -> Sentence -> Sentence
EmptyS :: Sentence
eS :: ModelExpr -> Sentence
eS :: ModelExpr -> Sentence
eS = ModelExpr -> Sentence
E
eS' :: Express t => t -> Sentence
eS' :: t -> Sentence
eS' = ModelExpr -> Sentence
E (ModelExpr -> Sentence) -> (t -> ModelExpr) -> t -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> ModelExpr
forall c. Express c => c -> ModelExpr
express
ch :: (HasUID c, HasSymbol c) => c -> Sentence
ch :: c -> Sentence
ch x :: c
x = UID -> Sentence
SyCh (c
x c -> Getting UID c UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID c UID
forall c. HasUID c => Lens' c UID
uid)
instance Semigroup Sentence where
<> :: Sentence -> Sentence -> Sentence
(<>) = Sentence -> Sentence -> Sentence
(:+:)
instance Monoid Sentence where
mempty :: Sentence
mempty = Sentence
EmptyS
mappend :: Sentence -> Sentence -> Sentence
mappend = Sentence -> Sentence -> Sentence
(:+:)
sentencePlural, sentenceShort, sentenceSymb, sentenceTerm :: UID -> Sentence
sentencePlural :: UID -> Sentence
sentencePlural = SentenceStyle -> TermCapitalization -> UID -> Sentence
Ch SentenceStyle
PluralTerm TermCapitalization
NoCap
sentenceShort :: UID -> Sentence
sentenceShort = SentenceStyle -> TermCapitalization -> UID -> Sentence
Ch SentenceStyle
ShortStyle TermCapitalization
NoCap
sentenceSymb :: UID -> Sentence
sentenceSymb = UID -> Sentence
SyCh
sentenceTerm :: UID -> Sentence
sentenceTerm = SentenceStyle -> TermCapitalization -> UID -> Sentence
Ch SentenceStyle
TermStyle TermCapitalization
NoCap
sParen :: Sentence -> Sentence
sParen :: Sentence -> Sentence
sParen x :: Sentence
x = String -> Sentence
S "(" Sentence -> Sentence -> Sentence
:+: Sentence
x Sentence -> Sentence -> Sentence
:+: String -> Sentence
S ")"
sDash :: Sentence -> Sentence -> Sentence
sDash :: Sentence -> Sentence -> Sentence
sDash a :: Sentence
a b :: Sentence
b = Sentence
a Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S "-" Sentence -> Sentence -> Sentence
+:+ Sentence
b
(+:+) :: Sentence -> Sentence -> Sentence
EmptyS +:+ :: Sentence -> Sentence -> Sentence
+:+ b :: Sentence
b = Sentence
b
a :: Sentence
a +:+ EmptyS = Sentence
a
a :: Sentence
a +:+ b :: Sentence
b = Sentence
a Sentence -> Sentence -> Sentence
:+: String -> Sentence
S " " Sentence -> Sentence -> Sentence
:+: Sentence
b
sC :: Sentence -> Sentence -> Sentence
a :: Sentence
a sC :: Sentence -> Sentence -> Sentence
`sC` b :: Sentence
b = Sentence
a Sentence -> Sentence -> Sentence
:+: String -> Sentence
S "," Sentence -> Sentence -> Sentence
+:+ Sentence
b
(+:+.) :: Sentence -> Sentence -> Sentence
a :: Sentence
a +:+. :: Sentence -> Sentence -> Sentence
+:+. b :: Sentence
b = Sentence
a Sentence -> Sentence -> Sentence
+:+ Sentence
b Sentence -> Sentence -> Sentence
:+: String -> Sentence
S "."
(!.) :: Sentence -> Sentence
!. :: Sentence -> Sentence
(!.) a :: Sentence
a = Sentence
a Sentence -> Sentence -> Sentence
:+: String -> Sentence
S "."
(+:) :: Sentence -> Sentence -> Sentence
a :: Sentence
a +: :: Sentence -> Sentence -> Sentence
+: b :: Sentence
b = Sentence
a Sentence -> Sentence -> Sentence
+:+ Sentence
b Sentence -> Sentence -> Sentence
:+: String -> Sentence
S ":"
capSent :: Sentence -> Sentence
capSent :: Sentence -> Sentence
capSent (S (s :: Char
s:ss :: String
ss)) = String -> Sentence
S (Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: String
ss)
capSent (a :: Sentence
a :+: b :: Sentence
b) = Sentence -> Sentence
capSent Sentence
a Sentence -> Sentence -> Sentence
:+: Sentence
b
capSent x :: Sentence
x = Sentence
x