From 5f8ca47ef0fac5d4e449ed233e6356f03c9f8a15 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Tue, 23 Jul 2024 15:27:50 +0200 Subject: [PATCH] term.go: New function Clone() --- term.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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)