Adoption style tree construction

Grammar astc

bhook <- 0
A before statment hook
ehook <- 0
An error hook
hooked(content) <- astc.bhook * (content | astc.ehook)

Use this to properly adopt groups, just use astc.hooked()

Note: This requires the AdoptionCenter to be named ac

Types

AdoptionCenter[T] = ref object
  s: seq[T]
  markers: seq[int]
  Source Edit
User[T] = proc (node: var T; children: seq[T])
  Source Edit

Procs

proc newAdoptionCenter[T](): AdoptionCenter[T]
Create a new AdoptionCenter type   Source Edit
proc add[T](a: var AdoptionCenter[T]; node: T)
Register a node for adoption   Source Edit
proc addMarker[T](a: AdoptionCenter[T])
Add a marker   Source Edit
proc failMarker[T](a: AdoptionCenter[T])
Remove a marker without processing   Source Edit
proc len[T](a: AdoptionCenter[T]): int
Get the length of un-adopted children   Source Edit
proc pop[T](a: var AdoptionCenter[T]): T
Pop the un-adopted children seq   Source Edit
proc `[]`[T](a: AdoptionCenter[T]; i: int): T
Self-explanatory   Source Edit
proc adopt[T](node: var T; a: var AdoptionCenter[T]; amount: int;
              u: User[T] = defaultUser[T])
Adopt amount amount of children to node using u   Source Edit
proc adopt[T](node: var T; a: var AdoptionCenter[T]; u: User[T] = defaultUser)
Adopt marked amount to node using u   Source Edit

Templates

template adoptCycle(center: untyped; n: untyped; cond: untyped): untyped
Equivalent to:
n.adopt(center, cond)
center.add n

Note: n must be var

  Source Edit
template adoptCycle(center: untyped; n: untyped): untyped
  Source Edit