diff options
author | Araq <rumpf_a@web.de> | 2012-02-24 19:20:34 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-02-24 19:20:34 +0100 |
commit | d72b00cf15402b050f4a1ca7e5e73a5968550d0c (patch) | |
tree | bda5e87d6d9b22eb824d4201fc6b944ca44815a2 /lib/core/macros.nim | |
parent | 8273ebcc289ab079b1e35ea6cac803c6f40efb27 (diff) | |
parent | a3f16968a75e3a9b254b6fac7820fea83debd1e8 (diff) | |
download | Nim-d72b00cf15402b050f4a1ca7e5e73a5968550d0c.tar.gz |
Merge branch 'master' of github.com:Araq/Nimrod
Diffstat (limited to 'lib/core/macros.nim')
-rwxr-xr-x | lib/core/macros.nim | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 4d13a076d..e8a16865e 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -208,7 +208,18 @@ proc getAst*(macroOrTemplate: expr): expr {.magic: "ExpandToAst".} ## ## macro FooMacro() = ## var ast = getAst(BarTemplate()) - + +template emit*(s: expr): stmt = + ## accepts a single sting argument and treats it as nimrod code + ## that should be inserted verbatim in the program + ## Example: + ## + ## emit("echo " & '"' & "hello world".toUpper & '"') + ## + block: + const evaluated = s + eval: result = evaluated.parseStmt + proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} = ## checks that `n` is of kind `k`. If this is not the case, ## compilation aborts with an error message. This is useful for writing |