tmacrostmt.nim 582 B

123456789101112131415161718192021222324252627
  1. import macros
  2. macro case_token(n: untyped): untyped {.immediate.} =
  3. # creates a lexical analyzer from regular expressions
  4. # ... (implementation is an exercise for the reader :-)
  5. nil
  6. case_token: # this colon tells the parser it is a macro statement
  7. of r"[A-Za-z_]+[A-Za-z_0-9]*":
  8. return tkIdentifier
  9. of r"0-9+":
  10. return tkInteger
  11. of r"[\+\-\*\?]+":
  12. return tkOperator
  13. else:
  14. return tkUnknown
  15. case_token: inc i
  16. #bug #488
  17. macro foo: typed =
  18. var exp = newCall("whatwhat", newIntLitNode(1))
  19. if compiles(getAst(exp)): return exp
  20. else: echo "Does not compute!"
  21. foo()