Superficial pattern for wildcard that doesn't bind.
This commit is contained in:
parent
e25156d67f
commit
214bc7089b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user