Files
dsarno cda07f7ff1 fix: ManageScript delimiter checking for C# string variants (#745)
* fix: extract CSharpLexer and fix delimiter checking for C# string variants

The ManageScript tool had 7 copy-pasted inline lexers that did not handle
verbatim strings (@""), interpolated strings ($""), or raw string literals,
causing false unbalanced braces errors on valid C# code like $"Score: {score}".

Extract a shared CSharpLexer struct that correctly handles all C# string/comment
types, rewrite all callers to use it, and remove redundant CheckScopedBalance
and ValidateBasicStructure methods. Fix IndexOfClassToken to skip matches inside
strings and comments. Fix anchor_insert to use depth-based best-match selection
instead of picking the first regex match (which selected method-level braces
over class-level ones).

On the Python side, add _is_in_string_context and _brace_depth_at_positions
helpers, and rewrite _find_best_closing_brace_match with depth-based scoring
that filters out matches inside strings/comments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: consolidate duplicate Python C# lexer into shared _iter_csharp_tokens generator

_is_in_string_context and _brace_depth_at_positions duplicated ~150 lines
of the same C# string/comment lexer. Extract a shared generator and rewrite
both as thin wrappers (-59 net lines, same behavior).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: handle interpolated raw strings and make anchor ops use best-match

1. Add """...""" and $"""...""" (C# 11 interpolated raw string)
   support to both C# CSharpLexer and Python _iter_csharp_tokens.
   Dollar count determines interpolation threshold (N dollars = N
   consecutive braces to open an interpolation hole).

2. Make anchor_delete and anchor_replace use FindBestAnchorMatch
   (same as anchor_insert) instead of rx.Match for consistent
   target selection when multiple anchors match.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: guard unterminated comment overshoot and filter on brace position

1. Guard _pos += 2 after /* comment scanning in both
   SkipInterpolatedStringBody and SkipInterpolatedRawStringBody —
   only advance past */ when the terminator was actually found,
   preventing overshoot past _end on unterminated comments.

2. Filter _find_best_closing_brace_match on the actual }
   position rather than m.start() (which points at leading
   whitespace for patterns like ^\s*}\s*$).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 20:24:57 -08:00
..
2026-01-30 18:39:21 -04:00
2026-01-30 18:39:21 -04:00