1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package conf
import (
"fmt"
"os"
"go.neonxp.ru/conf/internal/ast"
"go.neonxp.ru/conf/internal/parser"
"go.neonxp.ru/conf/model"
)
func LoadFile(filename string) (model.Doc, error) {
content, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("failed load file: %w", err)
}
return Load(filename, content)
}
func Load(name string, input []byte) (model.Doc, error) {
p := &parser.Parser{}
astSlice, err := p.Parse(name, input)
if err != nil {
return nil, fmt.Errorf("failed parse conf content: %w", err)
}
astTree := ast.Parse(p, astSlice)
doc, err := ast.ToDoc(astTree[0])
if err != nil {
return nil, fmt.Errorf("failed build Doc: %w", err)
}
return doc, nil
}
|