Skip to content

Conversation

Nigel-Ecma
Copy link
Contributor

Up to Standard v5 the C# grammar was defined using a custom BNF-like grammar which supported optional and recursion, starting with Standard v6 the ANTLR grammar notation was adopted which added support for repetition. As of now the C# grammar has well almost 70 rules using repetition which has replaced unnecessary recursion.

In general language constructs which are left-associative are often described using left-recursive grammar rules which visualised as trees produce left-deep structures – e.g. this is the case for many arithmetic operators. Similarly right-associative constructs may be described by right-recursive rules which visualised produce right-deep structures. Finally list-like constructs are often described using repetition and visualised produced wide-flater trees – e.g. think argument lists, type parameter lists etc.

In v5 the list-like constructs where often represented by left-recursion as there was no repetition, from v6 such rules have been replaced by those using repetition.

This PR is the first of a number to pickup the stragglers, v5-era list-like structures described using left-recursion. Further a number of these rules have similar “cousins” within the grammar which have long made since made the transition and the dissimilarity in approach due to these straggles make the grammar as a whole less consistent.

As of today there are just 7 stragglers and 1 semi-straggler (it seems to have started transition and faltered).

This first PR handles: expression_list, query_body_clauses, type_parameters, and variant_type_parameters

Review Notes:

You only need to consider the changes to the *.md files in standard; the other files are machine-generated updates to parsing test samples describing the new expected parse for some samples. If you wish to see visualisations of the changes you may download the changed *.svg files in the PR and the current versions of them in draft-v8 and view them side-by-side (multiple monitors helps!)

@Nigel-Ecma Nigel-Ecma added this to the C# 8.0 milestone Mar 17, 2025
@Nigel-Ecma Nigel-Ecma self-assigned this Mar 17, 2025
@Nigel-Ecma Nigel-Ecma marked this pull request as ready for review March 17, 2025 02:34
@Nigel-Ecma Nigel-Ecma added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Mar 18, 2025
Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

I hadn't expected to understand this PR, but I think I actually do. Shocker! (That doesn't mean it shouldn't be carefully reviewed by others, mind you.)

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

I reviewed the grammar changes closely, but didn't look much at the changes in the testing files.

I like the grammar updates. Those look great.

I'll approve as well.

@jskeet Can we merge this at tomorrow's meeting?

@jskeet
Copy link
Contributor

jskeet commented Mar 18, 2025

@BillWagner

@jskeet Can we merge this at tomorrow's meeting?

That's my hope, yes :)

@jskeet jskeet merged commit 75ca573 into dotnet:draft-v8 Mar 19, 2025
6 checks passed
@Nigel-Ecma Nigel-Ecma deleted the deep_to_wide branch March 19, 2025 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants