mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-03 10:24:44 +00:00
nimpretty: improved detection of commas and semicolons (#11661)
* nimpretty: improved detection of commas and semicolons * address the comments
This commit is contained in:
@@ -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
|
||||
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) =
|
||||
if em.endsWith(" ", "*", " "):
|
||||
setLen(em.tokens, em.tokens.len-3)
|
||||
@@ -526,11 +531,13 @@ proc starWasExportMarker*(em: var Emitter) =
|
||||
|
||||
proc commaWasSemicolon*(em: var Emitter) =
|
||||
if em.semicolons == detectSemicolonKind:
|
||||
em.semicolons = if em.endsWith(",", " "): dontTouch else: useSemicolon
|
||||
if em.semicolons == useSemicolon and em.endsWith(",", " "):
|
||||
em.tokens[em.tokens.len-2] = ";"
|
||||
em.semicolons = if em.rfind(";") > 0: useSemicolon else: dontTouch
|
||||
if em.semicolons == useSemicolon:
|
||||
let commaPos = em.rfind(",")
|
||||
if commaPos > 0:
|
||||
em.tokens[^commaPos] = ";"
|
||||
|
||||
proc curlyRiWasPragma*(em: var Emitter) =
|
||||
if em.endsWith("}"):
|
||||
em.tokens[em.tokens.len-1] = ".}"
|
||||
em.tokens[^1] = ".}"
|
||||
inc em.col
|
||||
|
||||
2
nimpretty/tests/expected/simple4.nim
Normal file
2
nimpretty/tests/expected/simple4.nim
Normal file
@@ -0,0 +1,2 @@
|
||||
proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
discard
|
||||
2
nimpretty/tests/simple4.nim
Normal file
2
nimpretty/tests/simple4.nim
Normal file
@@ -0,0 +1,2 @@
|
||||
proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
|
||||
discard
|
||||
Reference in New Issue
Block a user