diff options
author | Araq <rumpf_a@web.de> | 2017-11-21 01:42:53 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-11-21 01:42:53 +0100 |
commit | fba5f5acd6ab1b0aaca79241f55f95b089fbad2c (patch) | |
tree | ead1b2d771e17330cb8c54e12514694ca7aca87e | |
parent | ae65368a65e1a300afc9f9051839fa25dd67d76e (diff) | |
download | Nim-fba5f5acd6ab1b0aaca79241f55f95b089fbad2c.tar.gz |
added a version of macros.expectLen that takes min/max values
-rw-r--r-- | lib/core/macros.nim | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/js/tarrayboundscheck.nim | 0 |
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index fc5b5bfb7..dc56bb671 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -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. diff --git a/tests/js/tarrayboundscheck.nim b/tests/js/tarrayboundscheck.nim index f0eaeb89d..f0eaeb89d 100755..100644 --- a/tests/js/tarrayboundscheck.nim +++ b/tests/js/tarrayboundscheck.nim |