Skip to content

Commit 6ab2ffb

Browse files
konardclaude
andcommitted
Fix operator spacing to use sweet style instead of drunkard style
Removes spaces around equality and inequality operators (==, !=) in regex patterns to follow the "sweet style" format: - Before: operator ==(...) - After: operator==(...) Fixed patterns in both C# and Python implementations: - CSharpToCppTransformer.cs: Fixed 3 regex patterns - cs2cpp.py: Fixed 3 regex patterns Resolves issue #59 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ff86ad1 commit 6ab2ffb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public class CSharpToCppTransformer : TextTransformer
6666
(new Regex(@"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?<first>[^,)\n]+),\s*(?<second>[^\)\n]+)\s*\)\s*(?<comparison>[<>=]=?)\s*0(?<after>\D)"), "${first} ${comparison} ${second}${after}", 0),
6767
// public static bool operator ==(Range<T> left, Range<T> right) => left.Equals(right);
6868
//
69-
(new Regex(@"\r?\n[^\n]+bool operator ==\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => (\k<left>|\k<right>)\.Equals\((\k<left>|\k<right>)\);"), "", 10),
69+
(new Regex(@"\r?\n[^\n]+bool operator==\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => (\k<left>|\k<right>)\.Equals\((\k<left>|\k<right>)\);"), "", 10),
7070
// public static bool operator !=(Range<T> left, Range<T> right) => !(left == right);
7171
//
72-
(new Regex(@"\r?\n[^\n]+bool operator !=\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => !\((\k<left>|\k<right>) == (\k<left>|\k<right>)\);"), "", 10),
72+
(new Regex(@"\r?\n[^\n]+bool operator!=\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => !\((\k<left>|\k<right>) == (\k<left>|\k<right>)\);"), "", 10),
7373
// public override bool Equals(object obj) => obj is Range<T> range ? Equals(range) : false;
7474
//
7575
(new Regex(@"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?<this>[a-zA-Z0-9]+)\) => \k<this> is [^\n]+ (?<other>[a-zA-Z0-9]+) \? Equals\(\k<other>\) : false;"), "", 10),
@@ -358,7 +358,7 @@ public class CSharpToCppTransformer : TextTransformer
358358
(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} };", 0),
359359
// bool Equals(Range<T> other) { ... }
360360
// bool operator ==(const Key &other) const { ... }
361-
(new Regex(@"(?<before>\r?\n[^\n]+bool )Equals\((?<type>[^\n{]+) (?<variable>[a-zA-Z0-9]+)\)(?<after>(\s|\n)*{)"), "${before}operator ==(const ${type} &${variable}) const${after}", 0),
361+
(new Regex(@"(?<before>\r?\n[^\n]+bool )Equals\((?<type>[^\n{]+) (?<variable>[a-zA-Z0-9]+)\)(?<after>(\s|\n)*{)"), "${before}operator==(const ${type} &${variable}) const${after}", 0),
362362
// Insert scope borders.
363363
// class Range { ... public: override std::string ToString() { return ...; }
364364
// class Range {/*~Range<T>~*/ ... public: override std::string ToString() { return ...; }

python/cs2cpp/cs2cpp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def __init__(
6565
SubRule(r"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?P<first>[^,)\n]+),\s*(?P<second>[^\)\n]+)\s*\)\s*(?P<comparison>[<>=]=?)\s*0(?P<after>\D)", r"\g<first> \g<comparison> \g<second>\g<after>", max_repeat=0),
6666
# public static bool operator ==(Range<T> left, Range<T> right) => left.Equals(right);
6767
#
68-
SubRule(r"\r?\n[^\n]+bool operator ==\((?P<type>[^\n]+) (?P<left>[a-zA-Z0-9]+), \k<type> (?P<right>[a-zA-Z0-9]+)\) => (\k<left>|\k<right>)\.Equals\((\k<left>|\k<right>)\);", r"", max_repeat=10),
68+
SubRule(r"\r?\n[^\n]+bool operator==\((?P<type>[^\n]+) (?P<left>[a-zA-Z0-9]+), \k<type> (?P<right>[a-zA-Z0-9]+)\) => (\k<left>|\k<right>)\.Equals\((\k<left>|\k<right>)\);", r"", max_repeat=10),
6969
# public static bool operator !=(Range<T> left, Range<T> right) => !(left == right);
7070
#
71-
SubRule(r"\r?\n[^\n]+bool operator !=\((?P<type>[^\n]+) (?P<left>[a-zA-Z0-9]+), \k<type> (?P<right>[a-zA-Z0-9]+)\) => !\((\k<left>|\k<right>) == (\k<left>|\k<right>)\);", r"", max_repeat=10),
71+
SubRule(r"\r?\n[^\n]+bool operator!=\((?P<type>[^\n]+) (?P<left>[a-zA-Z0-9]+), \k<type> (?P<right>[a-zA-Z0-9]+)\) => !\((\k<left>|\k<right>) == (\k<left>|\k<right>)\);", r"", max_repeat=10),
7272
# public override bool Equals(object obj) => obj is Range<T> range ? Equals(range) : false;
7373
#
7474
SubRule(r"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?P<this>[a-zA-Z0-9]+)\) => \k<this> is [^\n]+ (?P<other>[a-zA-Z0-9]+) \? Equals\(\k<other>\) : false;", r"", max_repeat=10),
@@ -357,7 +357,7 @@ def __init__(
357357
SubRule(r"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];", r"\1\3 \2[\4] = { {0} };", max_repeat=0),
358358
# bool Equals(Range<T> other) { ... }
359359
# bool operator ==(const Key &other) const { ... }
360-
SubRule(r"(?P<before>\r?\n[^\n]+bool )Equals\((?P<type>[^\n{]+) (?P<variable>[a-zA-Z0-9]+)\)(?P<after>(\s|\n)*{)", r"\g<before>operator ==(const \g<type> &\g<variable>) const\g<after>", max_repeat=0),
360+
SubRule(r"(?P<before>\r?\n[^\n]+bool )Equals\((?P<type>[^\n{]+) (?P<variable>[a-zA-Z0-9]+)\)(?P<after>(\s|\n)*{)", r"\g<before>operator==(const \g<type> &\g<variable>) const\g<after>", max_repeat=0),
361361
# Insert scope borders.
362362
# class Range { ... public: override std::string ToString() { return ...; }
363363
# class Range {/*~Range<T>~*/ ... public: override std::string ToString() { return ...; }

0 commit comments

Comments
 (0)