Skip to content

Commit 020dcab

Browse files
Merge pull request #237 from Havvy/struct-grammar
Struct grammar
2 parents c95ce6c + c20b106 commit 020dcab

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/items/structs.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# Structs
22

3+
> **<sup>Syntax</sup>**
4+
> _Struct_ :
5+
> &nbsp;&nbsp; &nbsp;&nbsp; _StructStruct_
6+
> &nbsp;&nbsp; | _TupleStruct_
7+
>
8+
> _StructStruct_ :
9+
> &nbsp;&nbsp; `struct`
10+
> [IDENTIFIER]&nbsp;
11+
> [_Generics_]<sup>?</sup>
12+
> [_WhereClause_]<sup>?</sup>
13+
> ( `{` _StructFields_<sup>?</sup> `}` | `;` )
14+
>
15+
> _TupleStruct_ :
16+
> &nbsp;&nbsp; `struct`
17+
> [IDENTIFIER]&nbsp;
18+
> [_Generics_]<sup>?</sup>
19+
> `(` _TupleFields_<sup>?</sup> `)`
20+
> [_WhereClause_]<sup>?</sup>
21+
> `;`
22+
>
23+
> _StructFields_ :
24+
> &nbsp;&nbsp; _StructField_ (`,` _StructField_)<sup>\*</sup> `,`<sup>?</sup>
25+
>
26+
> _StructField_ :
27+
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>
28+
> &nbsp;&nbsp; [_Visibility_]
29+
> &nbsp;&nbsp; [IDENTIFIER] `:` [_Type_]
30+
>
31+
> _TupleFields_ :
32+
> &nbsp;&nbsp; _TupleField_ (`,` _TupleField_)<sup>\*</sup> `,`<sup>?</sup>
33+
>
34+
> _TupleField_ :
35+
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>
36+
> &nbsp;&nbsp; [_Visibility_]
37+
> &nbsp;&nbsp; [_Type_]
38+
339
A _struct_ is a nominal [struct type] defined with the keyword `struct`.
440

541
An example of a `struct` item and its use:
@@ -43,3 +79,10 @@ The precise memory layout of a struct is not specified. One can specify a
4379
particular layout using the [`repr` attribute].
4480

4581
[`repr` attribute]: attributes.html#ffi-attributes
82+
83+
[_OuterAttribute_]: attributes.html
84+
[IDENTIFIER]: identifiers.html
85+
[_Generics_]: items.html#type-parameters
86+
[_WhereClause_]: items.html#type-parameters
87+
[_Visibility_]: visibility-and-privacy.html
88+
[_Type_]: types.html

0 commit comments

Comments
 (0)