blob: 1acd381e7fb5c5b5473f08259f4cf1bc99bdb247 (
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
|
discard """
file: "toprprec.nim"
output: "done"
"""
# Test operator precedence:
template `@` (x: untyped): untyped {.immediate.} =
`self`.x
template `@!` (x: untyped): untyped = x
template `===` (x: untyped): untyped = x
type
TO = object
x: int
TA = tuple[a, b: int, obj: TO]
proc init(self: var TA): string =
@a = 3
=== @b = 4
@obj.x = 4
@! === result = "abc"
result = @b.`$`
assert 3+5*5-2 == 28- -26-28
proc `^-` (x, y: int): int =
# now right-associative!
result = x - y
assert 34 ^- 6 ^- 2 == 30
assert 34 - 6 - 2 == 26
var s: TA
assert init(s) == "4"
echo "done"
|