aboutsummaryrefslogtreecommitdiff
path: root/internal/ast
diff options
context:
space:
mode:
author2026-02-22 20:15:50 +0300
committer2026-02-22 20:15:50 +0300
commitdb8bb97dfa2dacef002a1f349ea970d76fee4fc9 (patch)
tree7de11be3a01a6ef83a218dc98d90586dd1afb09a /internal/ast
parentДобавил утилитарные функции для моделей (diff)
downloadconf-0.0.4.tar.gz
conf-0.0.4.tar.bz2
conf-0.0.4.tar.xz
conf-0.0.4.zip
Refactoringv0.0.4
Diffstat (limited to 'internal/ast')
-rw-r--r--internal/ast/processor.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/internal/ast/processor.go b/internal/ast/processor.go
index 783dbbe..55dce59 100644
--- a/internal/ast/processor.go
+++ b/internal/ast/processor.go
@@ -8,7 +8,7 @@ import (
"go.neonxp.ru/conf/model"
)
-func ToDoc(config *Node) (*model.Doc, error) {
+func ToDoc(config *Node) (model.Body, error) {
if len(config.Children) < 1 {
return nil, fmt.Errorf("invalid ast tree")
}
@@ -18,31 +18,31 @@ func ToDoc(config *Node) (*model.Doc, error) {
return processDoc(doc), nil
}
-func processDoc(docNode *Node) *model.Doc {
- doc := model.New(len(docNode.Children))
+func processDoc(docNode *Node) model.Body {
+ doc := make(model.Body, 0, len(docNode.Children))
for _, stmt := range docNode.Children {
- processStmt(doc, stmt)
+ processStmt(&doc, stmt)
}
return doc
}
-func processStmt(doc *model.Doc, stmt *Node) {
+func processStmt(doc *model.Body, stmt *Node) {
ident := extractIdent(stmt.Children[0])
nodeBody := stmt.Children[1]
switch nodeBody.Symbol {
case parser.Command:
- doc.AppendCommand(processCommand(ident, nodeBody))
+ *doc = append(*doc, processDirective(ident, nodeBody))
case parser.Assignment:
- doc.AppendAssignment(processAssignment(ident, nodeBody))
+ *doc = append(*doc, processSetting(ident, nodeBody))
}
}
-func processCommand(ident string, command *Node) *model.Command {
- result := &model.Command{
+func processDirective(ident string, directive *Node) *model.Directive {
+ result := &model.Directive{
Name: ident,
}
- for _, child := range command.Children {
+ for _, child := range directive.Children {
// Can be arguments OR body OR both
switch child.Symbol {
case parser.Values:
@@ -56,10 +56,10 @@ func processCommand(ident string, command *Node) *model.Command {
return result
}
-func processAssignment(ident string, assignment *Node) *model.Assignment {
- result := &model.Assignment{
+func processSetting(ident string, setting *Node) *model.Setting {
+ result := &model.Setting{
Key: ident,
- Value: extractValues(assignment.Children[1]), // Children[0] = '=', Children[1] = Values, Children[2] = ';'
+ Value: extractValues(setting.Children[1]), // Children[0] = '=', Children[1] = Values, Children[2] = ';'
}
return result