From 6dd78f44adf6fb032d0ecd9db813651b9524fcac Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 6 Sep 2023 08:49:19 +0200 Subject: 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. --- parser/node.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'parser/node.go') 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 +} -- cgit v1.2.3