-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathstxutil.ss
38 lines (34 loc) · 1.42 KB
/
stxutil.ss
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
;;; -*- Gerbil -*-
;;; © vyzo
;;; syntax utilities; import for-syntax
(import :gerbil/expander
:std/format)
(export #t)
;; format an identifier; see also stx-identifier
;; ctx := template identifier
;; fmt := format string
;; args := format arguments, may be syntax objects
(def (format-id ctx fmt . args)
(datum->syntax ctx (string->symbol (apply format fmt (map stx-e args)))
(stx-source ctx)))
;; TODO: delete after v0.18 -- for temporary compatibility only
(defalias displayify display-as-string)
(defalias stringify as-string)
(defalias symbolify make-symbol)
(defalias identifierify stx-identifier)
;; Use maybe-make-symbol instead of make-symbol to avoid DoS attacks
;; that cause you to intern too many symbols and run out of memory.
;; : (Or Symbol String) <- StringDesignator ...
(def maybe-make-symbol
(case-lambda ((x) (if (interned-symbol? x) x
(let (s (as-string x))
(or (##find-interned-symbol s) s))))
(x (maybe-make-symbol (as-string x)))))
;; Use maybe-make-keyword instead of make-keyword to avoid DoS attacks
;; that cause you to intern too many keywords and run out of memory.
;; : (Or Keyword String) <- StringDesignator ...
(def maybe-make-keyword
(case-lambda ((x) (if (interned-keyword? x) x
(let (s (as-string x))
(or (##find-interned-keyword s) s))))
(x (maybe-make-keyword (as-string x)))))