aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/platform/compiler/name.lux
blob: 184b2cab5519921303c2d4e03a1e639d3948c366 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)))