nimpretty: fixes #8626

(cherry picked from commit ed38079b9b)
This commit is contained in:
Andreas Rumpf
2018-10-16 15:33:21 +02:00
committed by narimiran
parent 3340e46310
commit 754e11de3e
5 changed files with 22 additions and 3 deletions

View File

@@ -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]:

View File

@@ -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)):

View File

@@ -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"

View File

@@ -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

View File

@@ -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