Skip to content

Commit 059b06f

Browse files
committed
Updating grammar specifiction
This updates the grammar specification to align with how C++ specifies parsing grammar, and the language spec latex is included. I've also added images containing the rendered grammar for ease of reading.
1 parent ede9517 commit 059b06f

4 files changed

+77
-34
lines changed
Loading
140 KB
Loading
58.3 KB
Loading

proposals/0002-cxx-attributes.md

+77-34
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ statements, declarations and expressions.
9898
Below are a few more examples of C++ attributes that we could support:
9999

100100
```c++
101-
[[hlsl::layout_attribute]] // applies to the struct type
102-
struct {
101+
struct [[hlsl::layout_attribute]] { // applies to the struct type
103102
int x;
104103
int y;
105104
};
@@ -137,54 +136,98 @@ which existing attributes will convert to C++ attributes.
137136
This proposal introduces grammar formulations for parsing attributes matching
138137
some formulations from C++ `dcl.attr.grammar`. Specifically:
139138
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}
158177
```
178+
![Latex Rendering](0002-assets/AttributeGrammarRendering.png)
159179

160180
In contrast to existing HLSL annotations and Microsoft-style attributes, these
161181
formulations use case-sensitive identifier tokens
162182

163183

164184
#### Statements
165185

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}
176198
```
199+
![Latex Rendering](0002-assets/StatementGrammarRendering.png)
177200

178201
#### Declarations
179202

180203
The `attribute-specifier-seq` element supports annotating type declarations. The
181204
following grammar formulations are valid:
182205

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
186218
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}
188229
```
189230

231+
![Latex Rendering](0002-assets/ClassGrammarRendering.png)
232+
190233
<!-- {% endraw %} -->

0 commit comments

Comments
 (0)