diff options
| author | Jeff Carr <[email protected]> | 2025-01-10 11:22:08 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-10 11:22:08 -0600 |
| commit | d36344e463e80d89d0cc8b028b6243823d184b35 (patch) | |
| tree | ea8c4c78907420631476fd5061500d896cded87b /protoParse.go | |
| parent | e07c6a35fd5d2ca1b3a6c09d9781d21f676f52f2 (diff) | |
make seperate find and sort files
Diffstat (limited to 'protoParse.go')
| -rw-r--r-- | protoParse.go | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/protoParse.go b/protoParse.go index 6403346..832601d 100644 --- a/protoParse.go +++ b/protoParse.go @@ -81,6 +81,7 @@ func (pb *Files) protoParse(f *File) error { 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) } @@ -93,13 +94,18 @@ func (pb *Files) protoParse(f *File) error { continue } - // log.Info("line:", line) parts := strings.Fields(line) + msgvar := parseMsgVar(line) + if msgvar == nil { + // log.Info("Junk in .proto file? line did not contain a message var:", line) + continue + } if strings.Contains(line, "autogenpb:sort") { newS := cases.Title(language.English, cases.NoLower).String(parts[1]) log.Info("Addded Sort:", newS, "in struct", curmsg.Name) curmsg.Sort = append(curmsg.Sort, newS) + msgvar.HasSort = true } if strings.Contains(line, "autogenpb:unique") { @@ -107,11 +113,43 @@ func (pb *Files) protoParse(f *File) error { newU = cases.Title(language.English, cases.NoLower).String(newU) log.Info("Added Unique:", newU, "in struct", curmsg.Name) curmsg.Unique = append(curmsg.Unique, newU) + msgvar.HasUnique = true } + curmsg.Vars = append(curmsg.Vars, msgvar) } return nil } +func parseMsgVar(line string) *MsgVar { + if strings.Contains(line, "//") { + parts := strings.Split(line, "//") + if len(parts) == 0 { + // log.Info("parseMsgVar() nothing line", line) + return nil + } + line = parts[0] + } + parts := strings.Fields(line) + if len(parts) < 3 { + // log.Info("parseMsgVar() len < 3", parts) + return nil + } + if parts[0] == "message" { + // this is the struct + return nil + } + v := new(MsgVar) + if parts[0] == "repeated" { + v.IsRepeated = true + v.VarType = parts[1] + v.VarName = parts[2] + return v + } + v.VarType = parts[0] + v.VarName = parts[1] + return v +} + // looks for mutex and marshal entries func (f *File) parseForMessage(line string) *MsgName { fields := strings.Fields(line) |
