From cd2005e9af6bed499cc9a87f6b641125206aedc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Fri, 26 Aug 2016 22:39:59 +0200 Subject: [PATCH] Fixed structure-options2b-test.rkt --- structure-options2b-test.rkt | 35 ++++++++++++++++++++++------------- structure-options2b.rkt | 5 +++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/structure-options2b-test.rkt b/structure-options2b-test.rkt index a3278da..28f8b54 100644 --- a/structure-options2b-test.rkt +++ b/structure-options2b-test.rkt @@ -12,36 +12,45 @@ racket/format)) (check-equal? (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5) - [({~no-order {~once {~global-counter cnt 'occurrencea #:kw}} - {~global-counter cnt 'occurrenceb :number} + [({~no-order {~once {~global-counter [cnt 'occurrencea] #:kw}} + {~global-counter [cnt 'occurrenceb] :number} "ab"}) (attribute cnt)]) 5) (check-equal? (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5) - [({~no-order {~once {~global-or kw-or-number #t #:kw}} - {~global-or kw-or-number #t :number} + [({~no-order {~once {~global-or kw-or-number #:kw}} + {~global-or kw-or-number :number} "ab"}) (attribute kw-or-number)]) #t) (check-equal? (syntax-parse #'(1 "ab" "ab" 3 4 5) - [({~no-order {~optional {~global-or kw #t #:kw}} - {~global-or kw #f :number} + [({~no-order {~optional {~global-or [kw #t] #:kw}} + {~global-or [kw #f] :number} "ab"}) (attribute kw)]) #f) (check-equal? (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5) - [({~no-order {~optional {~global-and kw-and-not-number #t #:kw}} - {~global-and kw-and-not-number #f :number} + [({~no-order {~optional {~global-and [kw-not-number #t] #:kw}} + {~global-and [kw-not-number #f] :number} "ab"}) - (attribute kw-and-not-number)]) + (attribute kw-not-number)]) #f) +(check-equal? (syntax-parse #'("ab" "ab") + [({~no-order {~optional {~global-and [kw-not-number #t] #:kw}} + {~global-and [kw-not-number #f] :number} + "ab"}) + (attribute kw-not-number)]) + ;; (and) of nothing is #t, but we provide a 'none value + ;; for this special case + 'none) + (check-equal? (syntax-parse #'("ab" #:kw "ab") - [({~no-order {~optional {~global-and kw-and-not-number #t #:kw}} - {~global-and kw-and-not-number #f :number} - "ab"}) - (attribute kw-and-not-number)]) + [({~no-order {~optional {~global-and [kw-not-number #t] #:kw}} + {~global-and [kw-not-number #f] :number} + "ab"}) + (attribute kw-not-number)]) #t) \ No newline at end of file diff --git a/structure-options2b.rkt b/structure-options2b.rkt index 052b6d5..3c462bf 100644 --- a/structure-options2b.rkt +++ b/structure-options2b.rkt @@ -179,8 +179,9 @@ (define (aggregate-global-and . bs) (andmap unbox ;; remove the layer of protection - (filter identity ;; remove failed bindings - (flatten bs)))) ;; don't care about ellipsis nesting + (cons (box-immutable 'none) ;; default value when no bindings matched + (filter identity ;; remove failed bindings + (flatten bs))))) ;; don't care about ellipsis nesting (define-~global ~global-and aggregate-global-and) (define (aggregate-global-counter . bs)