added a version of macros.expectLen that takes min/max values
This commit is contained in:
parent
ae65368a65
commit
fba5f5acd6
2 changed files with 7 additions and 0 deletions
|
|
@ -435,6 +435,13 @@ proc expectLen*(n: NimNode, len: int) {.compileTime.} =
|
|||
## macros that check its number of arguments.
|
||||
if n.len != len: error("macro expects a node with " & $len & " children", n)
|
||||
|
||||
proc expectLen*(n: NimNode, min, max: int) {.compileTime.} =
|
||||
## checks that `n` has a number of children in the range ``min..max``.
|
||||
## If this is not the case, compilation aborts with an error message.
|
||||
## This is useful for writing macros that check its number of arguments.
|
||||
if n.len < min or n.len > max:
|
||||
error("macro expects a node with " & $min & ".." & $max " children", n)
|
||||
|
||||
proc newTree*(kind: NimNodeKind,
|
||||
children: varargs[NimNode]): NimNode {.compileTime.} =
|
||||
## produces a new node with children.
|
||||
|
|
|
|||
0
tests/js/tarrayboundscheck.nim
Executable file → Normal file
0
tests/js/tarrayboundscheck.nim
Executable file → Normal file
Loading…
Add table
Add a link
Reference in a new issue