term.go: New function Clone()

This commit is contained in:
Celestino Amoroso 2024-07-23 15:27:50 +02:00
parent 837b887490
commit 5f8ca47ef0

19
term.go
View File

@ -53,6 +53,25 @@ type term struct {
evalFunc evalFuncType
}
func (s *term) Clone() (d *term) {
var children []*term
if s.children != nil {
children = make([]*term, len(s.children))
for i, c := range s.children {
children[i] = c.Clone()
}
}
d = &term{
tk: *s.tk.Clone(),
parent: s.parent,
children: children,
position: s.position,
priority: s.priority,
evalFunc: s.evalFunc,
}
return
}
func (term *term) String() string {
var sb strings.Builder
term.toString(&sb)