* refs #17292 fix `repr` with `do:` * address comment
This commit is contained in:
parent
d78ebe4a0e
commit
f3a6427109
2 changed files with 90 additions and 3 deletions
|
|
@ -1007,12 +1007,19 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
of nkCall, nkConv, nkDotCall, nkPattern, nkObjConstr:
|
of nkCall, nkConv, nkDotCall, nkPattern, nkObjConstr:
|
||||||
if n.len > 1 and n.lastSon.kind in {nkStmtList, nkStmtListExpr}:
|
if n.len > 1 and n.lastSon.kind in {nkStmtList, nkStmtListExpr}:
|
||||||
accentedName(g, n[0])
|
accentedName(g, n[0])
|
||||||
if n.len > 2:
|
var i = 1
|
||||||
|
while i < n.len and n[i].kind notin {nkStmtList, nkStmtListExpr}: i.inc
|
||||||
|
if i > 1:
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gcomma(g, n, 1, -2)
|
gcomma(g, n, 1, i - 1 - n.len)
|
||||||
put(g, tkParRi, ")")
|
put(g, tkParRi, ")")
|
||||||
put(g, tkColon, ":")
|
put(g, tkColon, ":")
|
||||||
gsub(g, n, n.len-1)
|
gsub(g, n, i)
|
||||||
|
for j in i+1 ..< n.len:
|
||||||
|
optNL(g)
|
||||||
|
put(g, tkDo, "do")
|
||||||
|
put(g, tkColon, ":")
|
||||||
|
gsub(g, n, j)
|
||||||
elif n.len >= 1:
|
elif n.len >= 1:
|
||||||
case bracketKind(g, n[0])
|
case bracketKind(g, n[0])
|
||||||
of bkBracket:
|
of bkBracket:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ discard """
|
||||||
# if excessive, could remove 'cpp' from targets
|
# if excessive, could remove 'cpp' from targets
|
||||||
|
|
||||||
from strutils import endsWith, contains
|
from strutils import endsWith, contains
|
||||||
|
from std/macros import newLit
|
||||||
|
macro deb(a): string = newLit a.repr
|
||||||
|
|
||||||
template main() =
|
template main() =
|
||||||
doAssert repr({3,5}) == "{3, 5}"
|
doAssert repr({3,5}) == "{3, 5}"
|
||||||
|
|
@ -65,5 +67,83 @@ template main() =
|
||||||
else:
|
else:
|
||||||
doAssert reprOpenarray(arr) == "[1, 2, 3]"
|
doAssert reprOpenarray(arr) == "[1, 2, 3]"
|
||||||
|
|
||||||
|
block: # bug #17292
|
||||||
|
template foo(a, b, c, d) = discard
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo(1, 2, 3, 4)
|
||||||
|
doAssert a == "\nfoo(1, 2, 3, 4)"
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo(1, 2, 3): 4
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
foo(1, 2, 3):
|
||||||
|
4"""
|
||||||
|
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo(1, 2): 3
|
||||||
|
do: 4
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
foo(1, 2):
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
4"""
|
||||||
|
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo(1): 3
|
||||||
|
do: 3
|
||||||
|
do: 4
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
foo(1):
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
4"""
|
||||||
|
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo(1):
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
discard
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
foo(1):
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
discard
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
discard
|
||||||
|
4"""
|
||||||
|
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
foo: 1
|
||||||
|
do: 2
|
||||||
|
do: 3
|
||||||
|
do: 4
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
foo:
|
||||||
|
1
|
||||||
|
do:
|
||||||
|
2
|
||||||
|
do:
|
||||||
|
3
|
||||||
|
do:
|
||||||
|
4"""
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue