diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-10-03 21:11:41 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-10-04 15:37:26 +0300 |
commit | d9d82fb0af8688e7c847bb7b0c3b2e38f7c8a735 (patch) | |
tree | 2e547df69eead6665ca4127f63872f0bbd67f275 /tests/run | |
parent | a6d5707faff21722f22f91c56704c44fc03d47f6 (diff) | |
download | Nim-d9d82fb0af8688e7c847bb7b0c3b2e38f7c8a735.tar.gz |
syntax compatibility between do blocks and stmt blocks
See the section `do notation` in the manual for more info. * nkMacroStmt has been removed Macro statements are now mapped to regular nkCall nodes. The support for additional clauses (such as else, except, of, etc) have been restored - they will now appear as additional arguments for the nkCall node (as nkElse, nkExcept, etc nodes) * fixed some regressions in the `is` operator and semCompiles
Diffstat (limited to 'tests/run')
-rwxr-xr-x | tests/run/tmacros1.nim | 12 | ||||
-rw-r--r-- | tests/run/tusingstatement.nim | 10 |
2 files changed, 10 insertions, 12 deletions
diff --git a/tests/run/tmacros1.nim b/tests/run/tmacros1.nim index b2fb7240d..3c814ad6d 100755 --- a/tests/run/tmacros1.nim +++ b/tests/run/tmacros1.nim @@ -1,5 +1,5 @@ discard """ - output: "Got: 'nnkMacroStmt' hi" + output: "Got: 'nnkCall' hi" """ import @@ -11,17 +11,15 @@ macro outterMacro*(n: stmt): stmt {.immediate.} = proc innerProc(i: int): string = echo "Using arg ! " & n.repr result = "Got: '" & $n.kind & "' " & $j - if n.kind != TNimrodNodeKind.nnkMacroStmt: - error("Macro " & n[0].repr & " requires a block.") var callNode = n[0] - expectKind(callNode, TNimrodNodeKind.nnkCall) - if callNode.len != 2 or callNode[1].kind != TNimrodNodeKind.nnkIdent: + expectKind(n, TNimrodNodeKind.nnkCall) + if n.len != 3 or n[1].kind != TNimrodNodeKind.nnkIdent: error("Macro " & callNode.repr & " requires the ident passed as parameter (eg: " & callNode.repr & "(the_name_you_want)): statements.") result = newNimNode(TNimrodNodeKind.nnkStmtList) - var ass : PNimrodNode = newNimNode(TNimrodNodeKind.nnkAsgn) - ass.add(newIdentNode(callNode[1].ident)) + var ass : PNimrodNode = newNimNode(nnkAsgn) + ass.add(newIdentNode(n[1].ident)) ass.add(newStrLitNode(innerProc(4))) result.add(ass) diff --git a/tests/run/tusingstatement.nim b/tests/run/tusingstatement.nim index f5168dbf5..b9d466377 100644 --- a/tests/run/tusingstatement.nim +++ b/tests/run/tusingstatement.nim @@ -28,12 +28,12 @@ import # `opened` is defined to `optional.hasValue` macro using(e: expr): stmt {.immediate.} = let e = callsite() - if e.len != 2: + if e.len != 3: error "Using statement: unexpected number of arguments. Got " & $e.len & ", expected: 1 or more variable assignments and a block" - var args = e[0] - var body = e[1] + var args = e + var body = e[2] var variables : seq[PNimrodNode] @@ -41,8 +41,8 @@ macro using(e: expr): stmt {.immediate.} = newSeq(variables, 0) newSeq(closingCalls, 0) - - for i in countup(1, args.len-1): + + for i in countup(1, args.len-2): if args[i].kind == nnkExprEqExpr: var varName = args[i][0] var varValue = args[i][1] |