goclj icon indicating copy to clipboard operation
goclj copied to clipboard

Add a new package that makes it easier to do common things with a parse.Tree

Open cespare opened this issue 9 years ago • 1 comments

Some common tasks:

  • Checking whether a node is a symbol (or keyword, etc) and if it is, pulling out Val
  • Walking through the whole tree recursively

It would be nice to have some clever high-level API for searching/matching certain constructs.

cespare avatar Sep 28 '16 04:09 cespare

Another idea:

  • Expose the key/value pairs of a map

There may be non-semantic nodes present, so a caller can't just iterate through every pair of m.Children().

Maybe this is implemented as:

type KeyVal struct {
        Key Node
        Val Node
}

func (m *MapNode) KeyVals() []*KeyVal

Or you could have an iterator, which might be more efficient if you're only looking for one key, say:

kv := m.KeyVals()
for kv.Next() {
        key, val := kv.KeyVal()
}

dmac avatar Mar 30 '22 05:03 dmac