Tested and fixed rest and #:rest

This commit is contained in:
Georges Dupéron 2016-09-22 04:21:41 +02:00
parent c3ee40168c
commit b1c58b37e5
4 changed files with 48 additions and 7 deletions

View File

@ -178,6 +178,8 @@
#'Null]
[rest:not-stx-list
#'rest]
[(#:rest rest)
#'rest]
[(stop . rest) ;; eliminate the private marker
(xl #'rest)]
[(s:with-superscripts . rest)
@ -240,6 +242,8 @@
#'(list)]
[rest:not-stx-list
#'rest]
[(#:rest rest)
#'rest]
[(stop . rest) ;; eliminate the private marker
(xl #'rest)]
[(({~literal unquote-splicing} splice) …+ . rest)

View File

@ -21,12 +21,13 @@ To use the type expander, you must first require the
@deftogether[
[@defform*[#:kind "type-expander"
[(xList τᵢ …)
(xList τᵢ … . rest)]]
[(xList τᵢ ...)
(xList τᵢ ... . rest)
(xList τᵢ ... #:rest . rest)]]
@defform*[#:kind "type-expander"
#:literals (^ *)
[(xlist τᵢ )
(xlist τᵢ . rest)]
[(xlist τᵢ ...)
(xlist τᵢ ... . rest)]
#:grammar
[(τᵢ type
repeated-type)
@ -130,7 +131,8 @@ To use the type expander, you must first require the
#:link-target? #f
#:literals (^ *)
[(xlist patᵢ ...)
(xlist patᵢ ... . rest)]
(xlist patᵢ ... . rest)
(xList patᵢ ... #:rest . rest)]
#:grammar
[(patᵢ pattern-or-spliced
repeated-pattern
@ -202,8 +204,8 @@ To use the type expander, you must first require the
@;{This is completely wrong.
@defform*[#:link-target? #f
#:literals (^ *)
[(xlist τᵢ … maybe-τⱼ τₖ … maybe-τₙ)
(xlist τᵢ τₘᵥ)]
[(xlist τᵢ ... maybe-τⱼ τₖ ... maybe-τₙ)
(xlist τᵢ ... τₘᵥ)]
#:grammar
[(τᵢ type
fixed-repeated-type)

View File

@ -19,6 +19,22 @@
(define-syntax-rule (check-not-match? v pat)
(check-false (match v [pat #t] [_ #f])))
(test-begin
"(xlist . single-pat)"
;; Need a not-yet-accepted PR in Racket.
;(check-match? '() (xlist . null?))
;(check-match? '1 (xlist . 1))
;(check-match? '1 (xlist . number?))
(void))
(test-begin
"(xlist #:rest . pat)"
(check-match '() [(xlist #:rest (? null? v)) v] '())
(check-match '1 [(xlist #:rest (and 1 v)) v] 1)
(check-match '1 [(xlist #:rest (? number? v)) v] 1)
(check-match #(1 "b") [(xlist #:rest (vector (? number? n) (? string? s))) (cons n s)] '(1 . "b"))
(void))
(test-begin
"(xlist 1 2 3 4 5)"
(check-match? '() (xlist))

View File

@ -4,6 +4,25 @@
type-expander
typed/rackunit)
(define-type VectorNS (Vector Number String))
(test-begin
"(xlist . single-type)"
(ann '() (xlist . Null))
(ann '1 (xlist . 1))
(ann '1 (xlist . Number))
(ann #(1 "b") (xlist . VectorNS))
(void))
(test-begin
"(xlist #:rest . type)"
(ann '() (xlist #:rest Null))
(ann '1 (xlist #:rest 1))
(ann '1 (xlist #:rest Number))
(ann #(1 "b") (xlist #:rest (Vector Number String)))
(void))
(test-begin
"(xlist 1 2 3 4 5)"
(ann '() (xlist))