Skip to content

Commit

Permalink
better code, preserve line info
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Sep 23, 2024
1 parent 3ca2c7b commit 84aa5eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 8 additions & 9 deletions stew/staticfor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ proc replaceNodes(ast: NimNode, what: NimNode, by: NimNode): NimNode =
case node.kind:
of {nnkIdent, nnkSym}:
if node.eqIdent(what):
return by
return node
of nnkEmpty:
return node
of nnkLiterals:
return node
by
else:
node
of nnkEmpty, nnkLiterals:
node
else:
var rTree = node.kind.newTree()
let rTree = newNimNode(node.kind, lineInfoFrom = node)
for child in node:
rTree.add inspect(child)
return rTree
result = inspect(ast)
rTree
inspect(ast)

macro staticFor*(idx: untyped{nkIdent}, slice: static Slice[int], body: untyped): untyped =
## Unrolled `for` loop over the given range:
Expand Down
1 change: 1 addition & 0 deletions tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import
test_ptrops,
test_sequtils2,
test_sets,
test_staticfor,
test_strformat,
test_templateutils,
test_winacl

0 comments on commit 84aa5eb

Please sign in to comment.