diff options
| author | Jeff Carr <[email protected]> | 2025-01-10 19:37:32 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-10 19:37:32 -0600 |
| commit | 22651438692cf991be22d8898e5727f586fd2f11 (patch) | |
| tree | b7e4936ca077f315af8d49908d0c14a5a1791411 /protoParse.go | |
| parent | dc86ae010f688eefc5f4757d1c6eb620effc68f9 (diff) | |
correctly identify the two primary structs
Diffstat (limited to 'protoParse.go')
| -rw-r--r-- | protoParse.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/protoParse.go b/protoParse.go index 832601d..173dd6f 100644 --- a/protoParse.go +++ b/protoParse.go @@ -33,8 +33,6 @@ func (pb *Files) hasPluralMessage(f *File) error { // nope, not this line continue } - // found the matching message - f.Bases = f.parseForMessage(line) line = scanner.Text() fields := strings.Fields(line) @@ -75,24 +73,19 @@ func (pb *Files) protoParse(f *File) error { // parse the proto file for message struct names for _, line := range strings.Split(string(data), "\n") { - base := cases.Title(language.English, cases.NoLower).String(f.Filebase) if strings.HasPrefix(line, "message ") { curmsg = f.parseForMessage(line) - prefix := "message " + base + " {" // only look for this for now - if strings.HasPrefix(line, prefix) { - f.Base = curmsg - f.MsgNames = append(f.MsgNames, curmsg) - } else { - f.MsgNames = append(f.MsgNames, curmsg) - } } + // this logic isn't right. find end of message with more bravado if strings.HasPrefix(line, "}") { curmsg = nil } if curmsg == nil { + // log.Info("curmsg == nil", line) // can't contiue on nil below here continue } + // log.Info("curmsg != nil", line) parts := strings.Fields(line) msgvar := parseMsgVar(line) @@ -151,16 +144,31 @@ func parseMsgVar(line string) *MsgVar { } // looks for mutex and marshal entries -func (f *File) parseForMessage(line string) *MsgName { +func (pf *File) parseForMessage(line string) *MsgName { fields := strings.Fields(line) - if fields[0] != "message" { + if len(fields) == 0 || fields[0] != "message" { return nil } + var msg *MsgName + msg = new(MsgName) + + base := cases.Title(language.English, cases.NoLower).String(pf.Filebase) + prefix := "message " + base + "s {" // only look for this for now + if strings.HasPrefix(line, prefix) { + pf.Bases = msg + } else { + prefix := "message " + base + " {" // only look for this for now + if strings.HasPrefix(line, prefix) { + pf.Base = msg + } else { + pf.MsgNames = append(pf.MsgNames, msg) + } + } + msgName := cases.Title(language.English, cases.NoLower).String(fields[1]) log.Info("found messge:", msgName) - msg := new(MsgName) msg.Name = msgName - msg.Lockname = f.Filebase + "Mu" // this should be lowercase. do not export the Mutex + msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex if strings.Contains(line, "`autogenpb:mutex`") { msg.DoMutex = true |
