string/nat lit stuff
This commit is contained in:
parent
3b9a339e5e
commit
e211887a34
5 changed files with 146 additions and 41 deletions
|
@ -7,6 +7,7 @@ import Quox.Pretty
|
|||
|
||||
import Quox.EffExtra
|
||||
import Quox.CharExtra
|
||||
import Quox.NatExtra
|
||||
import Data.DPair
|
||||
import Data.List1
|
||||
import Data.String
|
||||
|
@ -278,28 +279,16 @@ prelude = """
|
|||
;;;;;;
|
||||
"""
|
||||
|
||||
export
|
||||
toHex : Int -> String
|
||||
toHex x =
|
||||
case toHex' x of
|
||||
[<] => "0"
|
||||
cs => concatMap singleton cs
|
||||
where
|
||||
toHex' : Int -> SnocList Char
|
||||
toHex' x =
|
||||
if x == 0 then [<] else
|
||||
let d = x `div` 16
|
||||
m = x `mod` 16 in
|
||||
toHex' (assert_smaller x d) :<
|
||||
assert_total strIndex "0123456789abcdef" m
|
||||
|
||||
export
|
||||
escape : String -> String
|
||||
escape = concatMap esc1 . unpack where
|
||||
escape = foldMap esc1 . unpack where
|
||||
esc1 : Char -> String
|
||||
esc1 c = if c < ' ' || c > '~' || c == '\\' || c == '"'
|
||||
then "\\x" ++ toHex (ord c) ++ ";"
|
||||
else singleton c
|
||||
esc1 c =
|
||||
if c == '\\' || c == '"' then
|
||||
"\\" ++ singleton c
|
||||
else if c < ' ' || c > '~' then
|
||||
"\\x" ++ showHex (ord c) ++ ";"
|
||||
else singleton c
|
||||
|
||||
export covering
|
||||
defToScheme : Name -> Definition -> Eff Scheme (Maybe Sexp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue