Skip to content

Commit

Permalink
render infix with post-exprs (fixes #73) (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck authored Jul 19, 2024
1 parent 77457f1 commit 187dfd4
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/phrenderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1704,8 +1704,6 @@ proc gsub(g: var TOutput, n: PNode, flags: SubFlags, extra: int) =

gsub(g, n[0], flags = flags) # binary operator

doAssert n.len == 3

# `fitsNL` governs a preference to fit an argument fully on a new line over
# leaving parts of it on the same line as the operator.
# This increases the probability that the line will end with an operator and
Expand Down
6 changes: 6 additions & 0 deletions tests/after/postexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ else:
discard (
aaa.bbb.exec do(res: int64):
size = res).ccc()

macro `->`(a, b, c: untyped) =
discard

1 -> 2 do:
discard
42 changes: 42 additions & 0 deletions tests/after/postexprs.nim.nph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,45 @@ sons:
ident: "res"
- kind: "nkIdent"
ident: "ccc"
- kind: "nkMacroDef"
sons:
- kind: "nkAccQuoted"
sons:
- kind: "nkIdent"
ident: "->"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkFormalParams"
sons:
- kind: "nkEmpty"
- kind: "nkIdentDefs"
sons:
- kind: "nkIdent"
ident: "a"
- kind: "nkIdent"
ident: "b"
- kind: "nkIdent"
ident: "c"
- kind: "nkIdent"
ident: "untyped"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkStmtList"
sons:
- kind: "nkDiscardStmt"
sons:
- kind: "nkEmpty"
- kind: "nkInfix"
sons:
- kind: "nkIdent"
ident: "->"
- kind: "nkIntLit"
intVal: 1
- kind: "nkIntLit"
intVal: 2
- kind: "nkStmtList"
sons:
- kind: "nkDiscardStmt"
sons:
- kind: "nkEmpty"
5 changes: 5 additions & 0 deletions tests/before/postexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ else: discard

discard (aaa.bbb.exec do(res: int64):
size = res).ccc()

macro `->`(a, b, c: untyped) = discard

1 -> 2:
discard
42 changes: 42 additions & 0 deletions tests/before/postexprs.nim.nph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,45 @@ sons:
ident: "res"
- kind: "nkIdent"
ident: "ccc"
- kind: "nkMacroDef"
sons:
- kind: "nkAccQuoted"
sons:
- kind: "nkIdent"
ident: "->"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkFormalParams"
sons:
- kind: "nkEmpty"
- kind: "nkIdentDefs"
sons:
- kind: "nkIdent"
ident: "a"
- kind: "nkIdent"
ident: "b"
- kind: "nkIdent"
ident: "c"
- kind: "nkIdent"
ident: "untyped"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkEmpty"
- kind: "nkStmtList"
sons:
- kind: "nkDiscardStmt"
sons:
- kind: "nkEmpty"
- kind: "nkInfix"
sons:
- kind: "nkIdent"
ident: "->"
- kind: "nkIntLit"
intVal: 1
- kind: "nkIntLit"
intVal: 2
- kind: "nkStmtList"
sons:
- kind: "nkDiscardStmt"
sons:
- kind: "nkEmpty"

0 comments on commit 187dfd4

Please sign in to comment.