-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
AST RendererIssues related to the compiler turning AST back into Nim code as a string.Issues related to the compiler turning AST back into Nim code as a string.Parser
Description
bugs
-
do:
renders badly => fix #14850:repr
now correctly rendersdo
#17623 and refs #17292 fixrepr
withdo:
#17449 - bug 2:
(discard)
renders badly => refs #17292 fixrepr
:(discard)
now does't render asdiscard
which gave illegal code #17455 - bug 3: hex numbers render badly, silently giving wrong results, eg 0xFFFFFFFF, see Example 1 below
- bug 4:
nnkAccQuoted
renders badly, see Example 2 below =>repr
: fix rendering of'big
,=destroy
etc #17624 - bug 5:
*a: b
renders badly, which might be due to a parser error, see Example 3
Example 1
when true:
macro deb(a) =
echo a.repr
deb:
let f = () => (discard)
f()
let x = 0xffffffffffffffff
template fn(body: untyped): untyped = true
doAssert(fn do: nonexistant)
template foo(x, y) =
x
y
foo:
discard
do:
discard
Current Output
let f = () =>
discard
f()
let x = 0xFFFFFFFF
template fn(body: untyped): untyped =
true
doAssert(fn:
nonexistant)
template foo(x, y) =
x
y
foo(
discard ):
discard
Expected Output
let f = () =>
(discard)
f()
let x = 0xffffffffffffffff
template fn(body: untyped): untyped =
true
doAssert(fn do: nonexistant)
template foo(x, y) =
x
y
foo:
discard
do:
discard
Example 2
repr doesn't work with nnkAccQuoted
:
import macros
macro deb(a) =
echo a.repr
deb:
proc `=destroy`(a: Foo) = discard
proc `'foo`(a: string): int = discard
prints:
proc `= destroy`(a: Foo) =
discard
proc `' foo`(a: string): int =
discard
the culprit is the spaces inserted here in renderer.nim:
of nkAccQuoted:
put(g, tkAccent, "`")
if n.len > 0: gsub(g, n[0])
for i in 1..<n.len:
put(g, tkSpaces, Space)
gsub(g, n[i])
put(g, tkAccent, "`")
Example 3
- see
*a: b
parsed wrong inrepr
doesn't work with hex literals (and otherrepr
bugs now fixed) #17292 (comment)
(should be moved to a different bug)
Additional Information
- 1.5.1 b8c04bd
- code is under renderer.nim; eg
renderModule
is buggy - affected runnableExamples until fix #13491 #17279 runnableExamples now don't get lost in translation #17282
Metadata
Metadata
Assignees
Labels
AST RendererIssues related to the compiler turning AST back into Nim code as a string.Issues related to the compiler turning AST back into Nim code as a string.Parser