0 | module Language.JSON.String.Tokens
3 | import Data.String.Extra
9 | data JSONStringTokenKind
16 | JSONStringToken : Type
17 | JSONStringToken = Token JSONStringTokenKind
20 | Eq JSONStringTokenKind where
21 | (==) JSTQuote JSTQuote = True
22 | (==) JSTChar JSTChar = True
23 | (==) JSTSimpleEscape JSTSimpleEscape = True
24 | (==) JSTUnicodeEscape JSTUnicodeEscape = True
28 | charValue : String -> Char
29 | charValue x = case index 0 x of
34 | simpleEscapeValue : String -> Char
50 | unicodeEscapeValue : String -> Char
51 | unicodeEscapeValue x = fromHex (drop 2 $
fastUnpack x) 0
52 | where hexVal : Char -> Int
53 | hexVal c = if c >= 'A'
54 | then ord c - ord 'A' + 10
55 | else ord c - ord '0'
57 | fromHex : List Char -> Int -> Char
58 | fromHex [] acc = chr acc
59 | fromHex (h :: t) acc = fromHex t (hexVal h + 16 * acc)
62 | TokenKind JSONStringTokenKind where
63 | TokType JSTQuote = ()
64 | TokType JSTChar = Char
65 | TokType JSTSimpleEscape = Char
66 | TokType JSTUnicodeEscape = Char
68 | tokValue JSTQuote = const ()
69 | tokValue JSTChar = charValue
70 | tokValue JSTSimpleEscape = simpleEscapeValue
71 | tokValue JSTUnicodeEscape = unicodeEscapeValue