Conversation
This document introduces the concepts of enums and unions, detailing their syntax, semantics, and expansion options. It provides examples and grammar definitions for both types.
meetings/working-groups/discriminated-unions/enums-and-unions.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Joseph Musser <me@jnm2.com>
| Enum declaration: | ||
|
|
||
| ```C# | ||
| enum JsonValue |
There was a problem hiding this comment.
i like the practical example.
| ## Syntax | ||
|
|
||
| Expanded enum: | ||
| ```bnf |
There was a problem hiding this comment.
my pref is we stick with g4. IT's how we do all our grammars :)
meetings/working-groups/discriminated-unions/enums-and-unions.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
This proposal introduces a new discriminated union syntax for C# by separating enum and union into distinct type declarations. It outlines expanded enums as algebraic data types and unions as simple type unions.
- Defines syntax and semantics for both
enumanduniontype declarations - Provides grammar specifications in BNF notation for both constructs
- Explores expansion options including partial declarations and record bodies
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| <field-list> ::= <field> { "," <field> } | ||
| <field> ::= <type> <field-name> | ||
| <type> ::= <simple-type> | <generic-type> | ||
| <simple-type> ::= "double" | "bool" | "string" | <type-name> |
There was a problem hiding this comment.
The enum grammar defines <simple-type> without including 'int', but the union grammar on line 56 includes 'int'. For consistency, both grammars should include the same basic types or the difference should be explained.
| <simple-type> ::= "double" | "bool" | "string" | <type-name> | |
| <simple-type> ::= "double" | "bool" | "string" | "int" | <type-name> |
| String, | ||
| Object, | ||
| Array, | ||
| Null; |
There was a problem hiding this comment.
The semicolon after 'Null' is inconsistent with the proposed enum syntax shown earlier in the document where variants are separated by commas. This example should use consistent syntax.
| Null; | |
| Null, |
This document introduces the concepts of enums and unions, detailing their syntax, semantics, and expansion options. It provides examples and grammar definitions for both types.