diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-04-03 07:05:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-03 16:05:37 +0200 |
commit | 4a11a04fba99e868c371be09216dc93ae2fe3cd6 (patch) | |
tree | 9959c4c2c01446f924ab8c16e704623c37fefa81 /compiler | |
parent | fe7a76f62fa1563a76e1dcce18e3ee98bcd5d36a (diff) | |
download | Nim-4a11a04fba99e868c371be09216dc93ae2fe3cd6.tar.gz |
fix #14850: `repr` now correctly renders `do` (#17623)
* fix #14850: `repr` now correctly renders `do` * add tests * fix test
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/renderer.nim | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 1ca5a41e3..9a867b0a1 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -569,11 +569,11 @@ proc initContext(c: var TContext) = c.spacing = 0 c.flags = {} -proc gsub(g: var TSrcGen, n: PNode, c: TContext) -proc gsub(g: var TSrcGen, n: PNode) = +proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) +proc gsub(g: var TSrcGen, n: PNode, fromStmtList = false) = var c: TContext initContext(c) - gsub(g, n, c) + gsub(g, n, c, fromStmtList = fromStmtList) proc hasCom(n: PNode): bool = result = false @@ -681,7 +681,7 @@ proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) = if n[i].kind in {nkStmtList, nkStmtListExpr, nkStmtListType}: gstmts(g, n[i], c, doIndent=false) else: - gsub(g, n[i]) + gsub(g, n[i], fromStmtList = true) gcoms(g) if doIndent: dedent(g) else: @@ -1003,7 +1003,7 @@ proc isCustomLit(n: PNode): bool = (n[1].kind == nkIdent and n[1].ident.s.startsWith('\'')) or (n[1].kind == nkSym and n[1].sym.name.s.startsWith('\'')) -proc gsub(g: var TSrcGen, n: PNode, c: TContext) = +proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = if isNil(n): return var a: TContext @@ -1040,9 +1040,15 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkParLe, "(") gcomma(g, n, 1, i - 1 - n.len) put(g, tkParRi, ")") - put(g, tkColon, ":") + if fromStmtList: + put(g, tkColon, ":") + else: + put(g, tkSpaces, Space) + put(g, tkDo, "do") + put(g, tkColon, ":") gsub(g, n, i) - for j in i+1 ..< n.len: + i.inc + for j in i ..< n.len: optNL(g) put(g, tkDo, "do") put(g, tkColon, ":") |