fixes c2nim regression; do not produce more newlines
This commit is contained in:
parent
4f633dde64
commit
186e7d49d3
1 changed files with 21 additions and 18 deletions
|
|
@ -37,8 +37,8 @@ type
|
||||||
inGenericParams: bool
|
inGenericParams: bool
|
||||||
checkAnon: bool # we're in a context that can contain sfAnon
|
checkAnon: bool # we're in a context that can contain sfAnon
|
||||||
inPragma: int
|
inPragma: int
|
||||||
pendingNewlineCount: int
|
|
||||||
when defined(nimpretty):
|
when defined(nimpretty):
|
||||||
|
pendingNewlineCount: int
|
||||||
origContent: string
|
origContent: string
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ else:
|
||||||
template IndentWidth: untyped = lexer.gIndentationWidth
|
template IndentWidth: untyped = lexer.gIndentationWidth
|
||||||
template longIndentWid: untyped = IndentWidth() * 2
|
template longIndentWid: untyped = IndentWidth() * 2
|
||||||
|
|
||||||
proc minmaxLine(n: PNode): (int, int) =
|
proc minmaxLine(n: PNode): (int, int) =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkTripleStrLit:
|
of nkTripleStrLit:
|
||||||
result = (n.info.line.int, n.info.line.int + countLines(n.strVal))
|
result = (n.info.line.int, n.info.line.int + countLines(n.strVal))
|
||||||
|
|
@ -84,7 +84,7 @@ proc minmaxLine(n: PNode): (int, int) =
|
||||||
if currMin < result[0]: result[0] = currMin
|
if currMin < result[0]: result[0] = currMin
|
||||||
if currMax > result[1]: result[1] = currMax
|
if currMax > result[1]: result[1] = currMax
|
||||||
|
|
||||||
proc lineDiff(a, b: PNode): int =
|
proc lineDiff(a, b: PNode): int =
|
||||||
result = minmaxLine(b)[0] - minmaxLine(a)[1]
|
result = minmaxLine(b)[0] - minmaxLine(a)[1]
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -113,7 +113,10 @@ proc addTok(g: var TSrcGen, kind: TTokType, s: string) =
|
||||||
|
|
||||||
proc addPendingNL(g: var TSrcGen) =
|
proc addPendingNL(g: var TSrcGen) =
|
||||||
if g.pendingNL >= 0:
|
if g.pendingNL >= 0:
|
||||||
|
when defined(nimpretty):
|
||||||
let newlines = repeat("\n", clamp(g.pendingNewlineCount, 1, 3))
|
let newlines = repeat("\n", clamp(g.pendingNewlineCount, 1, 3))
|
||||||
|
else:
|
||||||
|
const newlines = "\n"
|
||||||
addTok(g, tkSpaces, newlines & spaces(g.pendingNL))
|
addTok(g, tkSpaces, newlines & spaces(g.pendingNL))
|
||||||
g.lineLen = g.pendingNL
|
g.lineLen = g.pendingNL
|
||||||
g.pendingNL = - 1
|
g.pendingNL = - 1
|
||||||
|
|
@ -139,7 +142,7 @@ proc putNL(g: var TSrcGen) =
|
||||||
proc optNL(g: var TSrcGen, indent: int) =
|
proc optNL(g: var TSrcGen, indent: int) =
|
||||||
g.pendingNL = indent
|
g.pendingNL = indent
|
||||||
g.lineLen = indent
|
g.lineLen = indent
|
||||||
g.pendingNewlineCount = 0
|
when defined(nimpretty): g.pendingNewlineCount = 0
|
||||||
|
|
||||||
proc optNL(g: var TSrcGen) =
|
proc optNL(g: var TSrcGen) =
|
||||||
optNL(g, g.indent)
|
optNL(g, g.indent)
|
||||||
|
|
@ -147,7 +150,7 @@ proc optNL(g: var TSrcGen) =
|
||||||
proc optNL(g: var TSrcGen; a, b: PNode) =
|
proc optNL(g: var TSrcGen; a, b: PNode) =
|
||||||
g.pendingNL = g.indent
|
g.pendingNL = g.indent
|
||||||
g.lineLen = g.indent
|
g.lineLen = g.indent
|
||||||
g.pendingNewlineCount = lineDiff(a, b)
|
when defined(nimpretty): g.pendingNewlineCount = lineDiff(a, b)
|
||||||
|
|
||||||
proc indentNL(g: var TSrcGen) =
|
proc indentNL(g: var TSrcGen) =
|
||||||
inc(g.indent, IndentWidth)
|
inc(g.indent, IndentWidth)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue