diff --git a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs index 2f5dceb..9445b86 100644 --- a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs +++ b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs @@ -124,7 +124,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"(?(private|protected|public): )?static readonly (?[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?[a-zA-Z0-9_]+) = new \k\((?[^\n]+)\);"), "${access}inline static ${type} ${name} = ${type}(${arguments});", 0), // public: static readonly string ExceptionContentsSeparator = "---"; // public: inline static std::string ExceptionContentsSeparator = "---"; - (new Regex(@"(?(private|protected|public): )?(const|static readonly) string (?[a-zA-Z0-9_]+) = ""(?(\\""|[^""\r\n])+)"";"), "${access}inline static std::string ${name} = \"${string}\";", 0), + (new Regex(@"(?(private|protected|public): )?(const|static readonly) string (?[a-zA-Z0-9_]+) = ""(?(\\""|[^""\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(@"(?(private|protected|public): )?(const|static readonly) (?[a-zA-Z0-9]+) (?[_a-zA-Z0-9]+) = (?[^;\r\n]+);"), "${access}inline static const ${type} ${name} = ${value};", 0), diff --git a/experiments/Program.cs b/experiments/Program.cs new file mode 100644 index 0000000..edc0ef5 --- /dev/null +++ b/experiments/Program.cs @@ -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); + } +} \ No newline at end of file diff --git a/experiments/TestTransformations.csproj b/experiments/TestTransformations.csproj new file mode 100644 index 0000000..8738f19 --- /dev/null +++ b/experiments/TestTransformations.csproj @@ -0,0 +1,9 @@ + + + Exe + net8 + + + + + \ No newline at end of file diff --git a/experiments/readonly_test.cs b/experiments/readonly_test.cs new file mode 100644 index 0000000..466d331 --- /dev/null +++ b/experiments/readonly_test.cs @@ -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"; +} \ No newline at end of file