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 [] = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
s 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 = 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 = 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 = forall c. HasSymbol c => c -> Stage -> Symbol
symbol q
q Stage
st 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 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 forall a b. (a -> b) -> a -> b
$ String -> String
unicodeString String
st
unicodeConv (Label String
st) = String -> Symbol
Label forall a b. (a -> b) -> a -> b
$ String -> String
unicodeString String
st
unicodeConv (Atop Decoration
d Symbol
s) = Decoration -> Symbol -> Symbol
Atop Decoration
d 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 (forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
a) (forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
b) (forall a b. (a -> b) -> [a] -> [b]
map Symbol -> Symbol
unicodeConv [Symbol]
c) (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 forall a b. (a -> b) -> a -> b
$ 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 = 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 forall a b. (a -> b) -> a -> b
$ Char -> [String]
nameList Char
x)
where
nameList :: Char -> [String]
nameList = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower 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]
_ = forall a. HasCallStack => String -> a
error String
"unicodeString not fully implemented"