This commit is contained in:
Andrea Ferretti 2015-07-02 20:19:50 +02:00
commit e382833aa8

View file

@ -41,7 +41,7 @@ proc makeBranch(n: NimNode): NimNode {. compileTime .} =
else: else:
error("Invalid ADT case: " & $(toStrLit(n))) error("Invalid ADT case: " & $(toStrLit(n)))
macro adt*(e: expr, body: stmt): stmt {. immediate .} = proc defineTypes(e, body: NimNode): NimNode {. compileTime .} =
e.expectKind(nnkIdent) e.expectKind(nnkIdent)
body.expectKind(nnkStmtList) body.expectKind(nnkStmtList)
# The children of the body should look like object constructors # The children of the body should look like object constructors
@ -72,6 +72,9 @@ macro adt*(e: expr, body: stmt): stmt {. immediate .} =
result = newNimNode(nnkTypeSection) result = newNimNode(nnkTypeSection)
result.add(enumType) result.add(enumType)
result.add(definedType) result.add(definedType)
macro adt*(e: expr, body: stmt): stmt {. immediate .} =
result = defineTypes(e, body)
when defined(pattydebug): when defined(pattydebug):
echo toStrLit(result) echo toStrLit(result)