diff options
| author | 2026-02-17 21:33:24 +0300 | |
|---|---|---|
| committer | 2026-02-21 16:23:10 +0300 | |
| commit | ba06314d59e55945b103ead2c7a9e01f58c6a93c (patch) | |
| tree | 34ab8ac19307da60bd5caf76d844a6dc2e730361 /internal/ast/processor.go | |
| parent | init (diff) | |
| download | conf-ba06314d59e55945b103ead2c7a9e01f58c6a93c.tar.gz conf-ba06314d59e55945b103ead2c7a9e01f58c6a93c.tar.bz2 conf-ba06314d59e55945b103ead2c7a9e01f58c6a93c.tar.xz conf-ba06314d59e55945b103ead2c7a9e01f58c6a93c.zip | |
v0.0.1v0.0.1
Diffstat (limited to '')
| -rw-r--r-- | internal/ast/processor.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/internal/ast/processor.go b/internal/ast/processor.go index 89ffbff..783dbbe 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.Doc, error) { if len(config.Children) < 1 { return nil, fmt.Errorf("invalid ast tree") } @@ -18,24 +18,22 @@ func ToDoc(config *Node) (model.Doc, error) { return processDoc(doc), nil } -func processDoc(docNode *Node) model.Doc { - doc := make(model.Doc, len(docNode.Children)) - for i, stmt := range docNode.Children { - doc[i] = processStmt(stmt) +func processDoc(docNode *Node) *model.Doc { + doc := model.New(len(docNode.Children)) + for _, stmt := range docNode.Children { + processStmt(doc, stmt) } return doc } -func processStmt(stmt *Node) any { +func processStmt(doc *model.Doc, stmt *Node) { ident := extractIdent(stmt.Children[0]) nodeBody := stmt.Children[1] switch nodeBody.Symbol { case parser.Command: - return processCommand(ident, nodeBody) + doc.AppendCommand(processCommand(ident, nodeBody)) case parser.Assignment: - return processAssignment(ident, nodeBody) - default: - return nil + doc.AppendAssignment(processAssignment(ident, nodeBody)) } } |
