toprprec.nim 575 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. output: "done"
  3. """
  4. # Test operator precedence:
  5. template `@@` (x: untyped): untyped =
  6. `self`.x
  7. template `@!` (x: untyped): untyped = x
  8. template `===` (x: untyped): untyped = x
  9. type
  10. TO = object
  11. x: int
  12. TA = tuple[a, b: int, obj: TO]
  13. proc init(self: var TA): string =
  14. @@a = 3
  15. === @@b = 4
  16. @@obj.x = 4
  17. @! === result = "abc"
  18. result = @@b.`$`
  19. assert 3+5*5-2 == 28- -26-28
  20. proc `^-` (x, y: int): int =
  21. # now right-associative!
  22. result = x - y
  23. assert 34 ^- 6 ^- 2 == 30
  24. assert 34 - 6 - 2 == 26
  25. var s: TA
  26. assert init(s) == "4"
  27. echo "done"