Skip to content

feat: add C# 12 collection expression support#409

Closed
slang25 wants to merge 1 commit intotree-sitter:masterfrom
slang25:slang25/add-agents-md
Closed

feat: add C# 12 collection expression support#409
slang25 wants to merge 1 commit intotree-sitter:masterfrom
slang25:slang25/add-agents-md

Conversation

@slang25
Copy link
Copy Markdown

@slang25 slang25 commented Feb 11, 2026

Summary

  • Implements grammar rules for collection expressions ([e1, e2, ..e3]) and spread elements (..)
  • Resolves syntax conflicts with list patterns and range expressions through precedence rules and GLR declarations
  • Adds element_binding_expression handling to initializer expressions to preserve dictionary/indexer initialization syntax
  • All 164 existing tests pass, plus 9 new collection expression test cases

Test Coverage

Collection expressions tested for: empty literals, simple elements, spread operators, trailing commas, nested collections, method calls in spreads, use as arguments, and conditional spreads with parentheses.

🤖 Generated with Claude Code

@slang25 slang25 force-pushed the slang25/add-agents-md branch 3 times, most recently from 3fb31be to 110f489 Compare February 11, 2026 21:12
Implement grammar rules for collection expressions ([e1, e2, ..e3]) and spread elements
(..). Resolves syntax conflicts with list patterns and range expressions through
precedence rules and GLR conflict declarations. All 164 tests pass, including 9 new
collection expression test cases covering empty, simple, nested, and spread scenarios.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@guillaume86
Copy link
Copy Markdown

I independently worked on the same feature in #414 and validated this PR against the pathological case from my issue comment: (int[])[Constants.Region.US, Constants.Region.EU, ...] inside a foreach was causing greedy error recovery that swallowed subsequent method declarations.

Confirmed this PR fully fixes it — all methods parse correctly with zero ERROR nodes. Ternary + collection (condition ? [x] : [y]) also works.

The _initializer_index_assignment approach to preserve element_binding_expression in initializer contexts is cleaner than what I had. 👍

Note: the CI parse-examples step will likely fail due to pre-existing issues — PowerToys and NUnit repos have been updated since the last master CI run, introducing files at new paths that aren't in the exclude list yet. See the exclude list update in my (now-closed) #414 for the specific files that need adding.

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.

2 participants