Skip to content

Commit

Permalink
Merge branch 'draft-v8' into indexers-and-ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
RexJaeschke authored Nov 11, 2024
2 parents 0b88e74 + 773fdb8 commit b2873d8
Show file tree
Hide file tree
Showing 41 changed files with 856 additions and 593 deletions.
Binary file not shown.
128 changes: 47 additions & 81 deletions .github/workflows/dependencies/ReplaceAndAdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,88 +33,14 @@ the automatic section numbering tooling, they **must** be maintained manually.
# Verification-Only Replacements & Additions

This set of replacements and additions is the bare minimum required to allow the grammar
to verify and run, though
it may not produce the desired parse (that requires at least the use of modes and/or
lexical predicates).
to verify and run, though it may not produce the desired lex and parse (that requires at
least the use of modes and/or lexical predicates).

This set can be used as a basic check that the grammar is a correct ANTLR grammar.
Pre-processing directives are skipped like whitespace, however lexing confirms the lexical
grammar is valid.

---

## Top Level Rule

The Standard’s *compilation_unit* as is will allow garbage at the end of a file, this
rule has an EOF requirement to ensure the whole of the input must be a correct program.

> *Note: The section number makes this the first rule in the grammar, not required but it
has to go somewhere…*

### 0.0.0 Top Level Rule

```ANTLR
// [ADDED] Rule added as the start point
prog: compilation_unit EOF;
```
---

## Discarding Whitespace

The following changes in §7.3.2, §7.3.3 and §7.3.4, add `-> skip` to the “whitespace”
token rules so that are not passed to the parser. This behaviour is implicit in the
Standard.

### 6.3.2 Line terminators

```ANTLR
// [SKIP]
New_Line
: ( New_Line_Character
| '\u000D\u000A' // carriage return, line feed
) -> skip
;
```

### 6.3.3 Comments

```ANTLR
// [SKIP]
Comment
: ( Single_Line_Comment
| Delimited_Comment
) -> skip
;
```

### 6.3.4 White space

```ANTLR
// [SKIP]
Whitespace
: ( [\p{Zs}] // any character with Unicode class Zs
| '\u0009' // horizontal tab
| '\u000B' // vertical tab
| '\u000C' // form feed
) -> skip
;
```

---

## Pre-processing directives

This change causes all pre-processor directives to be discarded, they don’t need to be
processed to validate the grammar (processing them would exercise the *implementation*
of the pre-processor, which is not part of the Standard).

### 6.5.1 General
This set can be used as a basic check that the grammar is a valid ANTLR grammar.

```ANTLR
// [CHANGE] Discard pre-processor directives
PP_Directive
: (PP_Start PP_Kind PP_New_Line) -> skip
;
```

---

Expand All @@ -139,7 +65,39 @@ As MLR is not supported by ANTLR without this change the grammar would be reject

```ANTLR
// [CHANGE] This removes a mutual left-recursion group which we have (currently?)
// [CHANGE] decided to leave in the Standard. Without this change the grammar will fail.
// [CHANGE] decided to leave in the Standard. Without this change the grammar will
// [CHANGE] fail to verify.
# Expect
primary_no_array_creation_expression
: literal
| interpolated_string_expression
| simple_name
| parenthesized_expression
| tuple_expression
| member_access
| null_conditional_member_access
| invocation_expression
| element_access
| null_conditional_element_access
| this_access
| base_access
| post_increment_expression
| post_decrement_expression
| object_creation_expression
| delegate_creation_expression
| anonymous_object_creation_expression
| typeof_expression
| sizeof_expression
| checked_expression
| unchecked_expression
| default_value_expression
| nameof_expression
| anonymous_method_expression
| pointer_member_access // unsafe code support
| pointer_element_access // unsafe code support
| stackalloc_expression
;
# ReplaceWith
primary_no_array_creation_expression
: literal
| interpolated_string_expression
Expand Down Expand Up @@ -194,12 +152,20 @@ primary_no_array_creation_expression
## Interpolated strings

The lexical rules for interpolated strings are context-sensitive and are not ANLTR-ready in the Standard
as how such rules are handled is an implementation detail, e.g. using ANTLR modes as done in mods-base.
as how such rules are handled is an implementation detail, e.g. using ANTLR modes.
Here we just define one token in terms of another to remove the overlap warnings.

### 12.8.3 Interpolated string expressions

```ANTLR
// [CHANGE] This allows the grammar to verify without warnings, it does NOT correctly
// [CHANGE] parse interpolated strings – that requires modes and/or lexical predicates.
// [CHANGE] Note: Interpolated strings are properly parsed in Base and other sets.
# Expect
Interpolated_Verbatim_String_End
: '"'
;
# ReplaceWith
Interpolated_Verbatim_String_End
: Interpolated_Regular_String_End
;
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/do-not-merge-label-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This GitHub Action workflow is triggered on label changes for pull requests.
# When a pull request is labeled with "DO NOT MERGE", the workflow fails, thus
# preventing the pull request from being merged. Otherwise, the workflow will
# succeed, allowing the pull request to be merged.

