@@ -98,8 +98,7 @@ statements, declarations and expressions.
98
98
Below are a few more examples of C++ attributes that we could support:
99
99
100
100
``` c++
101
- [[hlsl::layout_attribute]] // applies to the struct type
102
- struct {
101
+ struct [[hlsl::layout_attribute]] { // applies to the struct type
103
102
int x;
104
103
int y;
105
104
};
@@ -137,54 +136,98 @@ which existing attributes will convert to C++ attributes.
137
136
This proposal introduces grammar formulations for parsing attributes matching
138
137
some formulations from C++ `dcl.attr.grammar`. Specifically:
139
138
140
- ```ebnf
141
- attribute-specifier-seq: [ attribute-specifier-seq ], attribute-specifier
142
- attribute-specifier: "[" , "[" , attribute-list , "]" , "]"
143
- attribute-list: [ attribute ] ||
144
- attribute-list , "," , [attribute] ||
145
- { attribute } ||
146
- attribute-list , "," , { attribute }
147
- attribute: attribute-token , [attribute-argument-clause]
148
- attribute-token: identifier ||
149
- attribute-scoped-token
150
- attribute-scoped-token: attribute-namespace , "::" , identifier
151
- attribute-namespace: identifier
152
- attribute-argument-clause: "(" , balanced-token-seq , ")"
153
- balanced-token-seq: [ balanced-token ] ||
154
- balanced-token-seq , balanced-token
155
- balanced-token: "(" , balanced-token-seq , ")"
156
- "[" , balanced-token-seq , "]"
157
- "{" , balanced-token-seq , "}"
139
+ ```latex
140
+ \begin{grammar}
141
+ \define{attribute-specifier-seq}\br
142
+ \opt{attribute-specifier-seq} \textit{attribute-specifier}\br
143
+
144
+ \define{attribute-specifier}\br
145
+ \terminal{[ [} \textit{attribute-list} \terminal{] ]}\br
146
+
147
+ \define{attribute-list}\br
148
+ \opt{attribute}\br
149
+ \textit{attribute-list} \terminal{,} \opt{attribute}\br
150
+
151
+ \define{attribute}\br
152
+ \textit{attribute-token} \opt{attribute-argument-clause}\br
153
+
154
+ \define{attribute-token}\br
155
+ \textit{identifier}\br
156
+ \textit{attribute-scoped-token}\br
157
+
158
+ \define{attribute-scoped-token}\br
159
+ \textit{attribute-namespace} \terminal{::} \textit{identifier}\br
160
+
161
+ \define{attribute-namespace}\br
162
+ \textit{identifier}\br
163
+
164
+ \define{attribute-argument-clause}\br
165
+ \terminal{(} \textit{balanced-token-seq} \terminal{)}\br
166
+
167
+ \define{balanced-token-seq}\br
168
+ \opt{balanced-token}\br
169
+ \textit{balanced-token-seq} \textit{balanced-token}\br
170
+
171
+ \define{balanced-token}\br
172
+ \terminal{(} \textit{balanced-token-seq} \terminal{)}\br
173
+ \terminal{[} \textit{balanced-token-seq} \terminal{]}\br
174
+ \terminal{\{} \textit{balanced-token-seq} \terminal{\}}\br
175
+ any token other than a parenthesis, bracket or brace\br
176
+ \end{grammar}
158
177
```
178
+ ![ Latex Rendering] ( 0002-assets/AttributeGrammarRendering.png )
159
179
160
180
In contrast to existing HLSL annotations and Microsoft-style attributes, these
161
181
formulations use case-sensitive identifier tokens
162
182
163
183
164
184
#### Statements
165
185
166
- ``` ebnf
167
- statement: [ attribute-specifier-seq ] , expression-statement ||
168
- [ attribute-specifier-seq ] , compound-statement ||
169
- [ attribute-specifier-seq ] , selection-statement ||
170
- [ attribute-specifier-seq ] , iteration-statement ||
171
- [ attribute-specifier-seq ] , jump-statement ||
172
- declaration-statement
173
- labeled-statement
174
- labeled-statement: [ attribute-specifier-seq ] , "case" , constant-expression , ":" , statement
175
- [ attribute-specifier-seq ] , "default" , ":" , statement
186
+ > Note: This is already reflected in the language specification.
187
+
188
+ ``` latex
189
+ \begin{grammar}
190
+ \define{statement}\br
191
+ labeled-statement\br
192
+ \opt{attribute-specifier-sequence} expression-statement\br
193
+ \opt{attribute-specifier-sequence} compound-statement\br
194
+ \opt{attribute-specifier-sequence} iteration-statement\br
195
+ \opt{attribute-specifier-sequence} selection-statement\br
196
+ declaration-statement
197
+ \end{grammar}
176
198
```
199
+ ![ Latex Rendering] ( 0002-assets/StatementGrammarRendering.png )
177
200
178
201
#### Declarations
179
202
180
203
The ` attribute-specifier-seq ` element supports annotating type declarations. The
181
204
following grammar formulations are valid:
182
205
183
- ``` ebnf
184
- class-key: "class" || "struct"
185
- class-declaration: class-key , attribute-specifier-seq , identifier
206
+ ``` latex
207
+ \begin{grammar}
208
+ \define{class-name}\br
209
+ \textit{identifier}\br
210
+ \textit{simple-template-id}\br
211
+
212
+ \define{class-specifier}\br
213
+ \textit{class-head} \terminal{\}} \opt{member-specification} \terminal{\}}\br
214
+
215
+ \define{class-head}\br
216
+ \textit{class-key} \opt{attribute-specifier-seq} \textit{class-head-name} \opt{base-clause}\br
217
+ \textit{class-key} \opt{attribute-specifier-seq} \opt{base-clause}\br
186
218
187
- alias-declaration: "using" , identifier , [ attribute-specifier-seq ] , "=" , type-id , ";"
219
+ \define{class-head-name}\br
220
+ \opt{nested-name-specifier} \textit{class-name}\br
221
+
222
+ \define{class-key}\br
223
+ \terminal{class}\br
224
+ \terminal{struct}\br
225
+
226
+ \define{alias-declaration}\br
227
+ \terminal{using} \textit{identifier} \opt{attribute-specifier-seq} \terminal{=} \textit{type-id} \terminal{;}\br
228
+ \end{grammar}
188
229
```
189
230
231
+ ![ Latex Rendering] ( 0002-assets/ClassGrammarRendering.png )
232
+
190
233
<!-- {% endraw %} -->
0 commit comments