-
Notifications
You must be signed in to change notification settings - Fork 20
/
parse.go
50 lines (38 loc) · 951 Bytes
/
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
package parser
import (
contextpkg "context"
"errors"
"github.com/tliron/puccini/normal"
)
func (self *Context) Parse(context contextpkg.Context) (*normal.ServiceTemplate, error) {
// Phase 1: Read
ok := self.ReadRoot(context, self.URL, self.Bases, "")
self.MergeProblems()
problems := self.GetProblems()
if !ok {
return nil, errors.New("read error")
}
if !problems.Empty() {
return nil, errors.New("read problems")
}
// Phase 2: Namespaces
self.AddNamespaces()
self.LookupNames()
// Phase 3: Hierarchies
self.AddHierarchies()
// Phase 4: Inheritance
self.Inherit(nil)
self.SetInputs(self.Inputs)
// Phase 5: Rendering
self.Render()
self.MergeProblems()
if !problems.Empty() {
return nil, errors.New("parsing problems")
}
// Phase 6: Normalization
normalServiceTemplate, ok := self.Normalize()
if !ok || !problems.Empty() {
return nil, errors.New("normalization")
}
return normalServiceTemplate, nil
}