forked from tliron/puccini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
56 lines (43 loc) · 1.45 KB
/
parse.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
49
50
51
52
53
54
55
56
package parser
import (
"errors"
"github.com/tliron/kutil/ard"
"github.com/tliron/kutil/problems"
"github.com/tliron/kutil/terminal"
urlpkg "github.com/tliron/kutil/url"
"github.com/tliron/puccini/tosca"
"github.com/tliron/puccini/tosca/normal"
)
func (self *Context) Parse(url urlpkg.URL, origins []urlpkg.URL, stylist *terminal.Stylist, quirks tosca.Quirks, inputs map[string]ard.Value) (*ServiceContext, *normal.ServiceTemplate, *problems.Problems, error) {
serviceContext := self.NewServiceContext(stylist, quirks)
// Phase 1: Read
ok := serviceContext.ReadRoot(url, origins, "")
serviceContext.MergeProblems()
problems := serviceContext.GetProblems()
if !problems.Empty() {
return serviceContext, nil, problems, errors.New("read problems")
}
if !ok {
return serviceContext, nil, nil, errors.New("read error")
}
// Phase 2: Namespaces
serviceContext.AddNamespaces()
serviceContext.LookupNames()
// Phase 3: Hierarchies
serviceContext.AddHierarchies()
// Phase 4: Inheritance
serviceContext.Inherit(nil)
serviceContext.SetInputs(inputs)
// Phase 5: Rendering
serviceContext.Render()
serviceContext.MergeProblems()
if !problems.Empty() {
return serviceContext, nil, problems, errors.New("parsing problems")
}
// Normalize
serviceTemplate, ok := serviceContext.Normalize()
if !ok || !problems.Empty() {
return serviceContext, nil, problems, errors.New("normalization")
}
return serviceContext, serviceTemplate, problems, nil
}