summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-01-20 20:07:44 +0100
committerAraq <rumpf_a@web.de>2014-01-20 20:07:44 +0100
commit4a0aadef4d1eef2920bd84cbc532b607741a239a (patch)
tree0202cba6e947e3afb66d4093de0c71214d625c0c /lib/core
parentd18f40b4e2ea594d10c654616b95b038f808b8ed (diff)
downloadNim-4a0aadef4d1eef2920bd84cbc532b607741a239a.tar.gz
parser support anon iterators
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/macros.nim18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index 0356067f1..7cb084653 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -300,9 +300,12 @@ when not defined(booting):
     ## that should be inserted verbatim in the program
     ## Example:
     ##
+    ## .. code-block:: nimrod
     ##   emit("echo " & '"' & "hello world".toUpper & '"')
     ##
-    eval: result = e.parseStmt
+    macro payload: stmt {.gensym.} =
+      result = e.parseStmt
+    payload()
 
 proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
   ## checks that `n` is of kind `k`. If this is not the case,
@@ -645,10 +648,13 @@ iterator children*(n: PNimrodNode): PNimrodNode {.inline.}=
   for i in 0 .. high(n):
     yield n[i]
 
-template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {.immediate, dirty.} =
-  ## Find the first child node matching condition (or nil)
-  ## var res = findChild(n, it.kind == nnkPostfix and it.basename.ident == !"foo")
-  
+template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {.
+  immediate, dirty.} =
+  ## Find the first child node matching condition (or nil).
+  ## 
+  ## .. code-block:: nimrod
+  ##   var res = findChild(n, it.kind == nnkPostfix and
+  ##                          it.basename.ident == !"foo")
   block:
     var result: PNimrodNode
     for it in n.children:
@@ -736,6 +742,6 @@ proc addIdentIfAbsent*(dest: PNimrodNode, ident: string) {.compiletime.} =
       if ident.eqIdent($node): return
     of nnkExprColonExpr:
       if ident.eqIdent($node[0]): return
-    else: nil
+    else: discard
   dest.add(ident(ident))