blob: 6116f83d53b9e5a55976911b8632a7162ee41eed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import macros
{.experimental: "dotOperators".}
{.experimental: "callOperator".}
block:
template `.()`(foo: int, args: varargs[untyped]): untyped {.used.} =
".()"
template `()`(foo: int, args: varargs[untyped]): untyped =
"()"
let a = (b: 1)
let c = 3
doAssert a.b(c) == "()"
doAssert not compiles(a(c))
doAssert (a.b)(c) == "()"
macro `()`(args: varargs[typed]): untyped =
result = newLit("() " & args.treeRepr)
macro `.`(args: varargs[typed]): untyped =
result = newLit(". " & args.treeRepr)
block:
let a = 1
let b = 2
doAssert a.b == `()`(b, a)
block:
let a = 1
proc b(): int {.used.} = 2
doAssert a.b == `.`(a, b)
block:
let a = 1
proc b(x: int): int = x + 1
let c = 3
doAssert a.b(c) == `.`(a, b, c)
doAssert a(b) == `()`(a, b)
doAssert (a.b)(c) == `()`(a.b, c)
doAssert a.b == b(a)
|