smarter parsing

This commit is contained in:
Jeff Carr 2025-01-08 20:58:29 -06:00
parent ad67a6f42d
commit 355817c0db
1 changed files with 14 additions and 10 deletions

View File

@ -25,23 +25,26 @@ func (pb *Files) findAutogenpb(f *File) error {
return err return err
} }
// first parse the proto file for message struct names var curmsg *MsgName
// parse the proto file for message struct names
for _, line := range strings.Split(string(data), "\n") { for _, line := range strings.Split(string(data), "\n") {
if strings.HasPrefix(line, "message ") { if strings.HasPrefix(line, "message ") {
f.parseForMessage(line) curmsg = f.parseForMessage(line)
} }
if strings.HasPrefix(line, "}") {
curmsg = nil
} }
// look for included proto files
lines := strings.Split(string(data), "\n")
for _, line := range lines {
// log.Info("line:", line) // log.Info("line:", line)
parts := strings.Fields(line) parts := strings.Fields(line)
if strings.Contains(line, "autogenpb:marshal") { if strings.Contains(line, "autogenpb:marshal") {
newm := parts[1] newm := parts[1]
if curmsg != nil {
// log.Info("found marshal", newm) // log.Info("found marshal", newm)
marshalKeys = append(marshalKeys, newm) marshalKeys = append(marshalKeys, newm)
} }
}
if strings.Contains(line, "autogenpb:unique") { if strings.Contains(line, "autogenpb:unique") {
newu := parts[1] newu := parts[1]
newu = cases.Title(language.English, cases.NoLower).String(newu) newu = cases.Title(language.English, cases.NoLower).String(newu)
@ -53,10 +56,10 @@ func (pb *Files) findAutogenpb(f *File) error {
} }
// looks for mutex and marshal entries // looks for mutex and marshal entries
func (f *File) parseForMessage(line string) { func (f *File) parseForMessage(line string) *MsgName {
fields := strings.Fields(line) fields := strings.Fields(line)
if fields[0] != "message" { if fields[0] != "message" {
return return nil
} }
msgName := fields[1] msgName := fields[1]
msg := new(MsgName) msg := new(MsgName)
@ -71,6 +74,7 @@ func (f *File) parseForMessage(line string) {
msg.DoMarshal = true msg.DoMarshal = true
log.Info("Found Marshal for:", msg.Name) log.Info("Found Marshal for:", msg.Name)
} }
return msg
} }
func (pb *Files) findGlobalAutogenpb(f *File) error { func (pb *Files) findGlobalAutogenpb(f *File) error {