aboutsummaryrefslogtreecommitdiff
path: root/loader.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--loader.go40
1 files changed, 8 insertions, 32 deletions
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
}