diff --git a/term.go b/term.go index 5e869da..556410f 100644 --- a/term.go +++ b/term.go @@ -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)