Consider this code:
import macros
dumpTree:
type
ObjectKind = enum
oA, oB
ObjectType = object
case kind: ObjectKind
of oA:
a: string
of oB:
b: string
ObjectType2 = object
case kind: ObjectKind
of oA: a: string
of oB: b: string
proc foo(): int = 2
proc bar(): int =
2
It outputs:
StmtList
TypeSection
TypeDef
Ident !"ObjectKind"
Empty
EnumTy
Empty
Ident !"oA"
Ident !"oB"
TypeDef
Ident !"ObjectType"
Empty
ObjectTy
Empty
Empty
RecList
RecCase
IdentDefs
Ident !"kind"
Ident !"ObjectKind"
Empty
OfBranch
Ident !"oA"
RecList
IdentDefs
Ident !"a"
Ident !"string"
Empty
OfBranch
Ident !"oB"
RecList
IdentDefs
Ident !"b"
Ident !"string"
Empty
TypeDef
Ident !"ObjectType2"
Empty
ObjectTy
Empty
Empty
RecList
RecCase
IdentDefs
Ident !"kind"
Ident !"ObjectKind"
Empty
OfBranch
Ident !"oA"
IdentDefs
Ident !"a"
Ident !"string"
Empty
OfBranch
Ident !"oB"
IdentDefs
Ident !"b"
Ident !"string"
Empty
ProcDef
Ident !"foo"
Empty
Empty
FormalParams
Ident !"int"
Empty
Empty
StmtList
IntLit 2
ProcDef
Ident !"bar"
Empty
Empty
FormalParams
Ident !"int"
Empty
Empty
StmtList
IntLit 2
As you can see, the declaration of `ObjectType` produces `RecList` s inside its
case branches, while `ObjectType2` does not. I think it would be good for both
cases to produce the same AST since they are equivalent.
As comparison, I added the two proc defs at the end: Both produce a wrapping
`StmtList` although one has its implementation on the same line and one in the
next line.
My problem is that a specification of how the AST will look like exactly is
currently missing, so I usually just look at the AST that is produced. And that
way, I may overlook things like „if a variable declaration is on the same line
as the of branch, no wrapping `RecList` is produced“.