Skip to content

Parse C# with a real grammar #122

Closed

Description

@polewskm

Replace the brace scanner in src/csharp.ts with a C# parser (such as tree-sitter-c-sharp) if conditional-compilation branches with unbalanced braces make the api-compat floor fail closed too often; it needs a new dependency, which #112's plan avoided.

Found while planning #112 #113; it landed in #119.

Activity

  1. polewskm commented on Nov 1, 2026

    @polewskm
    ContributorAuthor

    Measurement for the "if it fails closed too often" condition: declarationSpans from src/csharp.ts was run over every *.cs file outside obj/ and bin/.

    Corpus Files Failed closed Files with #if
    NCodeGroup (18 C# and PowerShell repos, including Identity with 2,834 files) 3,258 0 16, all balanced
    dotnet/runtime sample (CoreLib, System.Text.Json, System.Memory, Common) 3,969 9 (0.23%) all 9 come from #if branches that each open a brace

    Conditional compilation never makes the api-compat floor fail closed on NCodeGroup code, so a parser dependency isn't justified, and the scanner stays.

    The measurement did find one real bug: a verbatim string whose text starts with an escaped quote (@"""", @"""Hi"" there") was read as a raw string literal, masked to the end of the file, and failed closed. #140 fixes it with a regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upWork a plan found and did not do

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions