From 939c0a6bb8c21c036bdb7bc44cf866b947b11696 Mon Sep 17 00:00:00 2001 From: transfuturist Date: Fri, 15 May 2015 21:55:06 -0700 Subject: [PATCH 1/6] NimNode needs an items iterator to be used nicely in for statements --- lib/core/macros.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 35f0f61c17..becfd2d940 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -712,6 +712,10 @@ iterator children*(n: NimNode): NimNode {.inline.}= for i in 0 .. high(n): yield n[i] +iterator items*(n: NimNode): NimNode {.inline.}= + for i in 0 .. high(n): + yield n[i] + template findChild*(n: NimNode; cond: expr): NimNode {. immediate, dirty.} = ## Find the first child node matching condition (or nil). From 7500eed0cfb56a1fc4812d57ac301ee9b7f50026 Mon Sep 17 00:00:00 2001 From: transfuturist Date: Sat, 16 May 2015 17:26:47 -0700 Subject: [PATCH 2/6] Better solution: deprecation --- lib/core/macros.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index becfd2d940..48e4566b3d 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -708,14 +708,12 @@ proc `$`*(node: NimNode): string {.compileTime.} = proc ident*(name: string): NimNode {.compileTime,inline.} = newIdentNode(name) ## Create a new ident node from a string -iterator children*(n: NimNode): NimNode {.inline.}= - for i in 0 .. high(n): - yield n[i] - iterator items*(n: NimNode): NimNode {.inline.}= for i in 0 .. high(n): yield n[i] +{.deprecated: [children: items].} + template findChild*(n: NimNode; cond: expr): NimNode {. immediate, dirty.} = ## Find the first child node matching condition (or nil). From 3d80fcb8c6ff1e03922f517681efad65d79563fb Mon Sep 17 00:00:00 2001 From: transfuturist Date: Sat, 16 May 2015 17:50:01 -0700 Subject: [PATCH 3/6] Add value check for NimNode items --- lib/core/macros.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 48e4566b3d..41998250e5 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -708,9 +708,10 @@ proc `$`*(node: NimNode): string {.compileTime.} = proc ident*(name: string): NimNode {.compileTime,inline.} = newIdentNode(name) ## Create a new ident node from a string -iterator items*(n: NimNode): NimNode {.inline.}= - for i in 0 .. high(n): - yield n[i] +iterator items*(n: NimNode): NimNode {.inline.} = + if n[0] != nil: + for i in 0 .. high(n): + yield n[i] {.deprecated: [children: items].} From bc2aaea853d3bd1ad7641bf32335e3725f03afed Mon Sep 17 00:00:00 2001 From: transfuturist Date: Sun, 17 May 2015 15:05:26 -0700 Subject: [PATCH 4/6] Change check for NimNode items to node kind --- lib/core/macros.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 41998250e5..0bfdffc5dc 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -709,7 +709,7 @@ proc ident*(name: string): NimNode {.compileTime,inline.} = newIdentNode(name) ## Create a new ident node from a string iterator items*(n: NimNode): NimNode {.inline.} = - if n[0] != nil: + if n.kind in {nnkType, nnkMetaNode .. nnkReturnToken}: for i in 0 .. high(n): yield n[i] From a31c36e98f7caa330160b55c21d48c06cce03a62 Mon Sep 17 00:00:00 2001 From: transfuturist Date: Sat, 20 Jun 2015 12:21:16 -0700 Subject: [PATCH 5/6] Undeprecate children --- lib/core/macros.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 0bfdffc5dc..3fd2c85020 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -713,7 +713,7 @@ iterator items*(n: NimNode): NimNode {.inline.} = for i in 0 .. high(n): yield n[i] -{.deprecated: [children: items].} +iterator children*(n: NimNode): NimNode {.inline.} = items template findChild*(n: NimNode; cond: expr): NimNode {. immediate, dirty.} = From 558360e6fdf73de27f2bf9631124288c4db4d8fb Mon Sep 17 00:00:00 2001 From: transfuturist Date: Fri, 3 Jul 2015 13:48:13 -0700 Subject: [PATCH 6/6] Update macros.nim --- lib/core/macros.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 3fd2c85020..98165dd17f 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -709,7 +709,7 @@ proc ident*(name: string): NimNode {.compileTime,inline.} = newIdentNode(name) ## Create a new ident node from a string iterator items*(n: NimNode): NimNode {.inline.} = - if n.kind in {nnkType, nnkMetaNode .. nnkReturnToken}: + if n.kind > nnkNilLit: for i in 0 .. high(n): yield n[i]