Skip to content

Commit

Permalink
Don't stack single-dotexpr-calls
Browse files Browse the repository at this point in the history
There should be at least two calls for stacking mode to kick in
  • Loading branch information
arnetheduck committed Feb 2, 2024
1 parent 503436b commit b9f59ad
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/phrenderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,19 @@ proc isCustomLit(n: PNode): bool =

result = ident != nil and ident.s.startsWith('\'')

proc isStackedCall(n: PNode, inCall: bool): bool =
# At least two calls to enable "stacking" mode
case n.kind
of nkCall:
if inCall:
true
else:
isStackedCall(n, true)
of nkDotExpr:
isStackedCall(n[0], inCall)
else:
false

proc gsub(g: var TOutput, n: PNode, flags: SubFlags, extra: int) =
if isNil(n):
return
Expand Down Expand Up @@ -1591,26 +1604,27 @@ proc gsub(g: var TOutput, n: PNode, flags: SubFlags, extra: int) =
gsub(g, n[1])
else:
let
stackDot = sfStackDot in flags or g.overflows(lsub(g, n[0]) + lsub(g, n[1]) + 1)
stackDot =
sfStackDot in flags or (
g.overflows(lsub(g, n[0]) + lsub(g, n[1]) + 1) and
isStackedCall(n[0], sfStackDotInCall in flags)
)
stackNL = stackDot and sfStackDotInCall in flags
subFlags =
if stackDot:
{sfStackDot}
else:
{}

gsub(
g,
n[0],
if stackDot:
{sfStackDot}
else:
{}
,
)
gsub(g, n[0], flags = subFlags)

# Mids here are put on a new line, then the dot follows on yet another new
# line as dot parsing continues after a comment on a new line too! see
# clMid pickup point in phparser.dotExpr
if n.mid.len > 0:
optNL(g)
gmids(g, n)
if stackNL:
elif stackNL:
optNL(g)
put(g, tkDot, ".")
accentedName(g, n[1])
Expand Down

0 comments on commit b9f59ad

Please sign in to comment.