Superficial pattern for wildcard that doesn't bind.

This commit is contained in:
J. Ian Johnson 2013-06-07 12:15:53 -04:00
parent e25156d67f
commit 214bc7089b
3 changed files with 7 additions and 2 deletions

View File

@ -215,6 +215,7 @@
(define prefix-stx (datum->syntax term prefix-sym)) (define prefix-stx (datum->syntax term prefix-sym))
(define mismatch? (regexp-match? #rx"^!_" suffix)) (define mismatch? (regexp-match? #rx"^!_" suffix))
(cond (cond
[(eq? (syntax-e term) '_) (values `any '())] ;; don't bind wildcard
[(eq? prefix-sym '...) [(eq? prefix-sym '...)
(raise-syntax-error (raise-syntax-error
what what

View File

@ -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) @(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 [pattern any
_
number number
natural natural
integer integer
@ -134,6 +135,10 @@ were an implicit @pattech[name] @pattern) and match the portion
before the underscore. 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. @item{The @defpattech[number] @pattern matches any number.
This @pattern may also be suffixed with an underscore and another This @pattern may also be suffixed with an underscore and another
identifier, in which case they bind the full name (as if it identifier, in which case they bind the full name (as if it

View File

@ -22,6 +22,7 @@
(check-equal? (rsc 1 () #t) `(1 () ())) (check-equal? (rsc 1 () #t) `(1 () ()))
(check-equal? (rsc (1) () #t) `((list 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 ...) () #t) `((list (repeat 1 #f #f)) () ()))
(check-equal? (rsc (1 ..._2) () #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)) () ())) (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) '(list (repeat (name x_1 (nt x)) ..._2 #f)
(repeat (name x (nt x)) ..._2 #f) (repeat (name x (nt x)) ..._2 #f)
(repeat (name x_1 (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)) (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) '(list (repeat (name x_1 (nt x)) ..._3 #f)
(repeat (name x_2 (nt x)) ..._3 #f) (repeat (name x_2 (nt x)) ..._3 #f)