nimpretty: improved detection of commas and semicolons (#11661)

* nimpretty: improved detection of commas and semicolons

* address the comments
This commit is contained in:
Miran 2019-07-06 00:21:21 +02:00 • committed by Andreas Rumpf
commit 34c09a98c7
3 changed files with 15 additions and 4 deletions

View file

@ -516,6 +516,11 @@ proc endsWith(em: Emitter; k: varargs[string]): bool =
if em.tokens[em.tokens.len - k.len + i] != k[i]: return false if em.tokens[em.tokens.len - k.len + i] != k[i]: return false
return true return true
proc rfind(em: Emitter, t: string): int =
for i in 1 .. 5:
if em.tokens[^i] == t:
return i
proc starWasExportMarker*(em: var Emitter) = proc starWasExportMarker*(em: var Emitter) =
if em.endsWith(" ", "*", " "): if em.endsWith(" ", "*", " "):
setLen(em.tokens, em.tokens.len-3) setLen(em.tokens, em.tokens.len-3)
@ -526,11 +531,13 @@ proc starWasExportMarker*(em: var Emitter) =
proc commaWasSemicolon*(em: var Emitter) = proc commaWasSemicolon*(em: var Emitter) =
if em.semicolons == detectSemicolonKind: if em.semicolons == detectSemicolonKind:
em.semicolons = if em.endsWith(",", " "): dontTouch else: useSemicolon em.semicolons = if em.rfind(";") > 0: useSemicolon else: dontTouch
if em.semicolons == useSemicolon and em.endsWith(",", " "): if em.semicolons == useSemicolon:
em.tokens[em.tokens.len-2] = ";" let commaPos = em.rfind(",")
if commaPos > 0:
em.tokens[^commaPos] = ";"
proc curlyRiWasPragma*(em: var Emitter) = proc curlyRiWasPragma*(em: var Emitter) =
if em.endsWith("}"): if em.endsWith("}"):
em.tokens[em.tokens.len-1] = ".}" em.tokens[^1] = ".}"
inc em.col inc em.col

View file

@ -0,0 +1,2 @@
proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
discard

View file

@ -0,0 +1,2 @@
proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
discard