aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/name.lux
blob: 394bdb2db7111323bec7ac14c11ac50b7b784280 (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
       [["*"] "_AS"
        ["+"] "_PL"
        ["-"] "_DS"
        ["/"] "_SL"
        ["\"] "_BS"
        ["_"] "_US"
        ["%"] "_PC"
        ["$"] "_DL"
        ["'"] "_QU"
        ["`"] "_BQ"
        ["@"] "_AT"
        ["^"] "_CR"
        ["&"] "_AA"
        ["="] "_EQ"
        ["!"] "_BG"
        ["?"] "_QM"
        [":"] "_CO"
        ["."] "_PD"
        [","] "_CM"
        ["<"] "_LT"
        [">"] "_GT"
        ["~"] "_TI"
        ["|"] "_PI"]
       (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)))