nimpretty: fixes #9506
This commit is contained in:
parent
0c3e6735ac
commit
03005fde99
4 changed files with 19 additions and 4 deletions
|
|
@ -111,15 +111,16 @@ proc softLinebreak(em: var Emitter, lit: string) =
|
||||||
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
|
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
|
||||||
else:
|
else:
|
||||||
# search backwards for a good split position:
|
# search backwards for a good split position:
|
||||||
for a in em.altSplitPos:
|
for a in mitems(em.altSplitPos):
|
||||||
if a > em.fixedUntil:
|
if a > em.fixedUntil:
|
||||||
var spaces = 0
|
var spaces = 0
|
||||||
while a+spaces < em.content.len and em.content[a+spaces] == ' ':
|
while a+spaces < em.content.len and em.content[a+spaces] == ' ':
|
||||||
inc spaces
|
inc spaces
|
||||||
if spaces > 0: delete(em.content, a, a+spaces-1)
|
if spaces > 0: delete(em.content, a, a+spaces-1)
|
||||||
let ws = "\L" & repeat(' ',em.indentLevel+moreIndent(em))
|
|
||||||
em.col = em.content.len - a
|
em.col = em.content.len - a
|
||||||
|
let ws = "\L" & repeat(' ', em.indentLevel+moreIndent(em))
|
||||||
em.content.insert(ws, a)
|
em.content.insert(ws, a)
|
||||||
|
a = -1
|
||||||
break
|
break
|
||||||
|
|
||||||
proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
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
|
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
||||||
|
|
||||||
if not isUnary(tok):
|
if not isUnary(tok):
|
||||||
wr(" ")
|
|
||||||
rememberSplit(splitBinary)
|
rememberSplit(splitBinary)
|
||||||
|
wr(" ")
|
||||||
of tkAccent:
|
of tkAccent:
|
||||||
if not em.inquote and endsInAlpha(em): wr(" ")
|
if not em.inquote and endsInAlpha(em): wr(" ")
|
||||||
wr(TokTypeToStr[tok.tokType])
|
wr(TokTypeToStr[tok.tokType])
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ else:
|
||||||
|
|
||||||
proc test(infile, ext: string) =
|
proc test(infile, ext: string) =
|
||||||
if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
|
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 nimFile = splitFile(infile).name
|
||||||
let expected = dir / "expected" / nimFile & ".nim"
|
let expected = dir / "expected" / nimFile & ".nim"
|
||||||
let produced = dir / nimFile.changeFileExt(ext)
|
let produced = dir / nimFile.changeFileExt(ext)
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,10 @@ foo bar
|
||||||
|
|
||||||
proc fun() =
|
proc fun() =
|
||||||
echo "ok1"
|
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()
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,8 @@ foo bar
|
||||||
|
|
||||||
proc fun() =
|
proc fun() =
|
||||||
echo "ok1"
|
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue