2018-12-16 22:59:16 +00:00
|
|
|
# Helper to generate core library mappings for janet
|
2019-01-07 00:33:27 +00:00
|
|
|
# Used to help build the tmLanguage grammar.
|
2018-12-16 22:59:16 +00:00
|
|
|
|
|
|
|
(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]
|
2019-01-07 00:33:27 +00:00
|
|
|
(if-let [rep (get escapes byte)]
|
2018-12-16 22:59:16 +00:00
|
|
|
(buffer/push-string buf rep)
|
|
|
|
(buffer/push-byte buf byte)))
|
|
|
|
buf)
|
|
|
|
|
2018-12-17 03:21:48 +00:00
|
|
|
(print (string/join (map escape allsyms) "|"))
|