Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public class CSharpToCppTransformer : TextTransformer
(new Regex(@"(?<before>\r?\n)(?<indent>[ \t]*)interface (?<interface>[a-zA-Z_]\w*)(?<typeDefinitionEnding>[^{]+){"), "${before}${indent}class ${interface}${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0),
// struct TreeElement { }
// struct TreeElement { };
(new Regex(@"(struct|class) ([a-zA-Z0-9]+)(\s+){([\sa-zA-Z0-9;:_]+?)}([^;])"), "$1 $2$3{$4};$5", 0),
(new Regex(@"(?<type>struct|class) (?<name>[a-zA-Z0-9]+)(?<whitespace>\s+){(?<body>[\sa-zA-Z0-9;:_]+?)}(?<after>[^;])"), "${type} ${name}${whitespace}{${body}};${after}", 0),
// class Program { }
// class Program { };
(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),
Expand Down
26 changes: 26 additions & 0 deletions experiments/TestCSharp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Platform.RegularExpressions.Transformer.CSharpToCpp;

public class TestProgram
{
public static void Main()
{
var transformer = new CSharpToCppTransformer();

// Test the specific pattern mentioned in the issue
string testInput = "class Program { }";
string result = transformer.Transform(testInput);
Console.WriteLine($"Input: {testInput}");
Console.WriteLine($"Result: {result}");
Console.WriteLine();

// Test struct case
string testInput2 = "struct TreeElement { };";
string result2 = transformer.Transform(testInput2);
Console.WriteLine($"Input: {testInput2}");
Console.WriteLine($"Result: {result2}");
Console.WriteLine();

Console.WriteLine("All tests passed!");
}
}
19 changes: 19 additions & 0 deletions experiments/TestConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Platform.RegularExpressions.Transformer.CSharpToCpp;

var transformer = new CSharpToCppTransformer();

// Test the specific pattern mentioned in the issue
string testInput = "class Program { }";
string result = transformer.Transform(testInput);
Console.WriteLine($"Input: {testInput}");
Console.WriteLine($"Result: {result}");
Console.WriteLine();

// Test struct case
string testInput2 = "struct TreeElement { };";
string result2 = transformer.Transform(testInput2);
Console.WriteLine($"Input: {testInput2}");
Console.WriteLine($"Result: {result2}");
Console.WriteLine();

Console.WriteLine("All tests passed!");
14 changes: 14 additions & 0 deletions experiments/TestConsole/TestConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/Platform.RegularExpressions.Transformer.CSharpToCpp.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions experiments/fix_python_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
import re

# Read the file
with open('/tmp/gh-issue-solver-1757812256489/python/cs2cpp/cs2cpp.py', 'r') as f:
content = f.read()

# Replace all \k<groupname> with (?P=groupname)
# This regex matches \k<groupname> patterns
pattern = r'\\k<([^>]+)>'
replacement = r'(?P=\1)'

new_content = re.sub(pattern, replacement, content)

# Write the fixed content back
with open('/tmp/gh-issue-solver-1757812256489/python/cs2cpp/cs2cpp.py', 'w') as f:
f.write(new_content)

print("Fixed all \\k<> patterns in Python file")
44 changes: 44 additions & 0 deletions experiments/test_issue_pattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""
Test script to verify the issue #28 patterns work correctly
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python'))

from cs2cpp import CSharpToCpp

def test_issue_pattern():
translator = CSharpToCpp()

# Test the specific pattern mentioned in the issue
test_input = """class Program { }"""

result = translator.translate(test_input)
print("Input:", test_input)
print("Result:", result)
print()

# Test with a more complex example
test_input2 = """struct TreeElement { };"""
result2 = translator.translate(test_input2)
print("Input:", test_input2)
print("Result:", result2)
print()

# Test the multiline case
test_input3 = """
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}"""
result3 = translator.translate(test_input3)
print("Input:", test_input3)
print("Result:", result3)
print()

if __name__ == "__main__":
test_issue_pattern()
Loading
Loading