From 00394a80501960ad26787b5c44435ed5ed67ad84 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 9 Mar 2026 23:05:42 +0300 Subject: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D1=83.?= =?UTF-8?q?=20=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D1=91=D0=BB=20=D1=81=20EBNF?= =?UTF-8?q?=20=D0=BD=D0=B0=20PEG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- visitor/default.go | 63 ------------------------------------------------------ 1 file changed, 63 deletions(-) delete mode 100644 visitor/default.go (limited to 'visitor/default.go') diff --git a/visitor/default.go b/visitor/default.go deleted file mode 100644 index d8c8172..0000000 --- a/visitor/default.go +++ /dev/null @@ -1,63 +0,0 @@ -package visitor - -import ( - "errors" - "fmt" - "strings" - - "go.neonxp.ru/conf/model" -) - -var ( - ErrEmptyQuery = errors.New("empty query") - ErrNoChildKey = errors.New("no child key") -) - -func NewDefault() *Default { - return &Default{ - vars: map[string]model.Values{}, - children: map[string]*Default{}, - args: model.Values{}, - } -} - -// Default просто собирает рекурсивно все переменные в дерево. -// На самом деле, для большинства сценариев конфигов его должно хватить. -type Default struct { - vars map[string]model.Values - children map[string]*Default - args model.Values -} - -func (p *Default) VisitDirective(ident string, args model.Values, body model.Body) error { - p.children[ident] = NewDefault() - p.children[ident].args = args - return body.Execute(p.children[ident]) -} - -func (p *Default) VisitSetting(key string, values model.Values) error { - p.vars[key] = values - - return nil -} - -func (p *Default) Get(path string) (model.Values, error) { - splitPath := strings.SplitN(path, ".", 2) - switch len(splitPath) { - case 1: - if v, ok := p.vars[splitPath[0]]; ok { - return v, nil - } - if child, ok := p.children[splitPath[0]]; ok { - return child.args, nil - } - return nil, fmt.Errorf("%w: %s", ErrNoChildKey, splitPath[0]) - case 2: - if child, ok := p.children[splitPath[0]]; ok { - return child.Get(splitPath[1]) - } - return nil, fmt.Errorf("%w: %s", ErrNoChildKey, splitPath[0]) - default: - return nil, ErrEmptyQuery - } -} -- cgit v1.2.3