Skip to content

Commit

Permalink
Merge pull request #159 from brauliobz/grammar_item_enum
Browse files Browse the repository at this point in the history
Enum grammar
  • Loading branch information
Havvy authored Dec 1, 2017
2 parents 64fcf08 + 1fc303e commit e19ff6d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/items/enumerations.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Enumerations

> **<sup>Syntax</sup>**
> _Enumeration_ :
> &nbsp;&nbsp; `enum`
> [IDENTIFIER]&nbsp;
> [_Generics_]<sup>?</sup>
> [_WhereClause_]<sup>?</sup>
> `{` _EnumItems_<sup>?</sup> `}`
>
> _EnumItems_ :
> &nbsp;&nbsp; _EnumItem_ ( `,` _EnumItem_ )<sup>\*</sup> `,`<sup>?</sup>
>
> _EnumItem_ :
> &nbsp;&nbsp; _OuterAttribute_<sup>\*</sup>
> &nbsp;&nbsp; [IDENTIFIER]&nbsp;( _EnumItemTuple_ | _EnumItemStruct_
> | _EnumItemDiscriminant_ )<sup>?</sup>
>
> _EnumItemTuple_ :
> &nbsp;&nbsp; `(` [_TupleFields_]<sup>?</sup> `)`
>
> _EnumItemStruct_ :
> &nbsp;&nbsp; `{` [_StructFields_]<sup>?</sup> `}`
>
> _EnumItemDiscriminant_ :
> &nbsp;&nbsp; `=` [_Expression_]
An _enumeration_ is a simultaneous definition of a nominal [enumerated type] as
well as a set of *constructors*, that can be used to create or pattern-match
values of the corresponding enumerated type.
Expand Down Expand Up @@ -67,3 +92,10 @@ let x = Foo::Baz as u32; // x is now 123u32

This only works as long as none of the variants have data attached. If it were
`Baz(i32)`, this is disallowed.

[IDENTIFIER]: identifiers.html
[_Generics_]: items.html#type-parameters
[_WhereClause_]: items.html#type-parameters
[_Expression_]: expressions.html
[_TupleFields_]: items/structs.html
[_StructFields_]: items/structs.html

0 comments on commit e19ff6d

Please sign in to comment.