Added ~whole, which acts like (~and (~seq id ...) . pats), but always provide a default value of '() for id if the match fails
This commit is contained in:
parent
53ae6058ff
commit
9b90a03c02
1
main.rkt
1
main.rkt
|
@ -18,6 +18,7 @@
|
||||||
~mixin
|
~mixin
|
||||||
~post-check
|
~post-check
|
||||||
~post-fail
|
~post-fail
|
||||||
|
~whole
|
||||||
~nop
|
~nop
|
||||||
~optional/else
|
~optional/else
|
||||||
~global-or
|
~global-or
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
(provide ~nop
|
(provide ~nop
|
||||||
~post-check
|
~post-check
|
||||||
~post-fail)
|
~post-fail
|
||||||
|
~whole)
|
||||||
|
|
||||||
(define-syntax ~nop
|
(define-syntax ~nop
|
||||||
(pattern-expander
|
(pattern-expander
|
||||||
|
@ -26,10 +27,36 @@
|
||||||
(begin (eh-post-accumulate! '~post-check #'post)
|
(begin (eh-post-accumulate! '~post-check #'post)
|
||||||
#'(~nop))])))
|
#'(~nop))])))
|
||||||
|
|
||||||
|
#;(define-eh-mixin-expander ~defaults
|
||||||
|
(λ (stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ ([a v] ...) . pats)
|
||||||
|
(let ()
|
||||||
|
(define/with-syntax clause-present (get-new-clause!))
|
||||||
|
(eh-post-accumulate! '~defaults
|
||||||
|
#'(~bind [a (or (attribute clause-present) v)]
|
||||||
|
...))
|
||||||
|
#'(~and (~bind [clause-present #t]) . pats))])))
|
||||||
|
|
||||||
|
(define-eh-mixin-expander ~whole
|
||||||
|
(λ (stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ id . pats)
|
||||||
|
(let ()
|
||||||
|
(define/with-syntax clause-present (get-new-clause!))
|
||||||
|
(define/with-syntax clause (get-new-clause!))
|
||||||
|
(eh-post-accumulate! '~whole
|
||||||
|
#'(~bind [(id 1) (if (attribute clause-present)
|
||||||
|
(attribute clause)
|
||||||
|
(list))]))
|
||||||
|
#'(~and (~bind [clause-present #t])
|
||||||
|
(~seq clause (... ...))
|
||||||
|
(~seq . pats)))])))
|
||||||
|
|
||||||
(define-for-syntax (post-fail stx)
|
(define-for-syntax (post-fail stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ message #:when condition)
|
[(_ message #:when condition)
|
||||||
(begin
|
(let ()
|
||||||
(define/with-syntax clause-present (get-new-clause!))
|
(define/with-syntax clause-present (get-new-clause!))
|
||||||
(eh-post-accumulate! '~post-fail
|
(eh-post-accumulate! '~post-fail
|
||||||
#`(~fail #:when (and (attribute clause-present)
|
#`(~fail #:when (and (attribute clause-present)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user