twhen_macro.nim 477 B

123456789101112131415161718192021222324
  1. import macros
  2. discard """
  3. output: '''
  4. when - test
  5. '''
  6. """
  7. # test that when stmt works from within a macro
  8. macro output(s: string, xs: varargs[untyped]): auto =
  9. result = quote do:
  10. when compiles(`s`):
  11. "when - " & `s`
  12. elif compiles(`s`):
  13. "elif - " & `s`
  14. # should never get here so this should not break
  15. broken.xs
  16. else:
  17. "else - " & `s`
  18. # should never get here so this should not break
  19. more.broken.xs
  20. echo output("test")