Skip to content

[new grammar] csharp v8-spec (ECMA-334 8th edition)#4789

Draft
kaby76 wants to merge 6 commits intoantlr:masterfrom
kaby76:g4-4783-v8
Draft

[new grammar] csharp v8-spec (ECMA-334 8th edition)#4789
kaby76 wants to merge 6 commits intoantlr:masterfrom
kaby76:g4-4783-v8

Conversation

@kaby76
Copy link
Contributor

@kaby76 kaby76 commented Mar 13, 2026

  • Add CSharp v8-spec grammar targeting ECMA-334 8th edition (C# 8.0)
  • Convert grammars to target-agnostic format: all inline actions replaced with this.PascalCase() calls; implementations in CSharpLexerBase.cs and CSharpParserBase.cs under CSharp/
  • Add superClass options in both .g4 files; remove empty support .g4 imports
  • Port v7 preprocessor approach: DIRECTIVE channel, DIRECTIVE_MODE, NextToken() override, SkipFalseBlock(), recursive-descent evaluator, --DSYM CLI support
  • Restore parse tree nodes elided by mutual-left-recursion removal via As*() reflection-based methods in CSharpParserBase
  • Add using_declaration to declaration_statement (C# 8 non-block using var)
  • Add MS extension expressions: __makeref, __reftype, __refvalue
  • Add 11 C# 8 example test files (CSharp8*.cs) covering switch expressions, tuple/positional patterns, readonly members, default interface members, using declarations, static local functions, nullable reference types, async streams, indices and ranges, ??= operator, and misc features
  • Add test-dotnet.sh for C# 8 (LangVersion=8.0, Nullable=enable)
  • Fix AllInOneNoPreprocessor.cs: invalid expression statements (i << 5) replaced with assignments; invalid ref-returning expression body fixed

kaby76 and others added 6 commits March 13, 2026 17:12
- Add CSharp v8-spec grammar targeting ECMA-334 8th edition (C# 8.0)
- Convert grammars to target-agnostic format: all inline actions replaced
  with this.PascalCase() calls; implementations in CSharpLexerBase.cs and
  CSharpParserBase.cs under CSharp/
- Add superClass options in both .g4 files; remove empty support .g4 imports
- Port v7 preprocessor approach: DIRECTIVE channel, DIRECTIVE_MODE,
  NextToken() override, SkipFalseBlock(), recursive-descent evaluator,
  --DSYM CLI support
- Restore parse tree nodes elided by mutual-left-recursion removal via
  As*() reflection-based methods in CSharpParserBase
- Add using_declaration to declaration_statement (C# 8 non-block using var)
- Add MS extension expressions: __makeref, __reftype, __refvalue
- Add 11 C# 8 example test files (CSharp8*.cs) covering switch expressions,
  tuple/positional patterns, readonly members, default interface members,
  using declarations, static local functions, nullable reference types,
  async streams, indices and ranges, ??= operator, and misc features
- Add test-dotnet.sh for C# 8 (LangVersion=8.0, Nullable=enable)
- Fix AllInOneNoPreprocessor.cs: invalid expression statements (i << 5)
  replaced with assignments; invalid ref-returning expression body fixed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CSharpParser.g4: make stackalloc_initializer_element_list optional so
that 'stackalloc T[] {}' (zero-length) parses correctly. This form is
valid C# 7.3+ and accepted by Roslyn but was rejected by the grammar.

Also adds testing/test.sh which clones Roslyn at version-2.8.2, extracts
C# source snippets from tests tagged LangVersion.CSharp7_3, and verifies
each one parses cleanly with the ANTLR grammar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant