(.module: lux (lux (control [monad #+ do] ["ex" exception #+ exception:]) (data [maybe] [product] ["e" error] [text "text/" Eq] text/format (coll [list])) [macro] (macro ["s" syntax #+ syntax:]) (lang (type ["tc" check]))) (luxc (lang ["la" analysis]))) (def: (normalize-char char) (-> Nat Text) (case char (^ (char "*")) "_ASTER_" (^ (char "+")) "_PLUS_" (^ (char "-")) "_DASH_" (^ (char "/")) "_SLASH_" (^ (char "\\")) "_BSLASH_" (^ (char "_")) "_UNDERS_" (^ (char "%")) "_PERCENT_" (^ (char "$")) "_DOLLAR_" (^ (char "'")) "_QUOTE_" (^ (char "`")) "_BQUOTE_" (^ (char "@")) "_AT_" (^ (char "^")) "_CARET_" (^ (char "&")) "_AMPERS_" (^ (char "=")) "_EQ_" (^ (char "!")) "_BANG_" (^ (char "?")) "_QM_" (^ (char ":")) "_COLON_" (^ (char ".")) "_PERIOD_" (^ (char ",")) "_COMMA_" (^ (char "<")) "_LT_" (^ (char ">")) "_GT_" (^ (char "~")) "_TILDE_" (^ (char "|")) "_PIPE_" _ (text.from-code char))) (def: underflow Nat (n/dec +0)) (def: #export (normalize-name name) (-> Text Text) (loop [idx (n/dec (text.size name)) output ""] (if (n/= underflow idx) output (recur (n/dec idx) (format (|> (text.nth idx name) maybe.assume normalize-char) output))))) (exception: #export (Error {message Text}) message) (def: #export (with-error-tracking action) (All [a] (-> (Meta a) (Meta a))) (function (_ compiler) (case (action compiler) (#e.Error error) ((throw Error error) compiler) output output)))