1
0
mirror of https://github.com/janet-lang/janet synced 2024-09-16 01:09:37 +00:00
janet/grammar/tmcorelib.janet

31 lines
601 B
Plaintext
Raw Normal View History

2018-12-16 22:59:16 +00:00
# Helper to generate core library mappings for janet
(def allsyms (all-symbols))
(def- escapes
{(get "|" 0) `\|`
(get "-" 0) `\-`
(get "+" 0) `\+`
(get "*" 0) `\*`
(get "^" 0) `\^`
(get "$" 0) `\$`
(get "?" 0) `\?`
38 "&"
60 "<"
62 ">"
34 """
39 "'"
47 "/"})
(defn- escape
2018-12-17 02:30:58 +00:00
"Escape special characters for HTML and regex encoding."
2018-12-16 22:59:16 +00:00
[str]
(def buf @"")
(loop [byte :in str]
(if-let [rep escapes.byte]
(buffer/push-string buf rep)
(buffer/push-byte buf byte)))
buf)
(print (string/join (map escape allsyms)) "|"))