* fix #14850: `repr` now correctly renders `do` * add tests * fix test
This commit is contained in:
parent
fe7a76f62f
commit
4a11a04fba
3 changed files with 64 additions and 9 deletions
|
|
@ -569,11 +569,11 @@ proc initContext(c: var TContext) =
|
||||||
c.spacing = 0
|
c.spacing = 0
|
||||||
c.flags = {}
|
c.flags = {}
|
||||||
|
|
||||||
proc gsub(g: var TSrcGen, n: PNode, c: TContext)
|
proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false)
|
||||||
proc gsub(g: var TSrcGen, n: PNode) =
|
proc gsub(g: var TSrcGen, n: PNode, fromStmtList = false) =
|
||||||
var c: TContext
|
var c: TContext
|
||||||
initContext(c)
|
initContext(c)
|
||||||
gsub(g, n, c)
|
gsub(g, n, c, fromStmtList = fromStmtList)
|
||||||
|
|
||||||
proc hasCom(n: PNode): bool =
|
proc hasCom(n: PNode): bool =
|
||||||
result = false
|
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}:
|
if n[i].kind in {nkStmtList, nkStmtListExpr, nkStmtListType}:
|
||||||
gstmts(g, n[i], c, doIndent=false)
|
gstmts(g, n[i], c, doIndent=false)
|
||||||
else:
|
else:
|
||||||
gsub(g, n[i])
|
gsub(g, n[i], fromStmtList = true)
|
||||||
gcoms(g)
|
gcoms(g)
|
||||||
if doIndent: dedent(g)
|
if doIndent: dedent(g)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1003,7 +1003,7 @@ proc isCustomLit(n: PNode): bool =
|
||||||
(n[1].kind == nkIdent and n[1].ident.s.startsWith('\'')) or
|
(n[1].kind == nkIdent and n[1].ident.s.startsWith('\'')) or
|
||||||
(n[1].kind == nkSym and n[1].sym.name.s.startsWith('\''))
|
(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
|
if isNil(n): return
|
||||||
var
|
var
|
||||||
a: TContext
|
a: TContext
|
||||||
|
|
@ -1040,9 +1040,15 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gcomma(g, n, 1, i - 1 - n.len)
|
gcomma(g, n, 1, i - 1 - n.len)
|
||||||
put(g, tkParRi, ")")
|
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)
|
gsub(g, n, i)
|
||||||
for j in i+1 ..< n.len:
|
i.inc
|
||||||
|
for j in i ..< n.len:
|
||||||
optNL(g)
|
optNL(g)
|
||||||
put(g, tkDo, "do")
|
put(g, tkDo, "do")
|
||||||
put(g, tkColon, ":")
|
put(g, tkColon, ":")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "in expression ':"
|
errormsg: "in expression ' do:"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
Error: in expression ':
|
Error: in expression ' do:
|
||||||
890': identifier expected, but found ''
|
890': identifier expected, but found ''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,5 +163,54 @@ proc `foo bar baz`(): int =
|
||||||
"""
|
"""
|
||||||
doAssert a2 == a
|
doAssert a2 == a
|
||||||
|
|
||||||
|
block: # bug #14850
|
||||||
|
block:
|
||||||
|
let a = deb:
|
||||||
|
template bar(): untyped =
|
||||||
|
foo1:
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
foo2(1):
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
foo3(1):
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
do: 1
|
||||||
|
do: 2
|
||||||
|
x.add foo4
|
||||||
|
x.add: foo5: 3
|
||||||
|
x.add foo6 do: 4
|
||||||
|
a.add(foo7 do:
|
||||||
|
echo "baz"
|
||||||
|
4)
|
||||||
|
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
template bar(): untyped =
|
||||||
|
foo1:
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
foo2(1):
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
foo3(1):
|
||||||
|
discard
|
||||||
|
4
|
||||||
|
do:
|
||||||
|
1
|
||||||
|
do:
|
||||||
|
2
|
||||||
|
x.add foo4
|
||||||
|
x.add:
|
||||||
|
foo5:
|
||||||
|
3
|
||||||
|
x.add foo6 do:
|
||||||
|
4
|
||||||
|
a.add(foo7 do:
|
||||||
|
echo "baz"
|
||||||
|
4)
|
||||||
|
"""
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue