Created
November 14, 2015 13:52
-
-
Save c0ffeeartc/0701c18bae3bc316410a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
# macro debug(c: varargs[expr]): stmt = | |
# result = newNimNode(nnkStmtList, c) | |
# for i in 0..c.len-1: | |
# # add a call to the statement list that writes the expression; | |
# # `toStrLit` converts an AST to its string representation: | |
# result.add(newCall("write", newIdentNode("stdout"), toStrLit(c[i]))) | |
# # add a call to the statement list that writes ": " | |
# result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": "))) | |
# # add a call to the statement list that writes the expressions value: | |
# result.add(newCall("writeLine", newIdentNode("stdout"), c[i])) | |
# var | |
# a: array[0..10, int] | |
# x = "some string" | |
# a[0] = 42 | |
# a[1] = 45 | |
block A: | |
discard | |
block B: | |
block A: | |
discard | |
# var c =0 | |
# debug(a[0], a[1], x) | |
macro some(str:string; body: stmt): stmt = | |
result = newNimNode(nnkStmtList) | |
dumpTree(body) | |
echo str | |
var counter =0 | |
for i in 0..<body.len: | |
if body[i].kind == nnkBlockStmt: | |
echo toStrLit(body[i]) | |
for j in 0..<body[i].len: | |
if body[i][j].kind == nnkBlockStmt: | |
echo "inner block" | |
inc counter | |
# result.add body[i] | |
echo counter | |
when isMainModule: | |
some("A"): | |
echo "echo 32" | |
block TEST_CASE: | |
echo 1 | |
block TEST_CASE: | |
echo 2 | |
echo 31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment