Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update antlr test harness #1177

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading