Grammar – Consistency & Cleanup #1290
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 instandard
; 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 indraft-v8
and view them side-by-side (multiple monitors helps!)