-
Notifications
You must be signed in to change notification settings - Fork 20
/
phase2.1-namespaces.go
47 lines (37 loc) · 1.12 KB
/
phase2.1-namespaces.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
package parser
import (
"github.com/tliron/kutil/terminal"
"github.com/tliron/puccini/tosca/parsing"
)
func (self *Context) AddNamespaces() {
self.Parser.lock.Lock()
defer self.Parser.lock.Unlock()
self.Root.mergeNamespaces()
}
func (self *File) mergeNamespaces() {
context := self.GetContext()
self.importsLock.RLock()
defer self.importsLock.RUnlock()
for _, import_ := range self.Imports {
import_.mergeNamespaces()
context.Namespace.Merge(import_.GetContext().Namespace, import_.NameTransformer)
context.ScriptletNamespace.Merge(import_.GetContext().ScriptletNamespace)
}
logNamespaces.Debugf("create: %s", context.URL.String())
namespace := parsing.NewNamespaceFor(self.EntityPtr)
context.Namespace.Merge(namespace, nil)
}
// Print
func (self *Context) PrintNamespaces(indent int) {
self.filesLock.RLock()
defer self.filesLock.RUnlock()
childIndent := indent + 1
for _, file := range self.Files {
context := file.GetContext()
if !context.Namespace.Empty() {
terminal.PrintIndent(indent)
terminal.Printf("%s\n", self.Stylist.Value(context.URL.String()))
context.Namespace.Print(childIndent)
}
}
}