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
This commit is contained in:
Zahary Karadjov 2012-10-03 21:11:41 +03:00
commit d9d82fb0af
21 changed files with 142 additions and 168 deletions

View file

@ -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)