-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher-rules.rkt
41 lines (36 loc) · 1.24 KB
/
watcher-rules.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#lang racket
(require "inotify.rkt")
(provide (all-defined-out))
(begin-for-syntax
(define (check-ids stx forms)
(for-each
(lambda (form)
(unless (identifier? form)
(raise-syntax-error #f
"not an identifier"
stx
form)))
(syntax->list forms))))
(define-syntax watcher-rules
(lambda (stx)
(syntax-case stx ()
[(_ (p m) base (pattern body ...) ...)
(check-ids stx #'(p m))
#'(begin
(unless (path-string? base)
(raise-argument-error 'watch-rules "base is not path-string?" base))
(new inotify-watcher%
[path base]
[recursive? #t]
[callback
(lambda (name mask)
(define p name)
(define m mask)
(match (path->string name)
[(pregexp pattern)
body ...] ...
[else #t]))]))]
[(_ (p) base (pattern body ...) ...)
#`(watcher-rules (p ___) base (pattern body ...) ...)]
[(_ base (pattern body ...) ...)
#`(watcher-rules (__ ___) base (pattern body ...) ...)])))