first pass parsing done
This commit is contained in:
parent
d67c2eb3a2
commit
213f719621
20
main.go
20
main.go
|
@ -103,11 +103,21 @@ func main() {
|
||||||
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
||||||
f.Filebase = protobase
|
f.Filebase = protobase
|
||||||
|
|
||||||
if err := pb.findGlobalAutogenpb(f); err != nil {
|
// parse the .proto file
|
||||||
|
if err := pb.protoParse(f); err != nil {
|
||||||
log.Info("autogenpb parse error:", err)
|
log.Info("autogenpb parse error:", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse sort & marshal options from the .proto file
|
||||||
|
// this goes through the .proto files and looks
|
||||||
|
// for `autogenpb: ` lines
|
||||||
|
if err := pb.protoParseNew(f); err != nil {
|
||||||
|
log.Info("autogenpb parse error:", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// this should be garbage soon
|
||||||
sortmap = make(map[string]string)
|
sortmap = make(map[string]string)
|
||||||
sortmap["package"] = packageName
|
sortmap["package"] = packageName
|
||||||
sortmap["protofile"] = argv.Proto
|
sortmap["protofile"] = argv.Proto
|
||||||
|
@ -134,14 +144,6 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse sort & marshal options from the .proto file
|
|
||||||
// this goes through the .proto files and looks
|
|
||||||
// for `autogenpb: ` lines
|
|
||||||
if err := pb.findAutogenpb(f); err != nil {
|
|
||||||
log.Info("autogenpb parse error:", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to make foo.pb.go with protoc if it's not here
|
// try to make foo.pb.go with protoc if it's not here
|
||||||
// this is helpful because the protoc-gen-go lines
|
// this is helpful because the protoc-gen-go lines
|
||||||
// are also annoying to code by hand
|
// are also annoying to code by hand
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
// finds autogenpb:marshal and autogenpb:unique in the .proto file
|
// finds autogenpb:marshal and autogenpb:unique in the .proto file
|
||||||
//
|
//
|
||||||
// adds fields to []marshal and []unique
|
// adds fields to []marshal and []unique
|
||||||
func (pb *Files) findAutogenpb(f *File) error {
|
func (pb *Files) protoParseNew(f *File) error {
|
||||||
// log.Info("starting findAutogenpb() on", names["protofile"])
|
// log.Info("starting findAutogenpb() on", names["protofile"])
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
data, err := os.ReadFile(f.Filename)
|
data, err := os.ReadFile(f.Filename)
|
||||||
|
@ -41,22 +41,29 @@ func (pb *Files) findAutogenpb(f *File) error {
|
||||||
|
|
||||||
if strings.Contains(line, "autogenpb:sort") {
|
if strings.Contains(line, "autogenpb:sort") {
|
||||||
if parts[0] == "repeated" {
|
if parts[0] == "repeated" {
|
||||||
newm := parts[1]
|
newS := parts[1]
|
||||||
if curmsg == nil {
|
if curmsg == nil {
|
||||||
log.Info("Error: Found Sort for:", newm, "however, this struct can't be used")
|
log.Info("Error: Found Sort for:", newS, "however, this struct can't be used")
|
||||||
} else {
|
} else {
|
||||||
log.Info("Found Sort for:", newm, "in struct", curmsg.Name)
|
log.Info("Addded Sort:", newS, "in struct", curmsg.Name)
|
||||||
|
curmsg.Sort = append(curmsg.Sort, newS)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Info("Error:", line)
|
log.Info("Error:", line)
|
||||||
log.Info("Error: can not sort on non repeated fields")
|
log.Info("Error: can not sort on non repeated fields")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(line, "autogenpb:unique") {
|
if strings.Contains(line, "autogenpb:unique") {
|
||||||
if parts[0] == "repeated" {
|
if parts[0] == "repeated" {
|
||||||
newu := parts[1]
|
newU := parts[1]
|
||||||
newu = cases.Title(language.English, cases.NoLower).String(newu)
|
newU = cases.Title(language.English, cases.NoLower).String(newU)
|
||||||
log.Info("Found unique field", newu, "in struct", curmsg.Name)
|
if curmsg == nil {
|
||||||
|
log.Info("Error: Found Unique for:", newU, "however, this struct can't be used")
|
||||||
|
} else {
|
||||||
|
log.Info("Added Unique:", newU, "in struct", curmsg.Name)
|
||||||
|
curmsg.Unique = append(curmsg.Unique, newU)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Info("Error:", line)
|
log.Info("Error:", line)
|
||||||
log.Info("Error: can not append on non repeated fields")
|
log.Info("Error: can not append on non repeated fields")
|
||||||
|
@ -88,7 +95,8 @@ func (f *File) parseForMessage(line string) *MsgName {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *Files) findGlobalAutogenpb(f *File) error {
|
// this doesn't do anything anymore (?)
|
||||||
|
func (pb *Files) protoParse(f *File) error {
|
||||||
// log.Info("starting findAutogenpb() on", filename)
|
// log.Info("starting findAutogenpb() on", filename)
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
data, err := os.ReadFile(f.Filename)
|
data, err := os.ReadFile(f.Filename)
|
||||||
|
|
Loading…
Reference in New Issue