From a2d34f9b333baf04b8dc21252e9a8c4bc3d611c3 Mon Sep 17 00:00:00 2001 From: Konstantin Diachenko Date: Fri, 27 Mar 2020 15:39:43 +0300 Subject: [PATCH] Part of #28. Making rules easy to translate. --- .../CSharpToCppTransformer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs index 83b92e5..bbbd4a5 100644 --- a/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs +++ b/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs @@ -120,7 +120,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"(?(private|protected|public): )?abstract (?[^;\r\n]+);"), "${access}virtual ${method} = 0;", 0), // TElement GetFirst(); // virtual TElement GetFirst() = 0; - (new Regex(@"([\r\n]+[ ]+)((?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(;[ ]*[\r\n]+)"), "$1virtual $2 = 0$3", 1), + (new Regex(@"(?[\r\n]+[ ]+)(?(?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(?;[ ]*[\r\n]+)"), "${before}virtual ${methodDeclaration} = 0${after}", 1), // protected: readonly TreeElement[] _elements; // protected: TreeElement _elements[N]; (new Regex(@"(?(private|protected|public): )?readonly (?[a-zA-Z<>0-9]+)([\[\]]+) (?[_a-zA-Z0-9]+);"), "${access}${type} ${name}[N];", 0), @@ -186,7 +186,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"(?return\s*)\((?[^\)\n]+)\)(?!\()(?\W)"), "${before}{${values}}${after}", 0), // string // std::string - (new Regex(@"(\W)(?\W)(?\W)"), "${before}std::string${after}", 0), // System.ValueTuple // std::tuple (new Regex(@"(?\W)(System\.)?ValueTuple(?!\s*=|\()(?\W)"), "${before}std::tuple${after}", 0), @@ -234,7 +234,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"(struct|class) ([a-zA-Z0-9]+)(\s+){([\sa-zA-Z0-9;:_]+?)}([^;])"), "$1 $2$3{$4};$5", 0), // class Program { } // class Program { }; - (new Regex(@"(struct|class) ([a-zA-Z0-9]+[^\r\n]*)([\r\n]+(?[\t ]*)?)\{([\S\s]+?[\r\n]+\k)\}([^;]|$)"), "$1 $2$3{$4};$5", 0), + (new Regex(@"(?struct|class) (?[a-zA-Z0-9]+[^\r\n]*)(?[\r\n]+(?[\t ]*)?)\{(?[\S\s]+?[\r\n]+\k)\}(?[^;]|$)"), "${type} ${name}${beforeBody}{${body}};${afterBody}", 0), // class SizedBinaryTreeMethodsBase : GenericCollectionMethodsBase // class SizedBinaryTreeMethodsBase : public GenericCollectionMethodsBase (new Regex(@"(struct|class) ([a-zA-Z0-9]+)(<[a-zA-Z0-9 ,]+>)? : ([a-zA-Z0-9]+)"), "$1 $2$3 : public $4", 0), @@ -282,7 +282,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"class ([a-zA-Z0-9]+Tests)"), "TEST_CLASS($1)", 0), // Assert.Equal // Assert::AreEqual - (new Regex(@"(Assert)\.((Not)?Equal)"), "$1::Are$2", 0), + (new Regex(@"(?Assert)\.(?(Not)?Equal)"), "${type}::Are${method}", 0), // Assert.Throws // Assert::ExpectException (new Regex(@"(Assert)\.Throws"), "$1::ExpectException", 0), @@ -303,7 +303,7 @@ public class CSharpToCppTransformer : TextTransformer (new Regex(@"Console\.WriteLine\(""([^""\r\n]+)""\)"), "printf(\"$1\\n\")", 0), // TElement Root; // TElement Root = 0; - (new Regex(@"(\r?\n[\t ]+)(private|protected|public)?(: )?([a-zA-Z0-9:_]+(?\r?\n[\t ]+)(?(private|protected|public)(: )?)?(?[a-zA-Z0-9:_]+(?[_a-zA-Z0-9]+);"), "${before}${access}${type} ${name} = 0;", 0), // TreeElement _elements[N]; // TreeElement _elements[N] = { {0} }; (new Regex(@"(\r?\n[\t ]+)(private|protected|public)?(: )?([a-zA-Z0-9]+) ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];"), "$1$2$3$4 $5[$6] = { {0} };", 0),