Re: [racket-dev] can a syntax-class "inherit" attributes?

2013-08-23 Thread Carl Eastlund
You'd have to ask Ryan to be sure, but I think they're pretty stable.  I've
been using them for some time.

Carl Eastlund


On Fri, Aug 23, 2013 at 12:53 PM, Stephen Chang  wrote:

> Ah, thanks. That's exactly what I wanted.
>
> How stable are these features? Shall I add them to the docs?
>
> On Fri, Aug 23, 2013 at 12:54 AM, Carl Eastlund  wrote:
> > Here's how you want to define AorB:
> >
> > (define-syntax-class AorB #:auto-nested-attributes
> >   (pattern :A)
> >   (pattern :B))
> >
> > There's two things going on here, both of which I believe are
> undocumented,
> > sadly.
> >
> > One is #:auto-nested-attributes, an option that tells AorB that anything
> > bound as an attribute by nested sub-patterns in its clauses should
> > automatically become an attribute of AorB.
> >
> > The other is that empty identifier does not add "." to its attribute
> names.
> > When you bind a with the attribute X, you get A.X, and when you bind b,
> you
> > get b.X, but when you bind the empty identifier, you just get X.
> >
> > So now you just have X bound in both clauses, and that's automatically
> made
> > an attribute of AorB, and it all works like you want.
> >
> > Carl Eastlund
> >
> >
> > On Fri, Aug 23, 2013 at 12:22 AM, Stephen Chang 
> wrote:
> >>
> >> Is there a way for a syntax-class to automatically inherit attributes?
> >>
> >> For example, the third class below combines the first two. Is there a
> >> way to automatically get the attributes from the first two classes in
> >> the third one (ie, I want to drop the "#:attr X #'a.X" part in the
> >> third class)?
> >>
> >> #lang racket
> >> (require syntax/parse)
> >>
> >> (define-syntax-class A (pattern (a b) #:attr X #'b))
> >> (define-syntax-class B (pattern (a b c) #:attr X #'c))
> >> (define-syntax-class AorB
> >>   (pattern a:A #:attr X #'a.X)
> >>   (pattern b:B #:attr X #'b.X))
> >>
> >> (syntax-parse #'(list 1) [ab:AorB (attribute ab.X)])
> >> _
> >>   Racket Developers list:
> >>   http://lists.racket-lang.org/dev
> >>
> >
>
>
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] can a syntax-class "inherit" attributes?

2013-08-23 Thread Stephen Chang
Ah, thanks. That's exactly what I wanted.

How stable are these features? Shall I add them to the docs?

On Fri, Aug 23, 2013 at 12:54 AM, Carl Eastlund  wrote:
> Here's how you want to define AorB:
>
> (define-syntax-class AorB #:auto-nested-attributes
>   (pattern :A)
>   (pattern :B))
>
> There's two things going on here, both of which I believe are undocumented,
> sadly.
>
> One is #:auto-nested-attributes, an option that tells AorB that anything
> bound as an attribute by nested sub-patterns in its clauses should
> automatically become an attribute of AorB.
>
> The other is that empty identifier does not add "." to its attribute names.
> When you bind a with the attribute X, you get A.X, and when you bind b, you
> get b.X, but when you bind the empty identifier, you just get X.
>
> So now you just have X bound in both clauses, and that's automatically made
> an attribute of AorB, and it all works like you want.
>
> Carl Eastlund
>
>
> On Fri, Aug 23, 2013 at 12:22 AM, Stephen Chang  wrote:
>>
>> Is there a way for a syntax-class to automatically inherit attributes?
>>
>> For example, the third class below combines the first two. Is there a
>> way to automatically get the attributes from the first two classes in
>> the third one (ie, I want to drop the "#:attr X #'a.X" part in the
>> third class)?
>>
>> #lang racket
>> (require syntax/parse)
>>
>> (define-syntax-class A (pattern (a b) #:attr X #'b))
>> (define-syntax-class B (pattern (a b c) #:attr X #'c))
>> (define-syntax-class AorB
>>   (pattern a:A #:attr X #'a.X)
>>   (pattern b:B #:attr X #'b.X))
>>
>> (syntax-parse #'(list 1) [ab:AorB (attribute ab.X)])
>> _
>>   Racket Developers list:
>>   http://lists.racket-lang.org/dev
>>
>
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] can a syntax-class "inherit" attributes?

2013-08-22 Thread Carl Eastlund
Here's how you want to define AorB:

(define-syntax-class AorB #:auto-nested-attributes
  (pattern :A)
  (pattern :B))

There's two things going on here, both of which I believe are undocumented,
sadly.

One is #:auto-nested-attributes, an option that tells AorB that anything
bound as an attribute by nested sub-patterns in its clauses should
automatically become an attribute of AorB.

The other is that empty identifier does not add "." to its attribute
names.  When you bind a with the attribute X, you get A.X, and when you
bind b, you get b.X, but when you bind the empty identifier, you just get X.

So now you just have X bound in both clauses, and that's automatically made
an attribute of AorB, and it all works like you want.

Carl Eastlund


On Fri, Aug 23, 2013 at 12:22 AM, Stephen Chang  wrote:

> Is there a way for a syntax-class to automatically inherit attributes?
>
> For example, the third class below combines the first two. Is there a
> way to automatically get the attributes from the first two classes in
> the third one (ie, I want to drop the "#:attr X #'a.X" part in the
> third class)?
>
> #lang racket
> (require syntax/parse)
>
> (define-syntax-class A (pattern (a b) #:attr X #'b))
> (define-syntax-class B (pattern (a b c) #:attr X #'c))
> (define-syntax-class AorB
>   (pattern a:A #:attr X #'a.X)
>   (pattern b:B #:attr X #'b.X))
>
> (syntax-parse #'(list 1) [ab:AorB (attribute ab.X)])
> _
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
>
>
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


[racket-dev] can a syntax-class "inherit" attributes?

2013-08-22 Thread Stephen Chang
Is there a way for a syntax-class to automatically inherit attributes?

For example, the third class below combines the first two. Is there a
way to automatically get the attributes from the first two classes in
the third one (ie, I want to drop the "#:attr X #'a.X" part in the
third class)?

#lang racket
(require syntax/parse)

(define-syntax-class A (pattern (a b) #:attr X #'b))
(define-syntax-class B (pattern (a b c) #:attr X #'c))
(define-syntax-class AorB
  (pattern a:A #:attr X #'a.X)
  (pattern b:B #:attr X #'b.X))

(syntax-parse #'(list 1) [ab:AorB (attribute ab.X)])
_
  Racket Developers list:
  http://lists.racket-lang.org/dev