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 @@ -124,7 +124,7 @@ public class CSharpToCppTransformer : TextTransformer
(new Regex(@"(?<access>(private|protected|public): )?static readonly (?<type>[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?<name>[a-zA-Z0-9_]+) = new \k<type>\((?<arguments>[^\n]+)\);"), "${access}inline static ${type} ${name} = ${type}(${arguments});", 0),
// public: static readonly string ExceptionContentsSeparator = "---";
// public: inline static std::string ExceptionContentsSeparator = "---";
(new Regex(@"(?<access>(private|protected|public): )?(const|static readonly) string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\\""|[^""\r\n])+)"";"), "${access}inline static std::string ${name} = \"${string}\";", 0),
(new Regex(@"(?<access>(private|protected|public): )?(const|static readonly) string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\\""|[^""\r\n])+)"";"), "${access}inline static const std::string ${name} = \"${string}\";", 0),
// private: const int MaxPath = 92;
// private: inline static const int MaxPath = 92;
(new Regex(@"(?<access>(private|protected|public): )?(const|static readonly) (?<type>[a-zA-Z0-9]+) (?<name>[_a-zA-Z0-9]+) = (?<value>[^;\r\n]+);"), "${access}inline static const ${type} ${name} = ${value};", 0),
Expand Down
34 changes: 34 additions & 0 deletions experiments/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.IO;
using Platform.RegularExpressions.Transformer.CSharpToCpp;

class Program
{
static void Main()
{
string inputCode = @"// Test cases for readonly transformations
public class TestClass
{
// Test string readonly
public static readonly string ExceptionContentsSeparator = ""---"";
private static readonly string PrivateMessage = ""error"";

// Test other types readonly
public static readonly int MaxPath = 92;
private static readonly bool IsEnabled = true;

// Test const (should already work)
private const int ConstValue = 42;
public const string ConstString = ""test"";
}";

Console.WriteLine("Original code:");
Console.WriteLine(inputCode);
Console.WriteLine("\n" + new string('=', 50) + "\n");

var transformer = new CSharpToCppTransformer();
string transformed = transformer.Transform(inputCode);
Console.WriteLine("Transformed code:");
Console.WriteLine(transformed);
}
}
9 changes: 9 additions & 0 deletions experiments/TestTransformations.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/Platform.RegularExpressions.Transformer.CSharpToCpp.csproj" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions experiments/readonly_test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Test cases for readonly transformations
public class TestClass
{
// Test string readonly
public static readonly string ExceptionContentsSeparator = "---";
private static readonly string PrivateMessage = "error";

// Test other types readonly
public static readonly int MaxPath = 92;
private static readonly bool IsEnabled = true;

// Test const (should already work)
private const int ConstValue = 42;
public const string ConstString = "test";
}
Loading