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 --- loader.go | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) (limited to 'loader.go') diff --git a/loader.go b/loader.go index 7f58237..99a8276 100644 --- a/loader.go +++ b/loader.go @@ -4,49 +4,25 @@ import ( "fmt" "os" - "go.neonxp.ru/conf/internal/ast" - "go.neonxp.ru/conf/internal/parser" "go.neonxp.ru/conf/model" + "go.neonxp.ru/conf/parser" ) -func New() *Conf { - return &Conf{ - root: model.Body{}, - } -} - -type Conf struct { - root model.Body -} - -func (c *Conf) LoadFile(filename string) error { +func LoadFile(filename string) (model.Group, error) { content, err := os.ReadFile(filename) if err != nil { - return fmt.Errorf("failed load file: %w", err) + return nil, fmt.Errorf("failed load file: %w", err) } - return c.Load(filename, content) + return Load(filename, content) } -func (c *Conf) Load(name string, input []byte) error { - p := &parser.Parser{} - astSlice, err := p.Parse(name, input) - if err != nil { - return fmt.Errorf("failed parse conf content: %w", err) - } - - astTree := ast.Parse(p, astSlice) +func Load(name string, input []byte) (model.Group, error) { - doc, err := ast.ToDoc(astTree[0]) + res, err := parser.Parse(name, input) if err != nil { - return fmt.Errorf("failed build Doc: %w", err) + return nil, parser.CaretErrors(err, string(input)) } - c.root = doc - - return nil -} - -func (c *Conf) Process(visitor model.Visitor) error { - return c.root.Execute(visitor) + return res.(model.Group), nil } -- cgit v1.2.3