[racket] Passing information between syntax classes
Konrad,
Adding the super-bar syntax-class below
and the following #with directive to the foo syntax class
#:with sb:super-bar #'((foo-symbol ...) (bar.symbol ...))
should accomplish what you want without recourse to explicit parameters
Let me know if you need/want further discussion.
Thanks
R./Zack
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (foos-of-bars stx)
(define-syntax-class bar
(pattern ((~datum bar) symbol:id)))
(define-syntax-class super-bar
#:attributes (value)
(pattern ((foo-symbol:id ...)(bar-symbol:id ...))
#:with value #'(let ([foo-symbols (set (quote foo-symbol) ...)])
(list 'bar
(if (set-member? foo-symbols (quote
bar-symbol))
(list (quote bar-symbol))
(quote bar-symbol))
...))))
(define-syntax-class foo
#:attributes (value)
(pattern ((~datum foo) foo-symbol:id ... bar:bar ...)
#:with sb:super-bar #'((foo-symbol ...) (bar.symbol ...))
#:with value #'(list 'foo sb.value)))
(syntax-parse stx
[(_ foo:foo ...)
#'(list foo.value ...) ]))
(foos-of-bars (foo x y (bar a) (bar x)))
;->'((foo (bar a (x))))