module Language.Drasil.Symbol (
Decoration(..), Symbol(..),
HasSymbol(..),
compsy
) where
import Language.Drasil.Stages (Stage)
import Language.Drasil.Unicode(Special)
import Data.Char (toLower)
data Decoration =
Hat
| Vector
| Prime
| Delta
| Magnitude
deriving (Decoration -> Decoration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Decoration -> Decoration -> Bool
$c/= :: Decoration -> Decoration -> Bool
== :: Decoration -> Decoration -> Bool
$c== :: Decoration -> Decoration -> Bool
Eq, Eq Decoration
Decoration -> Decoration -> Bool
Decoration -> Decoration -> Ordering
Decoration -> Decoration -> Decoration
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
min :: Decoration -> Decoration -> Decoration
$cmin :: Decoration -> Decoration -> Decoration
max :: Decoration -> Decoration -> Decoration
$cmax :: Decoration -> Decoration -> Decoration
>= :: Decoration -> Decoration -> Bool
$c>= :: Decoration -> Decoration -> Bool
> :: Decoration -> Decoration -> Bool
$c> :: Decoration -> Decoration -> Bool
<= :: Decoration -> Decoration -> Bool
$c<= :: Decoration -> Decoration -> Bool
< :: Decoration -> Decoration -> Bool
$c< :: Decoration -> Decoration -> Bool
compare :: Decoration -> Decoration -> Ordering
$ccompare :: Decoration -> Decoration -> Ordering
Ord)
data Symbol =
Variable String
| Label String
| Integ Int
| Special Special
| Atop Decoration Symbol
| Corners [Symbol] [Symbol] [Symbol] [Symbol] Symbol
| Concat [Symbol]
| Empty
deriving Symbol -> Symbol -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Symbol -> Symbol -> Bool
$c/= :: Symbol -> Symbol -> Bool
== :: Symbol -> Symbol -> Bool
$c== :: Symbol -> Symbol -> Bool
Eq
class HasSymbol c where
symbol :: c -> Stage -> Symbol
instance Semigroup Symbol where
Symbol
a <> :: Symbol -> Symbol -> Symbol
<> Symbol
b = [Symbol] -> Symbol
Concat [Symbol
a , Symbol
b]
instance Monoid Symbol where
mempty :: Symbol
mempty = Symbol
Empty
complsy :: [Symbol] -> [Symbol] -> Ordering
complsy :: [Symbol] -> [Symbol] -> Ordering
complsy [] [] = Ordering
EQ
complsy [] [Symbol]
_ = Ordering
LT
complsy [Symbol]
_ [] = Ordering
GT
complsy (Symbol
x : [Symbol]
xs) (Symbol
y : [Symbol]
ys) = Symbol -> Symbol -> Ordering
compsy Symbol
x Symbol
y forall a. Semigroup a => a -> a -> a
<> [Symbol] -> [Symbol] -> Ordering
complsy [Symbol]
xs [Symbol]
ys
compsy :: Symbol -> Symbol -> Ordering
compsy :: Symbol -> Symbol -> Ordering
compsy (Concat [Symbol]
x) (Concat [Symbol]
y) = [Symbol] -> [Symbol] -> Ordering
complsy [Symbol]
x [Symbol]
y
compsy (Concat [Symbol]
a) Symbol
b = [Symbol] -> [Symbol] -> Ordering
complsy [Symbol]
a [Symbol
b]
compsy Symbol
b (Concat [Symbol]
a) = [Symbol] -> [Symbol] -> Ordering
complsy [Symbol
b] [Symbol]
a
compsy (Atop Decoration
d1 Symbol
a) (Atop Decoration
d2 Symbol
a') =
case Symbol -> Symbol -> Ordering
compsy Symbol
a Symbol
a' of
Ordering
EQ -> forall a. Ord a => a -> a -> Ordering
compare Decoration
d1 Decoration
d2
Ordering
other -> Ordering
other
compsy Symbol
a (Atop Decoration
Magnitude Symbol
b) =
case Symbol -> Symbol -> Ordering
compsy Symbol
a Symbol
b of
Ordering
EQ -> Ordering
LT
Ordering
other -> Ordering
other
compsy (Atop Decoration
Magnitude Symbol
b) Symbol
a =
case Symbol -> Symbol -> Ordering
compsy Symbol
b Symbol
a of
Ordering
EQ -> Ordering
GT
Ordering
other -> Ordering
other
compsy Symbol
a (Atop Decoration
Delta Symbol
b) =
case Symbol -> Symbol -> Ordering
compsy Symbol
a Symbol
b of
Ordering
EQ -> Ordering
LT
Ordering
other -> Ordering
other
compsy (Atop Decoration
Delta Symbol
b) Symbol
a =
case Symbol -> Symbol -> Ordering
compsy Symbol
b Symbol
a of
Ordering
EQ -> Ordering
GT
Ordering
other -> Ordering
other
compsy (Corners [] [] [Symbol]
ur [] (Corners [] [] [] [Symbol]
lr Symbol
b)) Symbol
a = Symbol -> Symbol -> Ordering
compsy ([Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners [] [] [Symbol]
ur [Symbol]
lr Symbol
b) Symbol
a
compsy Symbol
a (Corners [] [] [Symbol]
ur [] (Corners [] [] [] [Symbol]
lr Symbol
b)) = Symbol -> Symbol -> Ordering
compsy Symbol
a ([Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners [] [] [Symbol]
ur [Symbol]
lr Symbol
b)
compsy (Corners [Symbol]
_ [Symbol]
_ [Symbol]
u [Symbol]
l Symbol
b) (Corners [Symbol]
_ [Symbol]
_ [Symbol]
u' [Symbol]
l' Symbol
b') =
case Symbol -> Symbol -> Ordering
compsy Symbol
b Symbol
b' of
Ordering
EQ -> case [Symbol] -> [Symbol] -> Ordering
complsy [Symbol]
l [Symbol]
l' of
Ordering
EQ -> [Symbol] -> [Symbol] -> Ordering
complsy [Symbol]
u [Symbol]
u'
Ordering
other -> Ordering
other
Ordering
other -> Ordering
other
compsy Symbol
a (Corners [Symbol]
_ [Symbol]
_ [Symbol]
_ [Symbol]
_ Symbol
b) =
case Symbol -> Symbol -> Ordering
compsy Symbol
a Symbol
b of
Ordering
EQ -> Ordering
LT
Ordering
other -> Ordering
other
compsy (Corners [Symbol]
_ [Symbol]
_ [Symbol]
_ [Symbol]
_ Symbol
b) Symbol
a =
case Symbol -> Symbol -> Ordering
compsy Symbol
b Symbol
a of
Ordering
EQ -> Ordering
GT
Ordering
other -> Ordering
other
compsy Symbol
a (Atop Decoration
_ Symbol
b) =
case Symbol -> Symbol -> Ordering
compsy Symbol
a Symbol
b of
Ordering
EQ -> Ordering
LT
Ordering
other -> Ordering
other
compsy (Atop Decoration
_ Symbol
b) Symbol
a =
case Symbol -> Symbol -> Ordering
compsy Symbol
b Symbol
a of
Ordering
EQ -> Ordering
GT
Ordering
other -> Ordering
other
compsy (Special Special
a) (Special Special
b) = forall a. Ord a => a -> a -> Ordering
compare Special
a Special
b
compsy (Integ Int
x) (Integ Int
y) = forall a. Ord a => a -> a -> Ordering
compare Int
x Int
y
compsy (Variable [Char]
x) (Variable [Char]
y) = [Char] -> [Char] -> Ordering
compsyLower [Char]
x [Char]
y
compsy (Variable [Char]
x) (Label [Char]
y) = [Char] -> [Char] -> Ordering
compsyLower [Char]
x [Char]
y
compsy (Label [Char]
x) (Variable [Char]
y) = [Char] -> [Char] -> Ordering
compsyLower [Char]
x [Char]
y
compsy (Label [Char]
x) (Label [Char]
y) = [Char] -> [Char] -> Ordering
compsyLower [Char]
x [Char]
y
compsy (Special Special
_) Symbol
_ = Ordering
LT
compsy Symbol
_ (Special Special
_) = Ordering
GT
compsy (Integ Int
_) Symbol
_ = Ordering
LT
compsy Symbol
_ (Integ Int
_) = Ordering
GT
compsy (Variable [Char]
_) Symbol
_ = Ordering
LT
compsy Symbol
_ (Variable [Char]
_) = Ordering
GT
compsy (Label [Char]
_) Symbol
_ = Ordering
LT
compsy Symbol
_ (Label [Char]
_) = Ordering
GT
compsy Symbol
Empty Symbol
Empty = Ordering
EQ
compsyLower :: String -> String -> Ordering
compsyLower :: [Char] -> [Char] -> Ordering
compsyLower [Char]
x [Char]
y = case forall a. Ord a => a -> a -> Ordering
compare (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower [Char]
x) (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower [Char]
y) of
Ordering
EQ -> forall a. Ord a => a -> a -> Ordering
compare [Char]
x [Char]
y
Ordering
other -> Ordering
other