generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
55 lines (43 loc) · 1.31 KB
/
config.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
package schema
import (
"fmt"
"strings"
"google.golang.org/protobuf/reflect/protoreflect"
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)
type Config struct {
Pos Position `parser:"" protobuf:"1,optional"`
Comments []string `parser:"@Comment*" protobuf:"2"`
Name string `parser:"'config' @Ident" protobuf:"3"`
Type Type `parser:"@@" protobuf:"4"`
}
var _ Decl = (*Config)(nil)
var _ Symbol = (*Config)(nil)
func (s *Config) GetName() string { return s.Name }
func (s *Config) IsExported() bool { return false }
func (s *Config) Position() Position { return s.Pos }
func (s *Config) String() string {
w := &strings.Builder{}
fmt.Fprint(w, EncodeComments(s.Comments))
fmt.Fprintf(w, "config %s %s", s.Name, s.Type)
return w.String()
}
func (s *Config) ToProto() protoreflect.ProtoMessage {
return &schemapb.Config{
Pos: posToProto(s.Pos),
Comments: s.Comments,
Name: s.Name,
Type: TypeToProto(s.Type),
}
}
func (s *Config) schemaChildren() []Node { return []Node{s.Type} }
func (s *Config) schemaDecl() {}
func (s *Config) schemaSymbol() {}
func ConfigFromProto(p *schemapb.Config) *Config {
return &Config{
Pos: posFromProto(p.Pos),
Comments: p.Comments,
Name: p.Name,
Type: TypeFromProto(p.Type),
}
}