@@ -313,8 +313,8 @@ public class CSharpToCppTransformer : TextTransformer
313313 ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)(struct|class) (?<type>[a-zA-Z0-9]+(<((?!\s*:\s*)[^{\n])+>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?<middle>((?!class|struct).|\n)+?)(?<toStringDeclaration>(?<access>(private|protected|public): )override const char\* ToString\(\))" ) , "${classDeclarationBegin}/*~${type}~*/${middle}${toStringDeclaration}" , 0 ) ,
314314 // Inside the scope of ~!_exceptionsBag!~ replace:
315315 // public: override const char* ToString() { return ...; }
316- // public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator << (std::ostream &out, const A &obj) { return out << (std::string)obj; }
317- ( new Regex ( @"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override const char\* ToString\(\) (?<toStringMethodBody>{[^}\n]+}))" ) , "${scope}${separator}${before}" + Environment . NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment . NewLine + Environment . NewLine + "${indent}${access}friend std::ostream & operator << (std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }" , 0 ) ,
316+ // public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator <<(std::ostream &out, const A &obj) { return out << (std::string)obj; }
317+ ( new Regex ( @"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override const char\* ToString\(\) (?<toStringMethodBody>{[^}\n]+}))" ) , "${scope}${separator}${before}" + Environment . NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment . NewLine + Environment . NewLine + "${indent}${access}friend std::ostream & operator <<(std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }" , 0 ) ,
318318 // Remove scope borders.
319319 // /*~Range~*/
320320 //
@@ -471,14 +471,30 @@ public class CSharpToCppTransformer : TextTransformer
471471 // const std::string& message
472472 // const std::string& message/*~message~*/
473473 ( new Regex ( @"(?<before>\(| )(?<variableDefinition>(const )?((std::)?string&?|char\*) (?<variable>[_a-zA-Z0-9]+))(?<after>\W)" ) , "${before}${variableDefinition}/*~${variable}~*/${after}" , 0 ) ,
474- // Inside the scope of ~! message!~ replace:
474+ // Inside the scope of /*~ message~*/ replace:
475475 // Platform::Converters::To<std::string>(message)
476476 // message
477477 ( new Regex ( @"(?<scope>/\*~(?<variable>[_a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<variable>~\*/)(.|\n))*?)Platform::Converters::To<std::string>\(\k<variable>\)" ) , "${scope}${separator}${before}${variable}" , 10 ) ,
478478 // Remove scope borders.
479479 // /*~ex~*/
480480 //
481481 ( new Regex ( @"/\*~[_a-zA-Z0-9]+~\*/" ) , "" , 0 ) ,
482+ // Insert scope borders.
483+ // class Range<T> {
484+ // class Range<T> {/*~type~Range~*/
485+ ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)(struct|class) (?<type>[a-zA-Z0-9]+(<((?!\s*:\s*)[^{\n])+>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)" ) , "${classDeclarationBegin}/*~type~${type}~*/" , 0 ) ,
486+ // Inside the scope of /*~type~Range<T>~*/ insert inner scope and replace:
487+ // public: static implicit operator std::tuple<T, T>(Range<T> range)
488+ // public: operator std::tuple<T, T>(Range<T> range) {/*~variable~Range<T>~*/
489+ ( new Regex ( @"(?<scope>/\*~type~(?<type>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<type>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<argumentDeclaration>\k<type> (?<variable>[a-zA-Z0-9]+))(?<after>\)\s*\n?\s*{)" ) , "${scope}${separator}${before}${access}operator ${targetType}(${argumentDeclaration}${after}/*~variable~${variable}~*/" , 10 ) ,
490+ // Inside the scope of /*~variable~range~*/ replace:
491+ // range.Minimum
492+ // this->Minimum
493+ ( new Regex ( @"(?<scope>{/\*~variable~(?<variable>[^~\n]+)~\*/)(?<separator>.|\n)(?<before>(?<beforeExpression>(?<bracket>{)|(?<-bracket>})|[^{}]|\n)*?)\k<variable>\.(?<field>[_a-zA-Z0-9]+)(?<after>(,|;|}| |\))(?<afterExpression>(?<bracket>{)|(?<-bracket>})|[^{}]|\n)*?})" ) , "${scope}${separator}${before}this->${field}${after}" , 10 ) ,
494+ // Remove scope borders.
495+ // /*~ex~*/
496+ //
497+ ( new Regex ( @"/\*~[^~\n]+~[^~\n]+~\*/" ) , "" , 0 ) ,
482498 } . Cast < ISubstitutionRule > ( ) . ToList ( ) ;
483499
484500 public static readonly IList < ISubstitutionRule > LastStage = new List < SubstitutionRule >
0 commit comments