Skip to content

Commit 5b2b8aa

Browse files
committed
Rules are now less gready (for single line patterns). This should increase the performance and reduce errors.
1 parent 0c2e6ea commit 5b2b8aa

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CSharpToCppTransformer : Transformer
3737
(new Regex(@"class ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>([^{]+){"), "template <typename $2> class $1$3{" + Environment.NewLine + " public:", null, 0),
3838
// static void TestMultipleCreationsAndDeletions<TElement>(SizedBinaryTreeMethodsBase<TElement> tree, TElement* root)
3939
// template<typename T> static void TestMultipleCreationsAndDeletions<TElement>(SizedBinaryTreeMethodsBase<TElement> tree, TElement* root)
40-
(new Regex(@"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)]+)\)"), "template <typename $3> static $1 $2($4)", null, 0),
40+
(new Regex(@"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)"), "template <typename $3> static $1 $2($4)", null, 0),
4141
// interface IFactory<out TProduct> {
4242
// template <typename TProduct> class IFactory { public:
4343
(new Regex(@"interface (?<interface>[a-zA-Z0-9]+)<(?<typeParameters>[a-zA-Z0-9 ,]+)>(?<whitespace>[^{]+){"), "template <typename...> class ${interface}; template <typename ${typeParameters}> class ${interface}<${typeParameters}>${whitespace}{" + Environment.NewLine + " public:", null, 0),
@@ -61,10 +61,10 @@ public class CSharpToCppTransformer : Transformer
6161
(new Regex(@"public static readonly (?<type>[a-zA-Z0-9]+) (?<name>[a-zA-Z0-9_]+) = new \k<type>\(\);"), "inline static ${type} ${name};", null, 0),
6262
// public static readonly string ExceptionContentsSeparator = "---";
6363
// inline static const char* ExceptionContentsSeparator = "---";
64-
(new Regex(@"public static readonly string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\""|[^""])+)"";"), "inline static const char* ${name} = \"${string}\";", null, 0),
64+
(new Regex(@"public static readonly string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\""|[^""\r\n])+)"";"), "inline static const char* ${name} = \"${string}\";", null, 0),
6565
// private const int MaxPath = 92;
6666
// static const int MaxPath = 92;
67-
(new Regex(@"private (const|static readonly) ([a-zA-Z0-9]+) ([_a-zA-Z0-9]+) = ([^;]+);"), "static const $2 $3 = $4;", null, 0),
67+
(new Regex(@"private (const|static readonly) ([a-zA-Z0-9]+) ([_a-zA-Z0-9]+) = ([^;\r\n]+);"), "static const $2 $3 = $4;", null, 0),
6868
// ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument argument) where TArgument : class
6969
// ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument& argument)
7070
(new Regex(@"(?<before> [a-zA-Z]+\(([a-zA-Z *,]+, |))(?<type>[a-zA-Z]+)(?<after>(| [a-zA-Z *,]+)\))[ \r\n]+where \k<type> : class"), "${before}${type}&${after}", null, 0),
@@ -73,10 +73,10 @@ public class CSharpToCppTransformer : Transformer
7373
(new Regex(@"protected virtual"), "virtual", null, 0),
7474
// protected abstract TElement GetFirst();
7575
// virtual TElement GetFirst() = 0;
76-
(new Regex(@"protected abstract ([^;]+);"), "virtual $1 = 0;", null, 0),
76+
(new Regex(@"protected abstract ([^;\r\n]+);"), "virtual $1 = 0;", null, 0),
7777
// TElement GetFirst();
7878
// virtual TElement GetFirst() = 0;
79-
(new Regex(@"([\r\n]+[ ]+)((?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)]*\))(;[ ]*[\r\n]+)"), "$1virtual $2 = 0$3", null, 1),
79+
(new Regex(@"([\r\n]+[ ]+)((?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(;[ ]*[\r\n]+)"), "$1virtual $2 = 0$3", null, 1),
8080
// public virtual
8181
// virtual
8282
(new Regex(@"public virtual"), "virtual", null, 0),
@@ -94,22 +94,22 @@ public class CSharpToCppTransformer : Transformer
9494
(new Regex(@"(\W)(private|protected|public|internal) "), "$1", null, 0),
9595
// SizeBalancedTree(int capacity) => a = b;
9696
// SizeBalancedTree(int capacity) { a = b; }
97-
(new Regex(@"(^\s+)(override )?(void )?([a-zA-Z0-9]+)\(([^\(]*)\)\s+=>\s+([^;]+);"), "$1$2$3$4($5) { $6; }", null, 0),
97+
(new Regex(@"(^\s+)(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);"), "$1$2$3$4($5) { $6; }", null, 0),
9898
// int SizeBalancedTree(int capacity) => a;
9999
// int SizeBalancedTree(int capacity) { return a; }
100-
(new Regex(@"(^\s+)(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(]*)\)\s+=>\s+([^;]+);"), "$1$2$3$4($5) { return $6; }", null, 0),
100+
(new Regex(@"(^\s+)(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);"), "$1$2$3$4($5) { return $6; }", null, 0),
101101
// () => Integer<TElement>.Zero,
102102
// () { return Integer<TElement>.Zero; },
103-
(new Regex(@"\(\)\s+=>\s+([^\r\n,;]+?),"), "() { return $1; },", null, 0),
103+
(new Regex(@"\(\)\s+=>\s+([^,;\r\n]+?),"), "() { return $1; },", null, 0),
104104
// => Integer<TElement>.Zero;
105105
// { return Integer<TElement>.Zero; }
106-
(new Regex(@"\)\s+=>\s+([^\r\n;]+?);"), ") { return $1; }", null, 0),
106+
(new Regex(@"\)\s+=>\s+([^;\r\n]+?);"), ") { return $1; }", null, 0),
107107
// () { return avlTree.Count; }
108108
// [&]()-> auto { return avlTree.Count; }
109-
(new Regex(@", \(\) { return ([^;]+); }"), ", [&]()-> auto { return $1; }", null, 0),
109+
(new Regex(@", \(\) { return ([^;\r\n]+); }"), ", [&]()-> auto { return $1; }", null, 0),
110110
// Count => GetSizeOrZero(Root);
111111
// GetCount() { return GetSizeOrZero(Root); }
112-
(new Regex(@"([A-Z][a-z]+)\s+=>\s+([^;]+);"), "Get$1() { return $2; }", null, 0),
112+
(new Regex(@"([A-Z][a-z]+)\s+=>\s+([^;\r\n]+);"), "Get$1() { return $2; }", null, 0),
113113
// var
114114
// auto
115115
(new Regex(@"(\W)var(\W)"), "$1auto$2", null, 0),
@@ -121,13 +121,13 @@ public class CSharpToCppTransformer : Transformer
121121
(new Regex(@"\$"""), "\"", null, 0),
122122
// Console.WriteLine("...")
123123
// printf("...\n")
124-
(new Regex(@"Console\.WriteLine\(""([^""]+)""\)"), "printf(\"$1\\n\")", null, 0),
124+
(new Regex(@"Console\.WriteLine\(""([^""\r\n]+)""\)"), "printf(\"$1\\n\")", null, 0),
125125
// throw new InvalidOperationException
126126
// throw std::exception
127127
(new Regex(@"throw new (InvalidOperationException|Exception)"), "throw std::exception", null, 0),
128128
// override void PrintNode(TElement node, StringBuilder sb, int level)
129129
// void PrintNode(TElement node, StringBuilder sb, int level) override
130-
(new Regex(@"override ([a-zA-Z0-9 \*\+]+)(\([^\)]+?\))"), "$1$2 override", null, 0),
130+
(new Regex(@"override ([a-zA-Z0-9 \*\+]+)(\([^\)\r\n]+?\))"), "$1$2 override", null, 0),
131131
// string
132132
// char*
133133
(new Regex(@"(\W)string(\W)"), "$1char*$2", null, 0),
@@ -297,7 +297,7 @@ public class CSharpToCppTransformer : Transformer
297297
(new Regex(@"#if [a-zA-Z0-9]+\s+#endif"), "", null, 0),
298298
// [Fact]
299299
//
300-
(new Regex(@"(?<firstNewLine>\r?\n|\A)(?<indent>[\t ]+)\[[a-zA-Z0-9]+(\((?<expression>((?<parenthesis>\()|(?<-parenthesis>\))|[^()]*)+)(?(parenthesis)(?!))\))?\][ \t]*(\r?\n\k<indent>)?"), "${firstNewLine}${indent}", null, 5),
300+
(new Regex(@"(?<firstNewLine>\r?\n|\A)(?<indent>[\t ]+)\[[a-zA-Z0-9]+(\((?<expression>((?<parenthesis>\()|(?<-parenthesis>\))|[^()\r\n]*)+)(?(parenthesis)(?!))\))?\][ \t]*(\r?\n\k<indent>)?"), "${firstNewLine}${indent}", null, 5),
301301
// \n ... namespace
302302
// namespace
303303
(new Regex(@"(\S[\r\n]{1,2})?[\r\n]+namespace"), "$1namespace", null, 0),

0 commit comments

Comments
 (0)