<div dir="ltr"><div><div><div><div>Here's how you want to define AorB:<br><br>(define-syntax-class AorB #:auto-nested-attributes<br> (pattern :A)<br> (pattern :B))<br><br></div>There's two things going on here, both of which I believe are undocumented, sadly.<br>
<br>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.<br><br></div>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.<br>
<br></div>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.</div></div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Fri, Aug 23, 2013 at 12:22 AM, Stephen Chang <span dir="ltr"><<a href="mailto:stchang@ccs.neu.edu" target="_blank">stchang@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is there a way for a syntax-class to automatically inherit attributes?<br>
<br>
For example, the third class below combines the first two. Is there a<br>
way to automatically get the attributes from the first two classes in<br>
the third one (ie, I want to drop the "#:attr X #'a.X" part in the<br>
third class)?<br>
<br>
#lang racket<br>
(require syntax/parse)<br>
<br>
(define-syntax-class A (pattern (a b) #:attr X #'b))<br>
(define-syntax-class B (pattern (a b c) #:attr X #'c))<br>
(define-syntax-class AorB<br>
(pattern a:A #:attr X #'a.X)<br>
(pattern b:B #:attr X #'b.X))<br>
<br>
(syntax-parse #'(list 1) [ab:AorB (attribute ab.X)])<br>
_________________________<br>
Racket Developers list:<br>
<a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
<br>
</blockquote></div><br></div>