commit b1c58b37e599806a4ffdf998fd1379f66c209e73
parent c3ee40168cc8c2e598306cf2fab3aa54d0bb245a
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Thu, 22 Sep 2016 04:21:41 +0200
Tested and fixed rest and #:rest
Diffstat:
4 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/main.rkt b/main.rkt
@@ -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)
diff --git a/scribblings/xlist.scrbl b/scribblings/xlist.scrbl
@@ -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)
diff --git a/test/test-match.rkt b/test/test-match.rkt
@@ -20,6 +20,22 @@
(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))
(check-match? '(1) (xlist 1))
diff --git a/test/test-type.rkt b/test/test-type.rkt
@@ -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))