Skip to content

Commit

Permalink
fix rendering of do inside call inside infix (fixes #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jul 19, 2024
1 parent 187dfd4 commit ddf378d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
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

0 comments on commit ddf378d

Please sign in to comment.