name: "Check labels that prevent merge"
on:
pull_request:
branches: [main]
types: [labeled, unlabeled]

permissions:
contents: read

jobs:
labels-preventing-merge-check:
runs-on: ubuntu-latest
strategy:
matrix:
label:
# Labels that prevent merging
- 'do not merge'
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- name: 'Check "${{ matrix.label }}" label'
run: |
echo "::notice::Merging permission is diabled for PRs when the '${{ matrix.label }}' label is applied."
if [ "${{ contains(github.event.pull_request.labels.*.name, matrix.label) }}" = "true" ]; then
echo "::error::Pull request is labeled as '${{ matrix.label }}'. Please remove the label before merging."
exit 1
else
exit 0
fi
2 changes: 1 addition & 1 deletion .github/workflows/grammar-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# Install build grammar global tool
- name: Install BuildGrammar tool
run: |
dotnet tool install --version 1.0.0-alpha.4 --global --add-source ./.github/workflows/dependencies/ EcmaTC49.BuildGrammar
dotnet tool install --version 2.0.0-beta.3 --global --add-source ./.github/workflows/dependencies/ EcmaTC49.BuildGrammar

- name: run validate
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/markdown-links-verifier.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/renumber-sections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
env:
DOTNET_NOLOGO: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ on:
jobs:
test-extraction-and-runner:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
env:
DOTNET_NOLOGO: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

steps:
- name: Check out our repo
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/word-converter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
env:
DOTNET_NOLOGO: true
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,6 @@ test-grammar/

# don't checkin jar files:
*.jar

