Skip to content

Commit df5993a

Browse files
konardclaude
andcommitted
Fix Python regex group counting inconsistency with C# (issue #28)
Replace numbered groups with named groups to ensure consistent behavior between C# and Python regex engines when counting inner groups. Changes: - Updated C# regex pattern from numbered groups ($1, $2, etc.) to named groups (${type}, ${name}, etc.) - Updated Python regex patterns to use named group syntax (?P<name>) and backreferences (?P=name) - Fixed all Python \k<name> backreferences to use (?P=name) syntax - Both versions now use consistent named group patterns for maintainability This resolves the issue where Python regex counts inner groups differently than C# regex, ensuring both transformers produce identical results. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6e14ad5 commit df5993a

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public class CSharpToCppTransformer : TextTransformer
283283
(new Regex(@"(?<before>\r?\n)(?<indent>[ \t]*)interface (?<interface>[a-zA-Z_]\w*)(?<typeDefinitionEnding>[^{]+){"), "${before}${indent}class ${interface}${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0),
284284
// struct TreeElement { }
285285
// struct TreeElement { };
286-
(new Regex(@"(struct|class) ([a-zA-Z0-9]+)(\s+){([\sa-zA-Z0-9;:_]+?)}([^;])"), "$1 $2$3{$4};$5", 0),
286+
(new Regex(@"(?<type>struct|class) (?<name>[a-zA-Z0-9]+)(?<whitespace>\s+){(?<body>[\sa-zA-Z0-9;:_]+?)}(?<after>[^;])"), "${type} ${name}${whitespace}{${body}};${after}", 0),
287287
// class Program { }
288288
// class Program { };
289289
(new Regex(@"(?<type>struct|class) (?<name>[a-zA-Z0-9]+[^\r\n]*)(?<beforeBody>[\r\n]+(?<indentLevel>[\t ]*)?)\{(?<body>[\S\s]+?[\r\n]+\k<indentLevel>)\}(?<afterBody>[^;]|$)"), "${type} ${name}${beforeBody}{${body}};${afterBody}", 0),

0 commit comments

Comments
 (0)