on master help sign in
javascript: filter all nonascii letters from identifiers
fe570cbraichoo
src/IRTS/CodegenJavaScript.hs+1−28
@@ -53,36 +53,9 @@ translateIdentifier :: String -> String
53translateIdentifier =
53translateIdentifier =
54 replaceReserved . concatMap replaceBadChars
54 replaceReserved . concatMap replaceBadChars
55 where replaceBadChars :: Char -> String
55 where replaceBadChars :: Char -> String
56− replaceBadChars ' ' = "_"
57− replaceBadChars '_' = "__"
58− replaceBadChars '@' = "_at"
59− replaceBadChars '[' = "_OSB"
60− replaceBadChars ']' = "_CSB"
61− replaceBadChars '(' = "_OP"
62− replaceBadChars ')' = "_CP"
63− replaceBadChars '{' = "_OB"
64− replaceBadChars '}' = "_CB"
65− replaceBadChars '!' = "_bang"
66− replaceBadChars '#' = "_hash"
67− replaceBadChars '.' = "_dot"
68− replaceBadChars ',' = "_comma"
69− replaceBadChars ':' = "_colon"
70− replaceBadChars '+' = "_plus"
71− replaceBadChars '-' = "_minus"
72− replaceBadChars '*' = "_times"
73− replaceBadChars '<' = "_lt"
74− replaceBadChars '>' = "_gt"
75− replaceBadChars '=' = "_eq"
76− replaceBadChars '|' = "_pipe"
77− replaceBadChars '&' = "_amp"
78− replaceBadChars '/' = "_SL"
79− replaceBadChars '\\' = "_BSL"
80− replaceBadChars '%' = "_per"
81− replaceBadChars '?' = "_que"
82− replaceBadChars '~' = "_til"
83− replaceBadChars '\'' = "_apo"
84 replaceBadChars c
56 replaceBadChars c
85 | isDigit c = "_" ++ [c] ++ "_"
57 | isDigit c = "_" ++ [c] ++ "_"
58+ | not (isLetter c && isAscii c) = '_' : show (ord c)
86 | otherwise = [c]
59 | otherwise = [c]
87 replaceReserved s
60 replaceReserved s
88 | s `elem` reserved = '_' : s
61 | s `elem` reserved = '_' : s