nimpretty: fixes #9506

This commit is contained in:
Andreas Rumpf
2018-10-26 01:53:10 +02:00
parent 0c3e6735ac
commit 03005fde99
4 changed files with 19 additions and 4 deletions

View File

@@ -111,15 +111,16 @@ proc softLinebreak(em: var Emitter, lit: string) =
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
else:
# search backwards for a good split position:
for a in em.altSplitPos:
for a in mitems(em.altSplitPos):
if a > em.fixedUntil:
var spaces = 0
while a+spaces < em.content.len and em.content[a+spaces] == ' ':
inc spaces
if spaces > 0: delete(em.content, a, a+spaces-1)
let ws = "\L" & repeat(' ',em.indentLevel+moreIndent(em))
em.col = em.content.len - a
let ws = "\L" & repeat(' ', em.indentLevel+moreIndent(em))
em.content.insert(ws, a)
a = -1
break
proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
@@ -256,8 +257,8 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
if not isUnary(tok):
wr(" ")
rememberSplit(splitBinary)
wr(" ")
of tkAccent:
if not em.inquote and endsInAlpha(em): wr(" ")
wr(TokTypeToStr[tok.tokType])

View File

@@ -17,7 +17,9 @@ else:
proc test(infile, ext: string) =
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
quit("FAILURE")
echo "FAILURE: nimpretty cannot prettify ", infile
failures += 1
return
let nimFile = splitFile(infile).name
let expected = dir / "expected" / nimFile & ".nim"
let produced = dir / nimFile.changeFileExt(ext)

View File

@@ -7,3 +7,10 @@ foo bar
proc fun() =
echo "ok1"
proc fun2(a = "fooo" & "bar" & "bar" & "bar" & "bar" & (
"bar" & "bar" & "bar") & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" &
"bar" & "bar" & "bar"): auto =
discard
fun2()

View File

@@ -7,3 +7,8 @@ foo bar
proc fun() =
echo "ok1"
proc fun2(a = "fooo" & "bar" & "bar" & "bar" & "bar" & ("bar" & "bar" & "bar") & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar" & "bar"): auto =
discard
fun2()