Skip to content

Commit 2385dea

Browse files
committed
support more atomic rewriting
1 parent bd9d670 commit 2385dea

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

redex-doc/redex/scribblings/ref/typesetting.scrbl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,18 +1048,21 @@ The @racket[proc] must match the contract @racket[(-> lw? lw?)].
10481048
Its result should be the rewritten version version of the input.
10491049
}
10501050
1051-
@defform[(with-atomic-rewriter name-symbol
1051+
@defform[(with-atomic-rewriter atom-name
10521052
string-or-thunk-returning-pict
10531053
expression)]{
10541054
10551055
Extends the current set of atomic-rewriters with one
1056-
new one that rewrites the value of name-symbol to
1056+
new one that rewrites the value of atom-name to
10571057
@racket[string-or-pict-returning-thunk] (applied, in the case of a
10581058
thunk), during the evaluation of expression.
10591059
1060-
@racket[name-symbol] is expected to evaluate to a symbol. The value
1061-
of @racket[string-or-thunk-returning-pict] is used whenever the symbol
1062-
appears in a pattern.
1060+
@racket[atom-name] is expected to evaluate to a symbol or
1061+
string. Note that to rewrite other literals, the string
1062+
representation of that literal should be used (e.g.
1063+
@racket["#t"] as the atom-name to rewrite @racket[#t], etc).
1064+
The value of @racket[string-or-thunk-returning-pict] is used
1065+
that atom appears in a pattern.
10631066
10641067
@ex[
10651068
(define-language lam-lang
@@ -1071,7 +1074,7 @@ appears in a pattern.
10711074
]
10721075
}
10731076
1074-
@defform[(with-atomic-rewriters ([name-symbol string-or-thunk-returning-pict] ...)
1077+
@defform[(with-atomic-rewriters ([atom-name string-or-thunk-returning-pict] ...)
10751078
expression)]{
10761079
Shorthand for nested @racket[with-atomic-rewriter] expressions.
10771080
@history[#:added "1.4"]}

redex-pict-lib/redex/private/core-layout.rkt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
(syntax-parse stx
9696
[(_ ([name transformer] ...) e:expr)
9797
#:declare name
98-
(expr/c #'symbol?
98+
(expr/c #'(or/c symbol? string?)
9999
#:name "atomic-rewriter name")
100100
#:declare transformer
101101
(expr/c #'(or/c (-> pict?) string?)
@@ -803,7 +803,8 @@
803803
(string=? "#:" (substring atom 0 2))))
804804
(list (make-string-token col span atom (paren-style)))]
805805
[(string? atom)
806-
(list (make-string-token col span atom (default-style)))]
806+
(list (or (rewrite-atomic col span atom literal-style)
807+
(make-string-token col span atom (default-style))))]
807808
[else (error 'atom->tokens "unk ~s" atom)]))
808809

809810
(define (rewrite-atomic col span e get-style)
@@ -818,7 +819,7 @@
818819
[(assoc e (atomic-rewrite-table))
819820
=>
820821
(λ (m)
821-
(when (eq? (cadr m) e)
822+
(when (equal? (cadr m) e)
822823
(error 'apply-rewrites "rewritten version of ~s is still ~s" e e))
823824
(let ([p (cadr m)])
824825
(if (procedure? p)

0 commit comments

Comments
 (0)