Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't stack single-dotexpr-calls #35

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading