aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/compiler/default/name.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/compiler/default/name.lux')
-rw-r--r--stdlib/source/lux/compiler/default/name.lux48
1 files changed, 48 insertions, 0 deletions
diff --git a/stdlib/source/lux/compiler/default/name.lux b/stdlib/source/lux/compiler/default/name.lux
new file mode 100644
index 000000000..f6489b89c
--- /dev/null
+++ b/stdlib/source/lux/compiler/default/name.lux
@@ -0,0 +1,48 @@
+(.module:
+ [lux #*
+ [data
+ ["." maybe]
+ ["." text
+ format]]])
+
+(def: (sanitize 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: #export (normalize name)
+ (-> Text Text)
+ (let [name/size (text.size name)]
+ (loop [idx +0
+ output ""]
+ (if (n/< name/size idx)
+ (recur (inc idx)
+ (|> (text.nth idx name) maybe.assume sanitize (format output)))
+ output))))
+
+(def: #export (definition [module name])
+ (-> Ident Text)
+ (format (normalize module) "___" (normalize name)))