summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-10-16 15:33:21 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-10-16 16:55:04 +0200
commited38079b9ba56ae494995e0eb594b824b45d5ad9 (patch)
tree47df13cc31c4be52435bfa649f00fc4c2ad706ff
parent72cd3b7914ba3390ba1f87683151c84a85dfbb85 (diff)
downloadNim-ed38079b9ba56ae494995e0eb594b824b45d5ad9.tar.gz
nimpretty: fixes #8626
-rw-r--r--compiler/layouter.nim4
-rw-r--r--compiler/parser.nim2
-rw-r--r--nimpretty/tester.nim9
-rw-r--r--nimpretty/tests/exhaustive.nim5
-rw-r--r--nimpretty/tests/expected/exhaustive.nim5
5 files changed, 22 insertions, 3 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index cc6ec48b7..d03105eb2 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -31,7 +31,7 @@ type
     inquote: bool
     semicolons: SemicolonKind
     col, lastLineNumber, lineSpan, indentLevel, indWidth: int
-    nested: int
+    inParamList*: int
     doIndentMore*: int
     content: string
     indentStack: seq[int]
@@ -142,7 +142,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
     em.fixedUntil = em.content.high
 
   elif tok.indent >= 0:
-    if em.lastTok in (splitters + oprSet):
+    if em.lastTok in (splitters + oprSet) or em.inParamList > 0:
       em.indentLevel = tok.indent
     else:
       if tok.indent > em.indentStack[^1]:
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 54aaf8194..cf64ad555 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -1037,6 +1037,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode =
   addSon(result, p.emptyNode) # return type
   when defined(nimpretty2):
     inc p.em.doIndentMore
+    inc p.em.inParamList
   let hasParLe = p.tok.tokType == tkParLe and p.tok.indent < 0
   if hasParLe:
     getTok(p)
@@ -1073,6 +1074,7 @@ proc parseParamList(p: var TParser, retColon = true): PNode =
     result = p.emptyNode
   when defined(nimpretty2):
     dec p.em.doIndentMore
+    dec p.em.inParamList
 
 proc optPragmas(p: var TParser): PNode =
   if p.tok.tokType == tkCurlyDotLe and (p.tok.indent < 0 or realInd(p)):
diff --git a/nimpretty/tester.nim b/nimpretty/tester.nim
index 8798ce06a..2f184b7fc 100644
--- a/nimpretty/tester.nim
+++ b/nimpretty/tester.nim
@@ -8,8 +8,15 @@ const
 var
   failures = 0
 
+when defined(develop):
+  const nimp = "bin/nimpretty".addFileExt(ExeExt)
+  if execShellCmd("nim c -o:$# nimpretty/nimpretty.nim" % [nimp]) != 0:
+    quit("FAILURE: compilation of nimpretty failed")
+else:
+  const nimp = "nimpretty"
+
 proc test(infile, outfile: string) =
-  if execShellCmd("nimpretty -o:$2 --backup:off $1" % [infile, outfile]) != 0:
+  if execShellCmd("$# -o:$# --backup:off $#" % [nimp, outfile, infile]) != 0:
     quit("FAILURE")
   let nimFile = splitFile(infile).name
   let expected = dir / "expected" / nimFile & ".nim"
diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim
index 1b8007844..cfb42e7a9 100644
--- a/nimpretty/tests/exhaustive.nim
+++ b/nimpretty/tests/exhaustive.nim
@@ -316,3 +316,8 @@ proc f() =
     str &= c
 
 const test = r"C:\Users\-\Desktop\test.txt"
+
+proc getKeyAndData(cursor: int, op: int):
+    tuple[key, data: string, success: bool] {.noInit.} =
+  var keyVal: string
+  var dataVal: string
diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim
index bace61945..b9cb2e053 100644
--- a/nimpretty/tests/expected/exhaustive.nim
+++ b/nimpretty/tests/expected/exhaustive.nim
@@ -325,3 +325,8 @@ proc f() =
     str &= c
 
 const test = r"C:\Users\-\Desktop\test.txt"
+
+proc getKeyAndData(cursor: int; op: int):
+    tuple[key, data: string; success: bool] {.noInit.} =
+  var keyVal: string
+  var dataVal: string