Workaround regex replace issue

This commit is contained in:
Joey Yakimowich-Payne 2018-07-13 08:17:10 +09:00
commit 59c64782bd

View file

@ -76,14 +76,14 @@ proc removeStatic*(filename: string) =
## out body ## out body
withFile(filename): withFile(filename):
content = content.replace( content = content.replace(
re"(?m)(static inline.*?\))(\s*\{(\s*?.*?$)*[\n\r]\})", re"(?m)(static inline.*?\))(\s*\{(\s*?.*?$)*?[\n\r]\})",
proc (m: RegexMatch, s: string): string = proc (m: RegexMatch, s: string): string =
let funcDecl = s[m.group(0)[0]] let funcDecl = s[m.group(0)[0]]
let body = s[m.group(1)[0]].strip() let body = s[m.group(1)[0]].strip()
result = "" result = ""
result.add("$#;" % [funcDecl]) result.add("$#;" % [funcDecl])
result.add(body.replace(re"(?m)^", "//")) result.add(body.replace(re"(?m)^(.*\n?)", "//$1"))
) )
proc reAddStatic*(filename: string) = proc reAddStatic*(filename: string) =
@ -91,14 +91,14 @@ proc reAddStatic*(filename: string) =
## removeStatic ## removeStatic
withFile(filename): withFile(filename):
content = content.replace( content = content.replace(
re"(?m)(static inline.*?\));(\/\/\s*\{(\s*?.*?$)*[\n\r]\/\/\})", re"(?m)(static inline.*?\));(\/\/\s*\{(\s*?.*?$)*?[\n\r]\/\/\})",
proc (m: RegexMatch, s: string): string = proc (m: RegexMatch, s: string): string =
let funcDecl = s[m.group(0)[0]] let funcDecl = s[m.group(0)[0]]
let body = s[m.group(1)[0]].strip() let body = s[m.group(1)[0]].strip()
result = "" result = ""
result.add("$# " % [funcDecl]) result.add("$# " % [funcDecl])
result.add(body.replace(re"(?m)^\/\/", "")) result.add(body.replace(re"(?m)^\/\/(.*\n?)", "$1"))
) )
proc fixFuncProtos*(file: string) = proc fixFuncProtos*(file: string) =