From df7e388e0c226731be3c46be7aad2d9993599a9e Mon Sep 17 00:00:00 2001 From: Chris Heller Date: Mon, 2 Mar 2015 17:02:43 -0800 Subject: [PATCH] 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) --- lib/core/macros.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 4758dc0c1..519bae209 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -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)