summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/layouter.nim15
-rw-r--r--nimpretty/tests/expected/simple4.nim2
-rw-r--r--nimpretty/tests/simple4.nim2
3 files changed, 15 insertions, 4 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index b54fb93bf..a6891f564 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -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
diff --git a/nimpretty/tests/expected/simple4.nim b/nimpretty/tests/expected/simple4.nim
new file mode 100644
index 000000000..62d106a9b
--- /dev/null
+++ b/nimpretty/tests/expected/simple4.nim
@@ -0,0 +1,2 @@
+proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
+  discard
diff --git a/nimpretty/tests/simple4.nim b/nimpretty/tests/simple4.nim
new file mode 100644
index 000000000..62d106a9b
--- /dev/null
+++ b/nimpretty/tests/simple4.nim
@@ -0,0 +1,2 @@
+proc readBuffer*(f: AsyncFile, buf: pointer, size: int): Future[int] =
+  discard