8
8
let s1 = " not captured!"
9
9
let xignoredLocal = kfoo4
10
10
let x3 = newLit kfoo4
11
- result = genAst ({kNoExposeLocalInjects}, s1= 2 , s2= " asdf" , x0= newLit x0, x1= x1, x2, x3) do :
11
+ result = genAst ({kNoExposeLocalInjects}, s1= 2 , s2= " asdf" , x0= newLit x0, x1= x1, x2, x3):
12
12
doAssert not declared (xignored)
13
13
doAssert not declared (xignoredLocal)
14
14
(s1, s2, s0, x0, x1, x2, x3)
36
36
37
37
macro m1 (): untyped =
38
38
# result = quote do: # Error: undeclared identifier: 'a1'
39
- result = genAst ({}) do :
39
+ result = genAst ({}):
40
40
template `a1=` (x: var Foo , val: int ) =
41
41
x.a = val
42
42
51
51
result = newStmtList ()
52
52
macro foo (c: bool ): untyped =
53
53
var b = false
54
- result = genAst ({}, b = newLit b, c) do :
54
+ result = genAst ({}, b = newLit b, c):
55
55
fun (b, c)
56
56
57
57
foo (true )
@@ -61,15 +61,15 @@ block:
61
61
# since `==` works with genAst, the problem goes away
62
62
macro foo2 (): untyped =
63
63
# result = quote do: # Error: '==' cannot be passed to a procvar
64
- result = genAst ({}) do :
64
+ result = genAst ({}):
65
65
`==` (3 ,4 )
66
66
doAssert not foo2 ()
67
67
68
68
block :
69
69
# fix https://github.com/nim-lang/Nim/issues/7726
70
70
macro foo (): untyped =
71
71
let a = @ [1 , 2 , 3 , 4 , 5 ]
72
- result = genAst ({}, a, b = a.len) do : # shows 2 ways to get a.len
72
+ result = genAst ({}, a, b = a.len): # shows 2 ways to get a.len
73
73
(a.len, b)
74
74
doAssert foo () == (5 , 5 )
75
75
@@ -82,15 +82,15 @@ block:
82
82
let info = args.lineInfoObj
83
83
let fun1 = bindSym " fun1" # optional; we can remove this and also the
84
84
# capture of fun1
85
- result = genAst ({}, info = newLit info, fun1) do :
85
+ result = genAst ({}, info = newLit info, fun1):
86
86
(fun1 (info), fun2 (info.line))
87
87
doAssert bar2 () == (" bar1" , " bar2" )
88
88
89
89
macro bar (args: varargs [untyped ]): untyped =
90
90
let info = args.lineInfoObj
91
91
let fun1 = bindSym " fun1"
92
92
let fun2 = bindSym " fun2"
93
- result = genAst ({kNoExposeLocalInjects}, info = newLit info) do :
93
+ result = genAst ({kNoExposeLocalInjects}, info = newLit info):
94
94
(fun1 (info), fun2 (info.line))
95
95
doAssert bar () == (" bar1" , " bar2" )
96
96
@@ -118,7 +118,7 @@ block:
118
118
119
119
proc funLocal (): auto = kfoo4
120
120
121
- result = genAst ({}, x1= newLit x1, x2, x3, x4 = newLit x4) do :
121
+ result = genAst ({}, x1= newLit x1, x2, x3, x4 = newLit x4):
122
122
# local x1 overrides remote x1
123
123
when false :
124
124
# one advantage of using `kNoExposeLocalInjects` is that these would hold:
@@ -149,7 +149,7 @@ block:
149
149
# fix https://github.com/nim-lang/Nim/issues/8220
150
150
macro foo (): untyped =
151
151
# kNoExposeLocalInjects needed here
152
- result = genAst ({kNoExposeLocalInjects}) do :
152
+ result = genAst ({kNoExposeLocalInjects}):
153
153
let bar = " Hello, World"
154
154
& " Let's interpolate { bar} in the string "
155
155
doAssert foo () == " Let's interpolate Hello, World in the string"
0 commit comments