aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/platform/compiler/name.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/platform/compiler/name.lux')
-rw-r--r--stdlib/source/lux/platform/compiler/name.lux47
1 files changed, 47 insertions, 0 deletions
diff --git a/stdlib/source/lux/platform/compiler/name.lux b/stdlib/source/lux/platform/compiler/name.lux
new file mode 100644
index 000000000..184b2cab5
--- /dev/null
+++ b/stdlib/source/lux/platform/compiler/name.lux
@@ -0,0 +1,47 @@
+(.module:
+ [lux #*
+ [data
+ ["." maybe]
+ ["." text
+ format]]])
+
+(`` (template: (!sanitize char)
+ ("lux syntax char case!" char
+ [["*"] "_ASTER_"
+ ["+"] "_PLUS_"
+ ["-"] "_DASH_"
+ ["/"] "_SLASH_"
+ ["\"] "_BSLASH_"
+ ["_"] "_UNDERS_"
+ ["%"] "_PERCENT_"
+ ["$"] "_DOLLAR_"
+ ["'"] "_QUOTE_"
+ ["`"] "_BQUOTE_"
+ ["@"] "_AT_"
+ ["^"] "_CARET_"
+ ["&"] "_AMPERS_"
+ ["="] "_EQ_"
+ ["!"] "_BANG_"
+ ["?"] "_QM_"
+ [":"] "_COLON_"
+ ["."] "_PERIOD_"
+ [","] "_COMMA_"
+ ["<"] "_LT_"
+ [">"] "_GT_"
+ ["~"] "_TILDE_"
+ ["|"] "_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)
+ (|> ("lux text char" name idx) !sanitize (format output)))
+ output))))
+
+(def: #export (definition [module short])
+ (-> Name Text)
+ (format (normalize module) "___" (normalize short)))