@@ -46,7 +46,7 @@ public class CSharpToCppTransformer : Transformer
46
46
( new Regex ( @"Action<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)" ) , "std::function<void($1)> $2" , null , 0 ) ,
47
47
// private const int MaxPath = 92;
48
48
// static const int MaxPath = 92;
49
- ( new Regex ( @"private const ([a-zA-Z0-9]+) ([_a-zA-Z0-9]+) = ([a-zA-Z0-9 ]+);" ) , "static const $1 $2 = $3 ;" , null , 0 ) ,
49
+ ( new Regex ( @"private ( const|static readonly) ([a-zA-Z0-9]+) ([_a-zA-Z0-9]+) = ([^; ]+);" ) , "static const $2 $3 = $4 ;" , null , 0 ) ,
50
50
// protected virtual
51
51
// virtual
52
52
( new Regex ( @"protected virtual" ) , "virtual" , null , 0 ) ,
@@ -70,7 +70,10 @@ public class CSharpToCppTransformer : Transformer
70
70
( new Regex ( @"(\W)(private|protected|public|internal) " ) , "$1" , null , 0 ) ,
71
71
// SizeBalancedTree(int capacity) => a = b;
72
72
// SizeBalancedTree(int capacity) { a = b; }
73
- ( new Regex ( @"(^\s+)(override )?(void )?([a-zA-Z0-9]+)\(([^\(]+)\)\s+=>\s+([^;]+);" ) , "$1$2$3$4($5) { $6; }" , null , 0 ) ,
73
+ ( new Regex ( @"(^\s+)(override )?(void )?([a-zA-Z0-9]+)\(([^\(]*)\)\s+=>\s+([^;]+);" ) , "$1$2$3$4($5) { $6; }" , null , 0 ) ,
74
+ // int SizeBalancedTree(int capacity) => a;
75
+ // int SizeBalancedTree(int capacity) { return a; }
76
+ ( new Regex ( @"(^\s+)(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(]*)\)\s+=>\s+([^;]+);" ) , "$1$2$3$4($5) { return $6; }" , null , 0 ) ,
74
77
// () => Integer<TElement>.Zero,
75
78
// () { return Integer<TElement>.Zero; },
76
79
( new Regex ( @"\(\)\s+=>\s+([^\r\n,;]+?)," ) , "() { return $1; }," , null , 0 ) ,
@@ -149,8 +152,8 @@ public class CSharpToCppTransformer : Transformer
149
152
// ref TElement
150
153
// TElement*
151
154
( new Regex ( @"( |\()ref ([a-zA-Z0-9]+) " ) , "$1$2* " , null , 0 ) ,
152
- // ref sizeBalancedTree2 .Root
153
- // &sizeBalancedTree2 ->Root
155
+ // ref sizeBalancedTree .Root
156
+ // &sizeBalancedTree ->Root
154
157
( new Regex ( @"ref ([a-zA-Z0-9]+)\.([a-zA-Z0-9\*]+)" ) , "&$1->$2" , null , 0 ) ,
155
158
// ref GetElement(node).Right
156
159
// &GetElement(node)->Right
@@ -175,7 +178,7 @@ public class CSharpToCppTransformer : Transformer
175
178
( new Regex ( @"(\r?\n[\t ]+)([a-zA-Z0-9]+) ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];" ) , "$1$2 $3[$4] = { {0} };" , null , 0 ) ,
176
179
// auto path = new TElement[MaxPath];
177
180
// TElement path[MaxPath] = { {0} };
178
- ( new Regex ( @"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([a -zA-Z0-9]+)\];" ) , "$1$3 $2[$4] = { {0} };" , null , 0 ) ,
181
+ ( new Regex ( @"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a -zA-Z0-9]+)\];" ) , "$1$3 $2[$4] = { {0} };" , null , 0 ) ,
179
182
// Insert scope borders.
180
183
// auto added = new HashSet<TElement>();
181
184
// ~!added!~std::unordered_set<TElement> added;
@@ -207,6 +210,23 @@ public class CSharpToCppTransformer : Transformer
207
210
// ~!random!~
208
211
//
209
212
( new Regex ( @"~!(?<pointer>[a-zA-Z0-9]+)!~" ) , "" , null , 5 ) ,
213
+ // Insert method body scope starts.
214
+ // void PrintNodes(TElement node, StringBuilder sb, int level) {
215
+ // void PrintNodes(TElement node, StringBuilder sb, int level) {/*method-start*/
216
+ ( new Regex ( @"(?<start>\r?\n[\t ]+)(?<prefix>((virtual )?[a-zA-Z0-9:_]+ )?)(?<method>[a-zA-Z][a-zA-Z0-9]*)\((?<arguments>[^\)]*)\)(?<override>( override)?)(?<separator>[ \t\r\n]*)\{(?<end>[^~])" ) , "${start}${prefix}${method}(${arguments})${override}${separator}{/*method-start*/${end}" , null , 0 ) ,
217
+ // Insert method body scope ends.
218
+ // {/*method-start*/...}
219
+ // {/*method-start*/.../*method-end*/}
220
+ ( new Regex ( @"\{/\*method-start\*/(?<body>((?<bracket>\{)|(?<-bracket>\})|[^\{\}]*)+)\}" ) , "{/*method-start*/${body}/*method-end*/}" , null , 0 ) ,
221
+ // Inside method bodies replace:
222
+ // GetFirst(
223
+ // this->GetFirst(
224
+ //(new Regex(@"(?<separator>(\(|, |([\W]) |return ))(?<!(->|\* ))(?<method>(?!sizeof)[a-zA-Z0-9]+)\((?!\) \{)"), "${separator}this->${method}(", null, 1),
225
+ ( new Regex ( @"(?<scope>/\*method-start\*/)(?<before>((?<!/\*method-end\*/)(.|\n))*?)(?<separator>[\W](?<!(::|\.|->)))(?<method>(?!sizeof)[a-zA-Z0-9]+)\((?!\) \{)(?<after>(.|\n)*?)(?<scopeEnd>/\*method-end\*/)" ) , "${scope}${before}${separator}this->${method}(${after}${scopeEnd}" , null , 100 ) ,
226
+ // Remove scope borders.
227
+ // /*method-start*/
228
+ //
229
+ ( new Regex ( @"/\*method-(start|end)\*/" ) , "" , null , 0 ) ,
210
230
} . Cast < ISubstitutionRule > ( ) . ToList ( ) ;
211
231
212
232
public static readonly IList < ISubstitutionRule > LastStage = new List < SubstitutionRule >
@@ -231,7 +251,7 @@ public class CSharpToCppTransformer : Transformer
231
251
( new Regex ( @"#if [a-zA-Z0-9]+\s+#endif" ) , "" , null , 0 ) ,
232
252
// [Fact]
233
253
//
234
- ( new Regex ( @"(?<firstNewLine>\r?\n|\A)(?<indent>[\t ]+)\[[a-zA-Z0-9]+(\((?<expression>((?<parenthesis>\()|(?<-parenthesis>\))|[^()]*)+)(?(parenthesis)(?!))\))?\]\s *(\r?\n\k<indent>)?" ) , "${firstNewLine}${indent}" , null , 5 ) ,
254
+ ( 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 ) ,
235
255
// \n ... namespace
236
256
// namespace
237
257
( new Regex ( @"(\S[\r\n]{1,2})?[\r\n]+namespace" ) , "$1namespace" , null , 0 ) ,
0 commit comments