Skip to content

C#: a verbatim interpolated string ending in }""" is rejected by the bundled grammar — file partially extracted, warning points at the recovery line #3376

Closed

Description

@PatrHofmann

Summary

In a verbatim interpolated string ($@"…" / @$"…"), an escaped quote "" that sits
immediately after an interpolation hole's closing } and immediately before the string
terminator is rejected by the bundled tree-sitter-c-sharp 0.23.5 grammar. In short: the
literal ends with }""".

It is valid C#, dotnet build is happy, and every neighbouring spelling parses. The file it
appears in is partially extracted, so the members after the offending line are missing from
graph.json.

The reported line is the recovery point, not the cause. In my case the construct is on lines
72 and 83 and the warning said first error at line 76, which sent me looking at an
[InlineData("Config")] attribute for a while.

Reproduction — grammar level

graphify 0.9.46, tree-sitter-c-sharp 0.23.5. No extraction run needed:

from tree_sitter import Language, Parser
import tree_sitter_c_sharp as tscs
p = Parser(Language(tscs.language()))

W = 'class C { void M(string e) { var s = %s; } }\n'
def check(lit):
    print("ERROR" if p.parse((W % lit).encode()).root_node.has_error else "ok   ", lit)

check(r'$@"a""{e}"""')   # ERROR  <-- valid C#, the real-world shape
check(r'$@"a{e}"""')     # ERROR
check(r'$@"{e}"""')      # ERROR
check(r'@$"a""{e}"""')   # ERROR  (other prefix order, same failure)

check(r'$@"a{e}""b"')    # ok     escape after the hole, but not at the end
check(r'$@"a{e}b"""')    # ok     escape at the end, but text between hole and escape
check(r'$@"{e}=""x"""')  # ok     hole and a trailing escape, hole not adjacent to it
check(r'$@"a""{e}""b"')  # ok     escape, hole, escape - not at the end
check(r'$@"a""x"""')     # ok     escape at the end, no hole at all
check(r'$@"a{e}"')       # ok     hole, no escape
check(r'@"a{e}"""')      # ok     no `$`, so `{e}` is literal text
check(r'$"a\"{e}\""')    # ok     regular interpolated string
check(r'$$"""a={{e}}"""')# ok     raw interpolated string

Each passing line differs from a failing one in exactly one property, so the trigger is
neither "verbatim interpolated string" nor "escape at the end" nor "escape plus hole" on its
own — it is specifically the } "" " adjacency.

What it costs

Small but silent-ish, and it hides in a construct that is idiomatic wherever a test asserts on
a quoted attribute:

Assert.Contains($@"Content=""{expected}""", xaml);   // XAML / XML / HTML attribute needle

On a 258-file C#/WPF repo it is 1 file — but that one file is the project's UI-language guard,
and the agent instructions for this repo tell the assistant to query the graph before reading
source. A guard that is only partially in the graph is worse than one that is absent, because
nothing signals the gap at query time.

The #2551 warning did its job here: without that line I would have had no reason to suspect
the parser at all. Same class as #2551 (Kotlin one-line type bodies) and #2520 (.luau),
different language and trigger.

Workaround

A regular interpolated string with backslash escapes is byte-identical in output and parses:

Assert.Contains($@"Content=""{expected}""", xaml);   // trips the grammar
Assert.Contains($"Content=\"{expected}\"", xaml);    // same string, parses

Environment

graphify 0.9.46
tree-sitter 0.26.0
tree-sitter-c-sharp 0.23.5
OS Windows 10 22H2
Python 3.12

Activity

  1. rohit-jsfreaky commented on Sep 16, 2026

    @rohit-jsfreaky
    Contributor

    Ran your grammar table verbatim on tree-sitter-c-sharp 0.23.5 — all four failing spellings error, all nine neighbours parse. The } "" " adjacency is exactly it.

    The extraction cost shows up as you describe. A class with six methods and the literal in the third:

    warning: Config.cs (first error at line 20, 5 symbol(s) extracted)
    extracted: BeforeOne()  BeforeTwo()  Offender()  Config  Config.cs  Demo
    missing:   AfterOne()   AfterTwo()   AfterThree()
    

    0.23.5 is the newest release on PyPI and the pin already allows <0.25, so there is no grammar bump to take.

    Opening a PR that neutralizes only the trailing "" escape, through the source_override seam extract_js / extract_vue / extract_cpp already use. It is byte-length preserving, so no source_location shifts — on the file above exactly 2 bytes change and every member still reports the line it is really on. It also steps aside entirely when a file already parses, and falls back to the original if the rewrite does not clear the errors.

    To be clear about scope: this does not fix the grammar, which is where the bug really is. It stops graphify silently dropping symbols while the grammar is what it is. If you would rather wait for an upstream fix, that is a reasonable call.

  2. safishamsi commented on Oct 12, 2026

    @safishamsi
    Member

    Fixed in v0.9.88 (graphifyy 0.9.88 on PyPI) via #3612.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions