diff options
author | Zahary Karadjov <zahary@gmail.comy> | 2011-09-05 15:56:02 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.comy> | 2011-09-20 14:13:45 +0300 |
commit | d541815e4b61b8378ed79af642cc2e0f3b4e09df (patch) | |
tree | 0bbb99e90fa72efb49d67424550d1ed215134114 /tests/accept/compile | |
parent | daa2c8732d0f4feef20f68e75e9c491e95b95a0d (diff) | |
download | Nim-d541815e4b61b8378ed79af642cc2e0f3b4e09df.tar.gz |
Added AST introspection routines as a part of the standard library
Diffstat (limited to 'tests/accept/compile')
-rwxr-xr-x | tests/accept/compile/tdumpast.nim | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/tests/accept/compile/tdumpast.nim b/tests/accept/compile/tdumpast.nim index fb31af0ec..a56438773 100755 --- a/tests/accept/compile/tdumpast.nim +++ b/tests/accept/compile/tdumpast.nim @@ -1,29 +1,12 @@ # Dump the contents of a PNimrodNode import macros - -proc dumpit(n: PNimrodNode): string {.compileTime.} = - if n == nil: return "nil" - result = $n.kind - add(result, "(") - case n.kind - of nnkEmpty: nil # same as nil node in this representation - of nnkNilLit: add(result, "nil") - of nnkCharLit..nnkInt64Lit: add(result, $n.intVal) - of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) - of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal) - of nnkIdent: add(result, $n.ident) - of nnkSym, nnkNone: assert false - else: - add(result, dumpit(n[0])) - for j in 1..n.len-1: - add(result, ", ") - add(result, dumpit(n[j])) - add(result, ")") macro dumpAST(n: stmt): stmt = # dump AST as a side-effect and return the inner node - echo dumpit(n) + echo n.prettyPrint + echo n.toYaml + result = n[1] dumpAST: |