nimpretty: fixes #11699
This commit is contained in:
parent
5b7273b4f8
commit
7deb49e992
3 changed files with 71 additions and 7 deletions
|
|
@ -153,8 +153,15 @@ proc lenOfNextTokens(em: Emitter; pos: int): int =
|
||||||
if em.kinds[pos+i] in {ltCrucialNewline, ltSplittingNewline, ltOptionalNewline}: break
|
if em.kinds[pos+i] in {ltCrucialNewline, ltSplittingNewline, ltOptionalNewline}: break
|
||||||
inc result, em.tokens[pos+i].len
|
inc result, em.tokens[pos+i].len
|
||||||
|
|
||||||
proc lacksGuidingInd(em: Emitter; pos: int): bool =
|
proc guidingInd(em: Emitter; pos: int): int =
|
||||||
result = true
|
var i = pos - 1
|
||||||
|
while i >= 0 and em.kinds[i] != ltSomeParLe:
|
||||||
|
dec i
|
||||||
|
while i+1 <= em.kinds.high and em.kinds[i] != ltSomeParRi:
|
||||||
|
if em.kinds[i] == ltSplittingNewline and em.kinds[i+1] == ltSpaces:
|
||||||
|
return em.tokens[i+1].len
|
||||||
|
inc i
|
||||||
|
result = -1
|
||||||
|
|
||||||
proc closeEmitter*(em: var Emitter) =
|
proc closeEmitter*(em: var Emitter) =
|
||||||
template defaultCase() =
|
template defaultCase() =
|
||||||
|
|
@ -209,11 +216,13 @@ proc closeEmitter*(em: var Emitter) =
|
||||||
let spaces = em.tokens[i-1].len
|
let spaces = em.tokens[i-1].len
|
||||||
content.setLen(content.len - spaces)
|
content.setLen(content.len - spaces)
|
||||||
content.add "\L"
|
content.add "\L"
|
||||||
content.add em.tokens[i]
|
let guide = if openPars > 0: guidingInd(em, i) else: -1
|
||||||
lineLen = em.tokens[i].len
|
if guide >= 0:
|
||||||
if false: # openPars == 0 or lacksGuidingInd(em, i):
|
content.add repeat(' ', guide)
|
||||||
content.add repeat(' ', em.indWidth*2)
|
lineLen = guide
|
||||||
lineLen += em.indWidth*2
|
else:
|
||||||
|
content.add em.tokens[i]
|
||||||
|
lineLen = em.tokens[i].len
|
||||||
lineBegin = i+1
|
lineBegin = i+1
|
||||||
if i+1 < em.kinds.len and em.kinds[i+1] == ltSpaces:
|
if i+1 < em.kinds.len and em.kinds[i+1] == ltSpaces:
|
||||||
# inhibit extra spaces at the start of a new line
|
# inhibit extra spaces at the start of a new line
|
||||||
|
|
|
||||||
|
|
@ -761,3 +761,28 @@ var rows2 = await pool.rows(sql"""
|
||||||
"BBBB"
|
"BBBB"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# bug #11699
|
||||||
|
|
||||||
|
const keywords = @[
|
||||||
|
"foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
let keywords1 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5", "bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
let keywords2 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5", "bar5", "foo6", "bar6", "foo7",
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5", "bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
if true:
|
||||||
|
let keywords3 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5", "bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -769,3 +769,33 @@ var rows2 = await pool.rows(sql"""
|
||||||
"BBBB"
|
"BBBB"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# bug #11699
|
||||||
|
|
||||||
|
const keywords = @[
|
||||||
|
"foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo",
|
||||||
|
"bar", "foo", "bar",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
let keywords1 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5",
|
||||||
|
"bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
let keywords2 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5",
|
||||||
|
"bar5", "foo6", "bar6", "foo7",
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5",
|
||||||
|
"bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
||||||
|
if true:
|
||||||
|
let keywords3 = @[
|
||||||
|
"foo1", "bar1", "foo2", "bar2", "foo3", "bar3", "foo4", "bar4", "foo5",
|
||||||
|
"bar5", "foo6", "bar6", "foo7",
|
||||||
|
"zzz", "ggg", "ddd",
|
||||||
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue