module Agda.Syntax.Concrete.Glyph
( UnicodeOrAscii(..)
, unsafeSetUnicodeOrAscii
, specialCharactersForGlyphs
, braces', dbraces
, forallQ
, leftIdiomBrkt, rightIdiomBrkt, emptyIdiomBrkt
, arrow, lambda
, SpecialCharacters(..)
) where
import Control.DeepSeq
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import qualified System.IO.Unsafe as UNSAFE (unsafePerformIO)
import GHC.Generics (Generic)
import Agda.Utils.List
import Agda.Utils.Null
import Agda.Utils.Pretty
data UnicodeOrAscii
= UnicodeOk
| AsciiOnly
deriving (Int -> UnicodeOrAscii -> ShowS
[UnicodeOrAscii] -> ShowS
UnicodeOrAscii -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnicodeOrAscii] -> ShowS
$cshowList :: [UnicodeOrAscii] -> ShowS
show :: UnicodeOrAscii -> String
$cshow :: UnicodeOrAscii -> String
showsPrec :: Int -> UnicodeOrAscii -> ShowS
$cshowsPrec :: Int -> UnicodeOrAscii -> ShowS
Show, UnicodeOrAscii -> UnicodeOrAscii -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnicodeOrAscii -> UnicodeOrAscii -> Bool
$c/= :: UnicodeOrAscii -> UnicodeOrAscii -> Bool
== :: UnicodeOrAscii -> UnicodeOrAscii -> Bool
$c== :: UnicodeOrAscii -> UnicodeOrAscii -> Bool
Eq, Int -> UnicodeOrAscii
UnicodeOrAscii -> Int
UnicodeOrAscii -> [UnicodeOrAscii]
UnicodeOrAscii -> UnicodeOrAscii
UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
UnicodeOrAscii
-> UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: UnicodeOrAscii
-> UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
$cenumFromThenTo :: UnicodeOrAscii
-> UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
enumFromTo :: UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
$cenumFromTo :: UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
enumFromThen :: UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
$cenumFromThen :: UnicodeOrAscii -> UnicodeOrAscii -> [UnicodeOrAscii]
enumFrom :: UnicodeOrAscii -> [UnicodeOrAscii]
$cenumFrom :: UnicodeOrAscii -> [UnicodeOrAscii]
fromEnum :: UnicodeOrAscii -> Int
$cfromEnum :: UnicodeOrAscii -> Int
toEnum :: Int -> UnicodeOrAscii
$ctoEnum :: Int -> UnicodeOrAscii
pred :: UnicodeOrAscii -> UnicodeOrAscii
$cpred :: UnicodeOrAscii -> UnicodeOrAscii
succ :: UnicodeOrAscii -> UnicodeOrAscii
$csucc :: UnicodeOrAscii -> UnicodeOrAscii
Enum, UnicodeOrAscii
forall a. a -> a -> Bounded a
maxBound :: UnicodeOrAscii
$cmaxBound :: UnicodeOrAscii
minBound :: UnicodeOrAscii
$cminBound :: UnicodeOrAscii
Bounded, forall x. Rep UnicodeOrAscii x -> UnicodeOrAscii
forall x. UnicodeOrAscii -> Rep UnicodeOrAscii x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UnicodeOrAscii x -> UnicodeOrAscii
$cfrom :: forall x. UnicodeOrAscii -> Rep UnicodeOrAscii x
Generic)
instance NFData UnicodeOrAscii
{-# NOINLINE unsafeUnicodeOrAsciiIORef #-}
unsafeUnicodeOrAsciiIORef :: IORef UnicodeOrAscii
unsafeUnicodeOrAsciiIORef :: IORef UnicodeOrAscii
unsafeUnicodeOrAsciiIORef = forall a. IO a -> a
UNSAFE.unsafePerformIO forall a b. (a -> b) -> a -> b
$ forall a. a -> IO (IORef a)
newIORef UnicodeOrAscii
UnicodeOk
{-# NOINLINE unsafeSetUnicodeOrAscii #-}
unsafeSetUnicodeOrAscii :: UnicodeOrAscii -> IO ()
unsafeSetUnicodeOrAscii :: UnicodeOrAscii -> IO ()
unsafeSetUnicodeOrAscii = forall a. IORef a -> a -> IO ()
writeIORef IORef UnicodeOrAscii
unsafeUnicodeOrAsciiIORef
unsafeUnicodeOrAscii :: UnicodeOrAscii
unsafeUnicodeOrAscii :: UnicodeOrAscii
unsafeUnicodeOrAscii = forall a. IO a -> a
UNSAFE.unsafePerformIO (forall a. IORef a -> IO a
readIORef IORef UnicodeOrAscii
unsafeUnicodeOrAsciiIORef)
data SpecialCharacters = SpecialCharacters
{ SpecialCharacters -> Doc -> Doc
_dbraces :: Doc -> Doc
, SpecialCharacters -> Doc
_lambda :: Doc
, SpecialCharacters -> Doc
_arrow :: Doc
, SpecialCharacters -> Doc
_forallQ :: Doc
, SpecialCharacters -> Doc
_leftIdiomBrkt :: Doc
, SpecialCharacters -> Doc
_rightIdiomBrkt :: Doc
, SpecialCharacters -> Doc
_emptyIdiomBrkt :: Doc
}
specialCharactersUnicode :: SpecialCharacters
specialCharactersUnicode :: SpecialCharacters
specialCharactersUnicode = SpecialCharacters
{ _dbraces :: Doc -> Doc
_dbraces = ((Doc
"\x2983 " forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Semigroup a => a -> a -> a
<> Doc
" \x2984"))
, _lambda :: Doc
_lambda = Doc
"\x03bb"
, _arrow :: Doc
_arrow = Doc
"\x2192"
, _forallQ :: Doc
_forallQ = Doc
"\x2200"
, _leftIdiomBrkt :: Doc
_leftIdiomBrkt = Doc
"\x2987"
, _rightIdiomBrkt :: Doc
_rightIdiomBrkt = Doc
"\x2988"
, _emptyIdiomBrkt :: Doc
_emptyIdiomBrkt = Doc
"\x2987\x2988"
}
specialCharactersAscii :: SpecialCharacters
specialCharactersAscii :: SpecialCharacters
specialCharactersAscii = SpecialCharacters
{ _dbraces :: Doc -> Doc
_dbraces = Doc -> Doc
braces forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
braces'
, _lambda :: Doc
_lambda = Doc
"\\"
, _arrow :: Doc
_arrow = Doc
"->"
, _forallQ :: Doc
_forallQ = Doc
"forall"
, _leftIdiomBrkt :: Doc
_leftIdiomBrkt = Doc
"(|"
, _rightIdiomBrkt :: Doc
_rightIdiomBrkt = Doc
"|)"
, _emptyIdiomBrkt :: Doc
_emptyIdiomBrkt = Doc
"(|)"
}
specialCharactersForGlyphs :: UnicodeOrAscii -> SpecialCharacters
specialCharactersForGlyphs :: UnicodeOrAscii -> SpecialCharacters
specialCharactersForGlyphs UnicodeOrAscii
UnicodeOk = SpecialCharacters
specialCharactersUnicode
specialCharactersForGlyphs UnicodeOrAscii
AsciiOnly = SpecialCharacters
specialCharactersAscii
{-# NOINLINE specialCharacters #-}
specialCharacters :: SpecialCharacters
specialCharacters :: SpecialCharacters
specialCharacters = UnicodeOrAscii -> SpecialCharacters
specialCharactersForGlyphs UnicodeOrAscii
unsafeUnicodeOrAscii
braces' :: Doc -> Doc
braces' :: Doc -> Doc
braces' Doc
d = forall a b. [a] -> b -> (a -> [a] -> b) -> b
caseList (Doc -> String
render Doc
d) (Doc -> Doc
braces Doc
d) forall a b. (a -> b) -> a -> b
$ \ Char
c String
cs ->
Doc -> Doc
braces (forall {a}. (IsString a, Null a) => Char -> a
spaceIfDash Char
c forall a. Semigroup a => a -> a -> a
<> Doc
d forall a. Semigroup a => a -> a -> a
<> forall {a}. (IsString a, Null a) => Char -> a
spaceIfDash (forall a. a -> [a] -> a
last1 Char
c String
cs))
where
spaceIfDash :: Char -> a
spaceIfDash Char
'-' = a
" "
spaceIfDash Char
_ = forall a. Null a => a
empty
dbraces :: Doc -> Doc
dbraces :: Doc -> Doc
dbraces = SpecialCharacters -> Doc -> Doc
_dbraces SpecialCharacters
specialCharacters
forallQ :: Doc
forallQ :: Doc
forallQ = SpecialCharacters -> Doc
_forallQ SpecialCharacters
specialCharacters
leftIdiomBrkt, rightIdiomBrkt, emptyIdiomBrkt :: Doc
leftIdiomBrkt :: Doc
leftIdiomBrkt = SpecialCharacters -> Doc
_leftIdiomBrkt SpecialCharacters
specialCharacters
rightIdiomBrkt :: Doc
rightIdiomBrkt = SpecialCharacters -> Doc
_rightIdiomBrkt SpecialCharacters
specialCharacters
emptyIdiomBrkt :: Doc
emptyIdiomBrkt = SpecialCharacters -> Doc
_emptyIdiomBrkt SpecialCharacters
specialCharacters
arrow, lambda :: Doc
arrow :: Doc
arrow = SpecialCharacters -> Doc
_arrow SpecialCharacters
specialCharacters
lambda :: Doc
lambda = SpecialCharacters -> Doc
_lambda SpecialCharacters
specialCharacters