-
Notifications
You must be signed in to change notification settings - Fork 4
/
generator.go
48 lines (38 loc) · 947 Bytes
/
generator.go
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
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"io"
"github.com/g4s8/envdoc/ast"
"github.com/g4s8/envdoc/debug"
"github.com/g4s8/envdoc/resolver"
"github.com/g4s8/envdoc/types"
)
type Renderer interface {
Render(scopes []*types.EnvScope, out io.Writer) error
}
type Generator struct {
parser *ast.Parser
converter *Converter
renderer Renderer
}
func NewGenerator(parser *ast.Parser, converter *Converter, renderer Renderer) *Generator {
return &Generator{
parser: parser,
converter: converter,
renderer: renderer,
}
}
func (g *Generator) Generate(dir string, out io.Writer) error {
files, err := g.parser.Parse(dir)
if err != nil {
return fmt.Errorf("parse dir: %w", err)
}
res := resolver.ResolveAllTypes(files)
debug.PrintDebug(res)
scopes := g.converter.ScopesFromFiles(res, files)
printScopesTree(scopes)
if err := g.renderer.Render(scopes, out); err != nil {
return fmt.Errorf("render: %w", err)
}
return nil
}