nimpretty: fixes #9505 [bugfix]
This commit is contained in:
parent
790bc5b07b
commit
667af87e66
3 changed files with 57 additions and 1 deletions
|
|
@ -113,6 +113,10 @@ const
|
|||
openPars = {tkParLe, tkParDotLe,
|
||||
tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
|
||||
tkCurlyLe}
|
||||
closedPars = {tkParRi, tkParDotRi,
|
||||
tkBracketRi, tkCurlyDotRi,
|
||||
tkCurlyRi}
|
||||
|
||||
splitters = openPars + {tkComma, tkSemicolon}
|
||||
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
||||
tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
|
||||
|
|
@ -196,8 +200,12 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
|||
em.fixedUntil = em.content.high
|
||||
|
||||
elif tok.indent >= 0:
|
||||
if em.lastTok in (splitters + oprSet) or em.keepIndents > 0:
|
||||
if em.keepIndents > 0:
|
||||
em.indentLevel = tok.indent
|
||||
elif (em.lastTok in (splitters + oprSet) and tok.tokType notin closedPars):
|
||||
# aka: we are in an expression context:
|
||||
let alignment = tok.indent - em.indentStack[^1]
|
||||
em.indentLevel = alignment + em.indentStack.high * em.indWidth
|
||||
else:
|
||||
if tok.indent > em.indentStack[^1]:
|
||||
em.indentStack.add tok.indent
|
||||
|
|
|
|||
24
nimpretty/tests/expected/wrong_ind.nim
Normal file
24
nimpretty/tests/expected/wrong_ind.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
# bug #9505
|
||||
|
||||
import std/[
|
||||
strutils, ospaths, os
|
||||
]
|
||||
import pkg/[
|
||||
regex
|
||||
]
|
||||
|
||||
proc fun() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
]
|
||||
discard
|
||||
|
||||
proc funB() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
discard
|
||||
24
nimpretty/tests/wrong_ind.nim
Normal file
24
nimpretty/tests/wrong_ind.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
# bug #9505
|
||||
|
||||
import std/[
|
||||
strutils, ospaths, os
|
||||
]
|
||||
import pkg/[
|
||||
regex
|
||||
]
|
||||
|
||||
proc fun() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
]
|
||||
discard
|
||||
|
||||
proc funB() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
discard
|
||||
Loading…
Add table
Add a link
Reference in a new issue