diff --git a/collects/redex/private/rewrite-side-conditions.rkt b/collects/redex/private/rewrite-side-conditions.rkt index a0b80be5c8..4e73f23296 100644 --- a/collects/redex/private/rewrite-side-conditions.rkt +++ b/collects/redex/private/rewrite-side-conditions.rkt @@ -215,6 +215,7 @@ (define prefix-stx (datum->syntax term prefix-sym)) (define mismatch? (regexp-match? #rx"^!_" suffix)) (cond + [(eq? (syntax-e term) '_) (values `any '())] ;; don't bind wildcard [(eq? prefix-sym '...) (raise-syntax-error what diff --git a/collects/redex/scribblings/ref.scrbl b/collects/redex/scribblings/ref.scrbl index 078a4e9364..8473a06e58 100644 --- a/collects/redex/scribblings/ref.scrbl +++ b/collects/redex/scribblings/ref.scrbl @@ -101,6 +101,7 @@ in the grammar are terminals. @(racketgrammar* #;#:literals #;(any number string variable variable-except variable-prefix variable-not-otherwise-mentioned hole hide-hole name in-hole side-condition cross) [pattern any + _ number natural integer @@ -134,6 +135,10 @@ were an implicit @pattech[name] @pattern) and match the portion before the underscore. } +@item{The @defpattech[_] @pattern matches any sexpression, +but does not bind $pattech[_] as a name, nor can it be suffixed to bind a name. +} + @item{The @defpattech[number] @pattern matches any number. This @pattern may also be suffixed with an underscore and another identifier, in which case they bind the full name (as if it diff --git a/collects/redex/tests/rewrite-side-condition-test.rkt b/collects/redex/tests/rewrite-side-condition-test.rkt index 494ea84fb3..5c549bc8e8 100644 --- a/collects/redex/tests/rewrite-side-condition-test.rkt +++ b/collects/redex/tests/rewrite-side-condition-test.rkt @@ -22,6 +22,7 @@ (check-equal? (rsc 1 () #t) `(1 () ())) (check-equal? (rsc (1) () #t) `((list 1) () ())) +(check-equal? (rsc (_ _ (name x _)) () #t) `((list any any (name x any)) (x) (x))) (check-equal? (rsc (1 ...) () #t) `((list (repeat 1 #f #f)) () ())) (check-equal? (rsc (1 ..._2) () #t) `((list (repeat 1 #f #f)) () ())) (check-equal? (rsc (1 ..._2 1 ..._2) () #t) `((list (repeat 1 ..._2 #f) (repeat 1 ..._2 #f)) () ())) @@ -68,8 +69,6 @@ '(list (repeat (name x_1 (nt x)) ..._2 #f) (repeat (name x (nt x)) ..._2 #f) (repeat (name x_1 (nt x)) ..._2 #f))) - - (check-equal? (car (rsc (x_1 ..._1 x_2 ..._2 (x_1 x_2) ..._3) (x) #t)) '(list (repeat (name x_1 (nt x)) ..._3 #f) (repeat (name x_2 (nt x)) ..._3 #f)