Make macros.nim expectKind error message with a single TNimrodNodeKind consistent with error message shown with a set of TNimrodNodeKind by displaying the actual node kind (as well as the expected)
This commit is contained in:
parent
f4e0f64f86
commit
df7e388e0c
1 changed files with 3 additions and 3 deletions
|
|
@ -339,11 +339,13 @@ proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst", noSideEffect.
|
|||
## if not `ex`:
|
||||
## echo `info` & ": Check failed: " & `expString`
|
||||
|
||||
from strutils import cmpIgnoreStyle, format
|
||||
|
||||
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
|
||||
## checks that `n` is of kind `k`. If this is not the case,
|
||||
## compilation aborts with an error message. This is useful for writing
|
||||
## macros that check the AST that is passed to them.
|
||||
if n.kind != k: error("macro expects a node of kind: " & $k)
|
||||
if n.kind != k: error("Expected a node of kind $1, got $2".format(k, n.kind))
|
||||
|
||||
proc expectMinLen*(n: PNimrodNode, min: int) {.compileTime.} =
|
||||
## checks that `n` has at least `min` children. If this is not the case,
|
||||
|
|
@ -581,8 +583,6 @@ const
|
|||
CallNodes* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand,
|
||||
nnkCallStrLit, nnkHiddenCallConv}
|
||||
|
||||
from strutils import cmpIgnoreStyle, format
|
||||
|
||||
proc expectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} =
|
||||
assert n.kind in k, "Expected one of $1, got $2".format(k, n.kind)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue