From b1c58b37e599806a4ffdf998fd1379f66c209e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 22 Sep 2016 04:21:41 +0200 Subject: [PATCH] Tested and fixed rest and #:rest --- main.rkt | 4 ++++ scribblings/xlist.scrbl | 16 +++++++++------- test/test-match.rkt | 16 ++++++++++++++++ test/test-type.rkt | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/main.rkt b/main.rkt index a0d90d1..09e16af 100644 --- 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 index e1cc916..14a4211 100644 --- 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 index b9ccd01..3c32e7f 100644 --- a/test/test-match.rkt +++ b/test/test-match.rkt @@ -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)) diff --git a/test/test-type.rkt b/test/test-type.rkt index 46f100c..523511c 100644 --- 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))