Skip to content

Conversation

agocke
Copy link
Member

@agocke agocke commented Sep 25, 2025

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.

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.
@agocke agocke requested a review from a team as a code owner September 25, 2025 02:00
Enum declaration:

```C#
enum JsonValue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like the practical example.

## Syntax

Expanded enum:
```bnf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my pref is we stick with g4. IT's how we do all our grammars :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rewrite to g4 syntax

@agocke agocke requested a review from Copilot October 6, 2025 22:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 enum and union type 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>
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
<simple-type> ::= "double" | "bool" | "string" | <type-name>
<simple-type> ::= "double" | "bool" | "string" | "int" | <type-name>

Copilot uses AI. Check for mistakes.

String,
Object,
Array,
Null;
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
Null;
Null,

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants