From 0c8a433b19b185bdbd3a7a60f1106d4c4d4681d5 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:19:18 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #68 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/issues/68 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..379d197 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/issues/68 +Your prepared branch: issue-68-37bd889a +Your prepared working directory: /tmp/gh-issue-solver-1757726353525 + +Proceed. \ No newline at end of file From 56da993eff3cd06669ea744c3b905a30b1f378cf Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:29:24 +0300 Subject: [PATCH 2/3] Fix template class/struct line formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Place class/struct definition on the next line after template declaration for better readability. This change affects both the C# and Python implementations. Changes: - Modified C# regex pattern for class/struct template declarations to add newline before class/struct - Updated Python regex patterns consistently - Added comprehensive test cases covering both struct and interface template transformations Before: template struct ISetter { After: template struct ISetter { 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../CSharpToCppTransformerTests.cs | 45 +++++++++++++++++++ .../CSharpToCppTransformer.cs | 4 +- python/cs2cpp/cs2cpp.py | 4 +- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs index edca381..83a23c6 100644 --- a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs +++ b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs @@ -35,5 +35,50 @@ public static void Main(string[] args) var actualResult = transformer.Transform(helloWorldCode); Assert.Equal(expectedResult, actualResult); } + + [Fact] + public void TemplateLineBreakTest() + { + const string inputCode = @" +struct ISetter +{ + virtual void Set(TValue value) = 0; + + virtual ~ISetter() = default; +};"; + const string expectedResult = @" +template struct ISetter; +template +struct ISetter +{ + virtual void Set(TValue value) = 0; + + virtual ~ISetter() = default; +};"; + var transformer = new CSharpToCppTransformer(); + var actualResult = transformer.Transform(inputCode); + Assert.Equal(expectedResult, actualResult); + } + + [Fact] + public void InterfaceTemplateLineBreakTest() + { + const string inputCode = @" +interface IFactory +{ + TProduct Create(); +};"; + const string expectedResult = @" +template class IFactory; +template +class IFactory +{ + public: + TProduct Create(); +};"; + var transformer = new CSharpToCppTransformer(); + var actualResult = transformer.Transform(inputCode); + Assert.Equal(expectedResult, actualResult); + } } } diff --git a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs index 2f5dceb..8de568d 100644 --- a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs +++ b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs @@ -87,13 +87,13 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"((public|protected|private|internal|abstract|static) )*(?interface|class|struct)"), "${category}", 0), // class GenericCollectionMethodsBase { // template class GenericCollectionMethodsBase { - (new Regex(@"(?\r?\n)(?[ \t]*)(?class|struct) (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template ${type} ${typeName};" + Environment.NewLine + "${indent}template ${type} ${typeName}<${typeParameters}>${typeDefinitionEnding}{", 0), + (new Regex(@"(?\r?\n)(?[ \t]*)(?class|struct) (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template ${type} ${typeName};" + Environment.NewLine + "${indent}template " + Environment.NewLine + "${indent}${type} ${typeName}<${typeParameters}>${typeDefinitionEnding}{", 0), // static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) // template static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) (new Regex(@"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)"), "template static $1 $2($4)", 0), // interface IFactory { // template class IFactory;\ntemplate class IFactory - (new Regex(@"(?\r?\n)(?[ \t]*)interface (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template class ${interface};" + Environment.NewLine + "${indent}template class ${interface}<${typeParameters}>${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0), + (new Regex(@"(?\r?\n)(?[ \t]*)interface (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template class ${interface};" + Environment.NewLine + "${indent}template " + Environment.NewLine + "${indent}class ${interface}<${typeParameters}>${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0), // template // template (new Regex(@"(?template <((, )?typename [a-zA-Z0-9]+)+, )(?[a-zA-Z0-9]+)(?(,|>))"), "${before}typename ${typeParameter}${after}", 10), diff --git a/python/cs2cpp/cs2cpp.py b/python/cs2cpp/cs2cpp.py index 44ab7bb..3bb472f 100644 --- a/python/cs2cpp/cs2cpp.py +++ b/python/cs2cpp/cs2cpp.py @@ -86,13 +86,13 @@ def __init__( SubRule(r"((public|protected|private|internal|abstract|static) )*(?Pinterface|class|struct)", r"\g", max_repeat=0), # class GenericCollectionMethodsBase { # template class GenericCollectionMethodsBase { - SubRule(r"(?P\r?\n)(?P[ \t]*)(?Pclass|struct) (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate \g \g;\n" + "\gtemplate > \g \g<\g>\g{", max_repeat=0), + SubRule(r"(?P\r?\n)(?P[ \t]*)(?Pclass|struct) (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate \g \g;\n" + "\gtemplate >\n" + "\g\g \g<\g>\g{", max_repeat=0), # static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) # template static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) SubRule(r"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)", r"template static \1 \2(\4)", max_repeat=0), # interface IFactory { # template class IFactory;\ntemplate class IFactory - SubRule(r"(?P\r?\n)(?P[ \t]*)interface (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate class \g;\n" + "\gtemplate > class \g<\g>\g{\n" + " public:", max_repeat=0), + SubRule(r"(?P\r?\n)(?P[ \t]*)interface (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate class \g;\n" + "\gtemplate >\n" + "\gclass \g<\g>\g{\n" + " public:", max_repeat=0), # template # template SubRule(r"(?Ptemplate <((, )?typename [a-zA-Z0-9]+)+, )(?P[a-zA-Z0-9]+)(?P(,|>))", r"\gtypename \g\g", max_repeat=10), From 93c22629ca44047a1f150a752c22448ac4faf7df Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 04:29:59 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 379d197..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/issues/68 -Your prepared branch: issue-68-37bd889a -Your prepared working directory: /tmp/gh-issue-solver-1757726353525 - -Proceed. \ No newline at end of file