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

fix rendering of do inside call inside infix (fixes #69) #79

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/phrenderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,11 @@ proc gsub(g: var TOutput, n: PNode, flags: SubFlags, extra: int) =
if nNext.kind == nkPrefix or (opr != nil and phrenderer.isKeyword(opr)):
optSpace(g)

if nNext.kind == nkInfix:
if nNext.kind == nkInfix or (
# This is a special case for a do statement, which needs an extra set of parens
nNext.kind == nkCall and nNext.len >= 2 and nNext[1].kind == nkStmtList and
nNext[1].len >= 1 and nNext[1][^1].kind == nkCall
):
put(g, tkParLe, "(")
gsub(g, n[1])
put(g, tkParRi, ")")
Expand Down
4 changes: 3 additions & 1 deletion tests/after/a00empty.nim
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

check not (compiles do:
result:
int8 = 6)
27 changes: 27 additions & 0 deletions tests/after/a00empty.nim.nph.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
kind: "nkStmtList"
sons:
- kind: "nkCommand"
sons:
- kind: "nkIdent"
ident: "check"
- kind: "nkPrefix"
sons:
- kind: "nkIdent"
ident: "not"
- kind: "nkCall"
sons:
- kind: "nkIdent"
ident: "compiles"
- kind: "nkStmtList"
sons:
- kind: "nkCall"
sons:
- kind: "nkIdent"
ident: "result"
- kind: "nkStmtList"
sons:
- kind: "nkAsgn"
sons:
- kind: "nkIdent"
ident: "int8"
- kind: "nkIntLit"
intVal: 6
2 changes: 2 additions & 0 deletions tests/before/a00empty.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
check not (compiles do:
result: int8 = 6)
27 changes: 27 additions & 0 deletions tests/before/a00empty.nim.nph.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
kind: "nkStmtList"
sons:
- kind: "nkCommand"
sons:
- kind: "nkIdent"
ident: "check"
- kind: "nkPrefix"
sons:
- kind: "nkIdent"
ident: "not"
- kind: "nkCall"
sons:
- kind: "nkIdent"
ident: "compiles"
- kind: "nkStmtList"
sons:
- kind: "nkCall"
sons:
- kind: "nkIdent"
ident: "result"
- kind: "nkStmtList"
sons:
- kind: "nkAsgn"
sons:
- kind: "nkIdent"
ident: "int8"
- kind: "nkIntLit"
intVal: 6
Loading