diff options
author | Zahary Karadjov <zahary@gmail.comy> | 2011-09-07 04:25:18 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.comy> | 2011-09-20 14:13:45 +0300 |
commit | 91351e5996e48ba1e3235a6dbaf37f9102e067b6 (patch) | |
tree | 3dd2eb17cafa2fdafceae0c4e66b0ec738e03ac3 /tests | |
parent | d541815e4b61b8378ed79af642cc2e0f3b4e09df (diff) | |
download | Nim-91351e5996e48ba1e3235a6dbaf37f9102e067b6.tar.gz |
Initial implementation of the parseExpr, parseStmt, getAst macro routines:
proc parseExpr*(s: string) : expr {.magic: "ParseExprToAst".} ## Compiles the passed string to its AST representation ## Expects a single expression proc parseStmt*(s: string) : stmt {.magic: "ParseStmtToAst".} ## Compiles the passed string to its AST representation ## Expects one or more statements proc getAst*(macroOrTemplate: expr): expr {.magic: "ExpandMacroToAst".} ## Obtains the AST nodes returned from a macro or template invocation ## example: ## macro FooMacro() = ## var ast = getAst(BarTemplate()) Handling of the node.toYaml magic moved to the evaluation engine.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/accept/compile/tdumpast.nim | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/accept/compile/tdumpast.nim b/tests/accept/compile/tdumpast.nim index a56438773..8561c6e42 100755 --- a/tests/accept/compile/tdumpast.nim +++ b/tests/accept/compile/tdumpast.nim @@ -1,12 +1,27 @@ # Dump the contents of a PNimrodNode import macros + +template plus(a, b: expr): expr = + a + b + +macro call(e: expr): expr = + return newCall("foo", newStrLitNode("bar")) -macro dumpAST(n: stmt): stmt = +macro dumpAST(n: stmt): stmt = # dump AST as a side-effect and return the inner node echo n.prettyPrint echo n.toYaml + var plusAst = getAst(plus(1, 2)) + echo plusAst.prettyPrint + + var callAst = getAst(call()) + echo callAst.prettyPrint + + var e = parseExpr("foo(bar + baz)") + echo e.prettyPrint + result = n[1] dumpAST: @@ -15,4 +30,3 @@ dumpAST: proc sub(x, y: int): int = return x - y - |