www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test-global.rkt (2565B)


      1 #lang racket
      2 
      3 (require extensible-parser-specifications
      4          racket/require
      5          syntax/parse
      6          (subtract-in syntax/stx phc-toolkit/untyped)
      7          rackunit
      8          racket/format
      9          phc-toolkit/untyped
     10          (for-syntax syntax/parse
     11                      syntax/stx
     12                      racket/format))
     13 
     14 (check-equal?
     15  (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5)
     16    [({~seq-no-order {~once {~global-counter [cnt 1] #:kw}}
     17                     {~global-counter [cnt 1] :number}
     18                     "ab"})
     19     (attribute cnt)])
     20  5)
     21 
     22 (check-equal?
     23  (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5)
     24    [({~seq-no-order {~once {~global-or kw-or-number #:kw}}
     25                     {~global-or kw-or-number :number}
     26                     "ab"})
     27     (attribute kw-or-number)])
     28  #t)
     29 
     30 (check-equal?
     31  (syntax-parse #'(1 "ab" "ab" 3 4 5)
     32    [({~seq-no-order {~optional {~global-or [kw #t] #:kw}}
     33                     {~global-or [kw #f] :number}
     34                     "ab"})
     35     (attribute kw)])
     36  #f)
     37 
     38 (check-equal?
     39  (syntax-parse #'(1 "ab" #:kw "ab" 3 4 5)
     40    [({~seq-no-order {~optional {~global-and [kw-not-number #t] #:kw}}
     41                     {~global-and [kw-not-number #f] :number}
     42                     "ab"})
     43     (attribute kw-not-number)])
     44  #f)
     45 
     46 (check-equal?
     47  (syntax-parse #'("ab" "ab")
     48    [({~seq-no-order {~optional {~global-and [kw-not-number #t] #:kw}}
     49                     {~global-and [kw-not-number #f] :number}
     50                     "ab"})
     51     (attribute kw-not-number)])
     52  ;; (and) of nothing is #t, but we provide a 'none value
     53  ;; for this special case
     54  'none)
     55 
     56 (check-equal?
     57  (syntax-parse #'("ab" #:kw "ab")
     58    [({~seq-no-order {~optional {~global-and [kw-not-number #t] #:kw}}
     59                     {~global-and [kw-not-number #f] :number}
     60                     "ab"})
     61     (attribute kw-not-number)])
     62  #t)
     63 
     64 ;; former tests present in the documentation:
     65 
     66 (check-equal?
     67  (syntax-parse #'(1 ya (2 #f 3) 4 yb (5 #f 6) yc 7)
     68    [(~no-order {~and x:id {~global-or [g (syntax-e #'x)]}}
     69                {~global-or [g (syntax-e #'y)] y:number}
     70                ({~global-or [g (syntax-e #'z)] (~and z (~or :number #f))}
     71                 …)
     72                {~global-or [g (syntax-e #'w)] w:str})
     73     (attribute g)])
     74  #t)
     75 
     76 (check-equal?
     77  (syntax-parse #'(1 ya (2 3) 4 yb (5 6) yc 7)
     78    [(~no-order {~and x:id {~global-and [g (syntax-e #'x)]}}
     79                {~global-and [g (syntax-e #'y)] y:number}
     80                ({~global-and [g (syntax-e #'z)] (~and z :number)}
     81                 …)
     82                {~global-and [g (syntax-e #'w)] w:str})
     83     (attribute g)])
     84  #t)