# don't checkin launchSettings:
**/launchSettings.json
6 changes: 3 additions & 3 deletions admin/v8-feature-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ default interface methods ([MS Proposal](https://github.com/dotnet/csharplang/bl
permit `stackalloc` in nested contexts ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/nested-stackalloc.md)) | [1056](https://github.com/dotnet/csharpstandard/pull/1056) | Completed | small | N/A |
`notnull` constraint ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/notnull-constraint.md)) | [830](https://github.com/dotnet/csharpstandard/pull/830) | Completed | small | Done |
null coalescing assignment ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/null-coalescing-assignment.md)) | [609](https://github.com/dotnet/csharpstandard/pull/609) | HELP NEEDED | small | N/A | See Issue [#737](https://github.com/dotnet/csharpstandard/issues/737)
nullable reference types ([MS Proposal (from V9)](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/nullable-reference-types-specification.md) which supercedes ([MS Proposal (from V8)](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/nullable-reference-types.md)) |[700](https://github.com/dotnet/csharpstandard/pull/700) | Completed | large | Done | related to V8 "notnull" feature
nullable reference types ([MS Proposal (from V9)](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/nullable-reference-types-specification.md) which supercedes ([MS Proposal (from V8)](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/nullable-reference-types.md)) |[700](https://github.com/dotnet/csharpstandard/pull/700), [1195](https://github.com/dotnet/csharpstandard/pull/1195) | Completed | large | Done | related to V8 "notnull" feature
Obsolete on property accessor ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/obsolete-accessor.md)) | **no change needed** | Postponed | | N/A | See Issue [#375](https://github.com/dotnet/csharpstandard/issues/375)
New kinds of pattern matching ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/patterns.md)) | [873](https://github.com/dotnet/csharpstandard/pull/873) | Completed | medium | Done | precedence table assumes "ranges and indices" has been merged
ranges and indices ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/ranges.md)) | [605](https://github.com/dotnet/csharpstandard/pull/605) | Completed | medium | Done |
readonly instance members ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/readonly-instance-members.md)) | [673](https://github.com/dotnet/csharpstandard/pull/673) | Completed | small | N/A |
name shadowing in nested functions ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/shadowing-in-nested-functions.md)) | [608](https://github.com/dotnet/csharpstandard/pull/608) | Completed | small | N/A |
static local functions ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/static-local-functions.md)) | [869](https://github.com/dotnet/csharpstandard/pull/869)| Completed | small | N/A |
name shadowing in nested functions ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/shadowing-in-nested-functions.md)) | [608](https://github.com/dotnet/csharpstandard/pull/608) | Merged | small | N/A |
static local functions ([MS Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/static-local-functions.md)) | [869](https://github.com/dotnet/csharpstandard/pull/869)| Merged | small | N/A |
Disposable ref structs [672](https://github.com/dotnet/csharpstandard/pull/672) | | **???** | | | Included in PR [606](https://github.com/dotnet/csharpstandard/pull/606); **Check this**
75 changes: 43 additions & 32 deletions standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@
- [§8.6](types.md#86-expression-tree-types) Expression tree types
- [§8.7](types.md#87-the-dynamic-type) The dynamic type
- [§8.8](types.md#88-unmanaged-types) Unmanaged types
- [§8.9](types.md#89-reference-types-and-nullability) Reference Types and nullability
- [§8.9.1](types.md#891-general) General
- [§8.9.2](types.md#892-non-nullable-reference-types) Non-nullable reference types
- [§8.9.3](types.md#893-nullable-reference-types) Nullable reference types
- [§8.9.4](types.md#894-nullable-context) Nullable context
- [§8.9.4.1](types.md#8941-general) General
- [§8.9.4.2](types.md#8942-nullable-disable) Nullable disable
- [§8.9.4.3](types.md#8943-nullable-annotations) Nullable annotations
- [§8.9.4.4](types.md#8944-nullable-warnings) Nullable warnings
- [§8.9.4.5](types.md#8945-nullable-enable) Nullable enable
- [§8.9.5](types.md#895-nullabilities-and-null-states) Nullabilities and null states
- [§9](variables.md#9-variables) Variables
- [§9.1](variables.md#91-general) General
- [§9.2](variables.md#92-variable-categories) Variable categories
Expand Down Expand Up @@ -212,9 +223,8 @@
- [§10.3.5](conversions.md#1035-explicit-reference-conversions) Explicit reference conversions
- [§10.3.6](conversions.md#1036-explicit-tuple-conversions) Explicit tuple conversions
- [§10.3.7](conversions.md#1037-unboxing-conversions) Unboxing conversions
- [§10.3.8](conversions.md#1038-explicit-dynamic-conversions) Explicit dynamic conversions
- [§10.3.9](conversions.md#1039-explicit-conversions-involving-type-parameters) Explicit conversions involving type parameters
- [§10.3.10](conversions.md#10310-user-defined-explicit-conversions) User-defined explicit conversions
- [§10.3.8](conversions.md#1038-explicit-conversions-involving-type-parameters) Explicit conversions involving type parameters
- [§10.3.9](conversions.md#1039-user-defined-explicit-conversions) User-defined explicit conversions
- [§10.4](conversions.md#104-standard-conversions) Standard conversions
- [§10.4.1](conversions.md#1041-general) General
- [§10.4.2](conversions.md#1042-standard-implicit-conversions) Standard implicit conversions
Expand Down Expand Up @@ -314,35 +324,36 @@
- [§12.8.7.1](expressions.md#12871-general) General
- [§12.8.7.2](expressions.md#12872-identical-simple-names-and-type-names) Identical simple names and type names
- [§12.8.8](expressions.md#1288-null-conditional-member-access) Null Conditional Member Access
- [§12.8.9](expressions.md#1289-invocation-expressions) Invocation expressions
- [§12.8.9.1](expressions.md#12891-general) General
- [§12.8.9.2](expressions.md#12892-method-invocations) Method invocations
- [§12.8.9.3](expressions.md#12893-extension-method-invocations) Extension method invocations
- [§12.8.9.4](expressions.md#12894-delegate-invocations) Delegate invocations
- [§12.8.10](expressions.md#12810-null-conditional-invocation-expression) Null Conditional Invocation Expression
- [§12.8.11](expressions.md#12811-element-access) Element access
- [§12.8.11.1](expressions.md#128111-general) General
- [§12.8.11.2](expressions.md#128112-array-access) Array access
- [§12.8.11.3](expressions.md#128113-indexer-access) Indexer access
- [§12.8.12](expressions.md#12812-null-conditional-element-access) Null Conditional Element Access
- [§12.8.13](expressions.md#12813-this-access) This access
- [§12.8.14](expressions.md#12814-base-access) Base access
- [§12.8.15](expressions.md#12815-postfix-increment-and-decrement-operators) Postfix increment and decrement operators
- [§12.8.16](expressions.md#12816-the-new-operator) The new operator
- [§12.8.16.1](expressions.md#128161-general) General
- [§12.8.16.2](expressions.md#128162-object-creation-expressions) Object creation expressions
- [§12.8.16.3](expressions.md#128163-object-initializers) Object initializers
- [§12.8.16.4](expressions.md#128164-collection-initializers) Collection initializers
- [§12.8.16.5](expressions.md#128165-array-creation-expressions) Array creation expressions
- [§12.8.16.6](expressions.md#128166-delegate-creation-expressions) Delegate creation expressions
- [§12.8.16.7](expressions.md#128167-anonymous-object-creation-expressions) Anonymous object creation expressions
- [§12.8.17](expressions.md#12817-the-typeof-operator) The typeof operator
- [§12.8.18](expressions.md#12818-the-sizeof-operator) The sizeof operator
- [§12.8.19](expressions.md#12819-the-checked-and-unchecked-operators) The checked and unchecked operators
- [§12.8.20](expressions.md#12820-default-value-expressions) Default value expressions
- [§12.8.21](expressions.md#12821-stack-allocation) Stack allocation
- [§12.8.22](expressions.md#12822-the-nameof-operator) The nameof operator
- [§12.8.23](expressions.md#12823-anonymous-method-expressions) Anonymous method expressions
- [§12.8.9](expressions.md#1289-null-forgiving-expressions) Null-forgiving expressions
- [§12.8.10](expressions.md#12810-invocation-expressions) Invocation expressions
- [§12.8.10.1](expressions.md#128101-general) General
- [§12.8.10.2](expressions.md#128102-method-invocations) Method invocations
- [§12.8.10.3](expressions.md#128103-extension-method-invocations) Extension method invocations
- [§12.8.10.4](expressions.md#128104-delegate-invocations) Delegate invocations
- [§12.8.11](expressions.md#12811-null-conditional-invocation-expression) Null Conditional Invocation Expression
- [§12.8.12](expressions.md#12812-element-access) Element access
- [§12.8.12.1](expressions.md#128121-general) General
- [§12.8.12.2](expressions.md#128122-array-access) Array access
- [§12.8.12.3](expressions.md#128123-indexer-access) Indexer access
- [§12.8.13](expressions.md#12813-null-conditional-element-access) Null Conditional Element Access
- [§12.8.14](expressions.md#12814-this-access) This access
- [§12.8.15](expressions.md#12815-base-access) Base access
- [§12.8.16](expressions.md#12816-postfix-increment-and-decrement-operators) Postfix increment and decrement operators
- [§12.8.17](expressions.md#12817-the-new-operator) The new operator
- [§12.8.17.1](expressions.md#128171-general) General
- [§12.8.17.2](expressions.md#128172-object-creation-expressions) Object creation expressions
- [§12.8.17.3](expressions.md#128173-object-initializers) Object initializers
- [§12.8.17.4](expressions.md#128174-collection-initializers) Collection initializers
- [§12.8.17.5](expressions.md#128175-array-creation-expressions) Array creation expressions
- [§12.8.17.6](expressions.md#128176-delegate-creation-expressions) Delegate creation expressions
- [§12.8.17.7](expressions.md#128177-anonymous-object-creation-expressions) Anonymous object creation expressions
- [§12.8.18](expressions.md#12818-the-typeof-operator) The typeof operator
- [§12.8.19](expressions.md#12819-the-sizeof-operator) The sizeof operator
- [§12.8.20](expressions.md#12820-the-checked-and-unchecked-operators) The checked and unchecked operators
- [§12.8.21](expressions.md#12821-default-value-expressions) Default value expressions
- [§12.8.22](expressions.md#12822-stack-allocation) Stack allocation
- [§12.8.23](expressions.md#12823-the-nameof-operator) The nameof operator
- [§12.8.24](expressions.md#12824-anonymous-method-expressions) Anonymous method expressions
- [§12.9](expressions.md#129-unary-operators) Unary operators
- [§12.9.1](expressions.md#1291-general) General
- [§12.9.2](expressions.md#1292-unary-plus-operator) Unary plus operator
Expand Down
Loading

0 comments on commit b2873d8

Please sign in to comment.