repr: fix rendering of 'big, =destroy etc (#17624)
This commit is contained in:
parent
61c1e35181
commit
fe7a76f62f
2 changed files with 37 additions and 3 deletions
|
|
@ -51,6 +51,8 @@ type
|
||||||
config*: ConfigRef
|
config*: ConfigRef
|
||||||
mangler: seq[PSym]
|
mangler: seq[PSym]
|
||||||
|
|
||||||
|
proc renderTree*(n: PNode, renderFlags: TRenderFlags = {}): string
|
||||||
|
|
||||||
# We render the source code in a two phases: The first
|
# We render the source code in a two phases: The first
|
||||||
# determines how long the subtree will likely be, the second
|
# determines how long the subtree will likely be, the second
|
||||||
# phase appends to a buffer that will be the output.
|
# phase appends to a buffer that will be the output.
|
||||||
|
|
@ -1314,9 +1316,23 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
put(g, tkOpr, "[]")
|
put(g, tkOpr, "[]")
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
put(g, tkAccent, "`")
|
put(g, tkAccent, "`")
|
||||||
if n.len > 0: gsub(g, n[0])
|
for i in 0..<n.len:
|
||||||
for i in 1..<n.len:
|
proc getStrVal(n: PNode): string =
|
||||||
put(g, tkSpaces, Space)
|
# pending https://github.com/nim-lang/Nim/pull/17540, use `getStrVal`
|
||||||
|
case n.kind
|
||||||
|
of nkIdent: n.ident.s
|
||||||
|
of nkSym: n.sym.name.s
|
||||||
|
else: ""
|
||||||
|
var useSpace = false
|
||||||
|
if i == 1 and n[0].kind == nkIdent and n[0].ident.s in ["=", "'"]:
|
||||||
|
let tmp = n[1].getStrVal
|
||||||
|
if tmp.len > 0 and tmp[0] in {'a'..'z', 'A'..'Z'}:
|
||||||
|
# handle `=destroy`, `'big'
|
||||||
|
discard
|
||||||
|
else:
|
||||||
|
useSpace = true
|
||||||
|
elif i > 0: useSpace = true
|
||||||
|
if useSpace: put(g, tkSpaces, Space)
|
||||||
gsub(g, n[i])
|
gsub(g, n[i])
|
||||||
put(g, tkAccent, "`")
|
put(g, tkAccent, "`")
|
||||||
of nkIfExpr:
|
of nkIfExpr:
|
||||||
|
|
|
||||||
|
|
@ -145,5 +145,23 @@ do:
|
||||||
do:
|
do:
|
||||||
4"""
|
4"""
|
||||||
|
|
||||||
|
block: # bug #17292 (bug 4)
|
||||||
|
let a = deb:
|
||||||
|
proc `=destroy`() = discard
|
||||||
|
proc `'foo`(): int = discard
|
||||||
|
proc `foo bar baz`(): int = discard
|
||||||
|
let a2 = """
|
||||||
|
|
||||||
|
proc `=destroy`() =
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc `'foo`(): int =
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc `foo bar baz`(): int =
|
||||||
|
discard
|
||||||
|
"""
|
||||||
|
doAssert a2 == a
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue