diff options
author | Araq <rumpf_a@web.de> | 2014-01-17 08:47:51 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-01-17 08:47:51 +0100 |
commit | 383fbca27ef4f4e0b5eae0e0e02029fe644248ac (patch) | |
tree | 5ac65389061921d1b6122b8cbf83cec411ff617d /tests/macros/tmacrostmt.nim | |
parent | 12247b3f56a74836af874d707bf63452c11dcf92 (diff) | |
download | Nim-383fbca27ef4f4e0b5eae0e0e02029fe644248ac.tar.gz |
better tester
Diffstat (limited to 'tests/macros/tmacrostmt.nim')
-rw-r--r-- | tests/macros/tmacrostmt.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/macros/tmacrostmt.nim b/tests/macros/tmacrostmt.nim new file mode 100644 index 000000000..d9c70197d --- /dev/null +++ b/tests/macros/tmacrostmt.nim @@ -0,0 +1,26 @@ +import macros +macro case_token(n: stmt): stmt {.immediate.} = + # creates a lexical analyzer from regular expressions + # ... (implementation is an exercise for the reader :-) + nil + +case_token: # this colon tells the parser it is a macro statement +of r"[A-Za-z_]+[A-Za-z_0-9]*": + return tkIdentifier +of r"0-9+": + return tkInteger +of r"[\+\-\*\?]+": + return tkOperator +else: + return tkUnknown + +case_token: inc i + +#bug #488 + +macro foo: stmt = + var exp = newCall("whatwhat", newIntLitNode(1)) + if compiles(getAst(exp)): return exp + else: echo "Does not compute!" + +foo() |