[racket] Syntax class patterns and nested attributes
If you switch the order in which the syntax-classes are defined and add #:auto-nested-attribustes, this works:
#lang racket
(require syntax/parse)
(define-syntax-class B
(pattern (b1 b2 b3)))
(define-syntax-class A
#:auto-nested-attributes
(pattern (a1 a2:B a3)))
(define foo
(syntax-parser
[blah:A #'blah.a2.b1]))
(syntax->datum (foo #'(1 (2 3 4) 5))) ; 2
But for some reason this doesn’t work:
#lang at-exp racket
(require syntax/parse)
(define-syntax-class A
#:auto-nested-attributes
(pattern (a1 a2:B a3)))
(define-syntax-class B
(pattern (b1 b2 b3)))
(define foo
(syntax-parser
[blah:A #'blah.a2.b1]))
(syntax->datum (foo #'(1 (2 3 4) 5))) ; 'blah.a2.b1
But this does:
#lang at-exp racket
(require syntax/parse)
(define-syntax-class A
#:attributes (a2.b1)
(pattern (a1 a2:B a3)))
(define-syntax-class B
(pattern (b1 b2 b3)))
(define foo
(syntax-parser
[blah:A #'blah.a2.b1]))
(syntax->datum (foo #'(1 (2 3 4) 5))) ; 2
On Feb 3, 2015, at 5:30 PM, Jack Firth <jackhfirth at gmail.com> wrote:
> Suppose I have these syntax classes:
>
> (define-syntax-class A
> (pattern (a1 a2:B a3)))
>
> (define-syntax-class B
> (pattern (b1 b2 b3)))
>
> I'd like to be able to access nested attributes, like so:
>
> (define foo
> (syntax-parser
> [blah:A #'blah.a2.b1]))
>
> Currently, this doesn't work (and it doesn't even throw an error either). How could I do this?
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users