module Language.Drasil.Symbol.Helpers(eqSymb, codeSymb, hasStageSymbol,
autoStage, hat, prime, staged, sub, subStr, sup, unicodeConv, upperLeft,
vec, label, variable) where
import Data.Char (isLatin1, toLower)
import Data.Char.Properties.Names (getCharacterName)
import Data.List.Split (splitOn)
import Language.Drasil.Symbol (HasSymbol(symbol), Symbol(..), Decoration(..))
import Language.Drasil.Stages (Stage(Equational,Implementation))
neSymb :: (String -> Symbol) -> String -> String -> Symbol
neSymb :: (String -> Symbol) -> String -> String -> Symbol
neSymb String -> Symbol
_ String
s [] = String -> Symbol
forall a. HasCallStack => String -> a
error (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" names must be non-empty"
neSymb String -> Symbol
sy String
_ String
s = String -> Symbol
sy String
s
label :: String -> Symbol
label :: String -> Symbol
label = (String -> Symbol) -> String -> String -> Symbol
neSymb String -> Symbol
Label String
"label"
variable :: String -> Symbol
variable :: String -> Symbol
variable = (String -> Symbol) -> String -> String -> Symbol
neSymb String -> Symbol
Variable String
"variable"
eqSymb :: HasSymbol q => q -> Symbol
eqSymb :: forall q. HasSymbol q => q -> Symbol
eqSymb q
c = q -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol q
c Stage
Equational
codeSymb :: HasSymbol q => q -> Symbol
codeSymb :: forall q. HasSymbol q => q -> Symbol
codeSymb q
c = q -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol q
c Stage
Implementation
hasStageSymbol :: HasSymbol q => q -> Stage -> Bool
hasStageSymbol :: forall q. HasSymbol q => q -> Stage -> Bool
hasStageSymbol q
q Stage
st = q -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol q
q Stage
st Symbol -> Symbol -> Bool
forall a. Eq a => a -> a -> Bool
/= Symbol
Empty
upperLeft :: Symbol -> Symbol -> Symbol
upperLeft :: Symbol -> Symbol -> Symbol
upperLeft Symbol
b Symbol
ul = [Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners [Symbol
ul] [] [] [] Symbol
b
sub :: Symbol -> Symbol -> Symbol
sub :: Symbol -> Symbol -> Symbol
sub Symbol
b Symbol
lr = [Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners [] [] [] [Symbol
lr] Symbol
b
subStr :: Symbol -> String -> Symbol
subStr :: Symbol -> String -> Symbol
subStr Symbol
sym String
substr = Symbol -> Symbol -> Symbol
sub Symbol
sym (Symbol -> Symbol) -> Symbol -> Symbol
forall a b. (a -> b) -> a -> b
$ String -> Symbol
Label String
substr
sup :: Symbol -> Symbol -> Symbol
sup :: Symbol -> Symbol -> Symbol
sup Symbol
b Symbol
ur = [Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners [] [] [Symbol
ur] [] Symbol
b
hat :: Symbol -> Symbol
hat :: Symbol -> Symbol
hat = Decoration -> Symbol -> Symbol
Atop Decoration
Hat
vec :: Symbol -> Symbol
vec :: Symbol -> Symbol
vec = Decoration -> Symbol -> Symbol
Atop Decoration
Vector
prime :: Symbol -> Symbol
prime :: Symbol -> Symbol
prime = Decoration -> Symbol -> Symbol
Atop Decoration
Prime
staged :: Symbol -> Symbol -> Stage -> Symbol
staged :: Symbol -> Symbol -> Stage -> Symbol
staged Symbol
eqS Symbol
_ Stage
Equational = Symbol
eqS
staged Symbol
_ Symbol
impS Stage
Implementation = Symbol
impS
autoStage :: Symbol -> (Stage -> Symbol)
autoStage :: Symbol -> Stage -> Symbol
autoStage Symbol
s = Symbol -> Symbol -> Stage -> Symbol
staged Symbol
s (Symbol -> Symbol
unicodeConv Symbol
s)
unicodeConv :: Symbol -> Symbol
unicodeConv :: Symbol -> Symbol
unicodeConv (Variable String
st) = String -> Symbol
Variable (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String -> String
unicodeString String
st
unicodeConv (Label String
st) = String -> Symbol
Label (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String -> String
unicodeString String
st
unicodeConv (Atop Decoration
d Symbol
s) = Decoration -> Symbol -> Symbol
Atop Decoration
d (Symbol -> Symbol) -> Symbol -> Symbol
forall a b. (a -> b) -> a -> b
$ Symbol -> Symbol
unicodeConv Symbol
s
unicodeConv (Corners [Symbol]
a [Symbol]
b [Symbol]
c [Symbol]
d Symbol
s) =
[Symbol] -> [Symbol] -> [Symbol] -> [Symbol] -> Symbol -> Symbol
Corners ((Symbol -> Symbol) -> [Symbol] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
a) ((Symbol -> Symbol) -> [Symbol] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
b) ((Symbol -> Symbol) -> [Symbol] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
c) ((Symbol -> Symbol) -> [Symbol] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
d) (Symbol -> Symbol
unicodeConv Symbol
s)
unicodeConv (Concat [Symbol]
ss) = [Symbol] -> Symbol
Concat ([Symbol] -> Symbol) -> [Symbol] -> Symbol
forall a b. (a -> b) -> a -> b
$ (Symbol -> Symbol) -> [Symbol] -> [Symbol]
forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
ss
unicodeConv Symbol
x = Symbol
x
unicodeString :: String -> String
unicodeString :: String -> String
unicodeString = (Char -> String) -> String -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Char
x -> if Char -> Bool
isLatin1 Char
x then [Char
x] else [String] -> String
getName ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ Char -> [String]
nameList Char
x)
where
nameList :: Char -> [String]
nameList = String -> String -> [String]
forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
" " (String -> [String]) -> (Char -> String) -> Char -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (String -> String) -> (Char -> String) -> Char -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> String
getCharacterName
getName :: [String] -> String
getName (String
"greek":String
_:String
_:[String]
name) = [String] -> String
unwords [String]
name
getName [String]
_ = String -> String
forall a. HasCallStack => String -> a
error String
"unicodeString not fully implemented"