diff options
| author | Marc Vertes <mvertes@free.fr> | 2023-09-06 08:49:19 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2023-09-06 08:49:19 +0200 |
| commit | 6dd78f44adf6fb032d0ecd9db813651b9524fcac (patch) | |
| tree | d1d4b3305db708614f147b2294b4b0e28336a55d /parser/node.go | |
| parent | 4241593b42bffac2f8fcb63f1e88621fe025e360 (diff) | |
chore: refactor some APIs
The scanner returns a slice of pointers to tokens instead of a
slice of tokens. The parser now pass the initial node context.
Diffstat (limited to 'parser/node.go')
| -rw-r--r-- | parser/node.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/parser/node.go b/parser/node.go index d2f13ef..b6e34cd 100644 --- a/parser/node.go +++ b/parser/node.go @@ -3,9 +3,9 @@ package parser import "github.com/gnolang/parscan/scanner" type Node struct { - Child []*Node // sub-tree nodes - scanner.Token // token at origin of the node - Kind // Node kind, depends on the language spec + Child []*Node // sub-tree nodes + *scanner.Token // token at origin of the node + Kind // Node kind, depends on the language spec } // TODO: remove it in favor of Walk2 @@ -39,3 +39,12 @@ func (n *Node) Walk2(a *Node, i int, in, out func(*Node, *Node, int) bool) (stop } return } + +func (n *Node) RemoveChild(i int) { + n.Child = append(n.Child[:i], n.Child[i+1:]...) +} + +func (n *Node) InsertChild(node *Node, i int) { + n.Child = append(n.Child[:i+1], n.Child[i:]...) + n.Child[i] = node +} |
