This commit is contained in:
Jeff Carr 2025-03-29 21:10:22 -05:00
parent 3b43eea6a3
commit 12b8c5603b
1 changed files with 49 additions and 21 deletions

View File

@ -91,34 +91,39 @@ func doParse(lines []string) *FormatMsg {
line := allTheLines.NextRaw() line := allTheLines.NextRaw()
if strings.HasPrefix(line, "oneof ") { if strings.HasPrefix(line, "oneof ") {
newmsg := basemsg.newOneofMessage(line) newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
comments = "" comments = ""
newmsg.load()
inMessage = true inMessage = true
if strings.Contains(line, "}") {
newmsg.Footer = "} // blah"
continue
}
newmsg.load()
continue continue
} }
if strings.HasPrefix(line, "enum ") { if strings.HasPrefix(line, "enum ") {
newmsg := basemsg.newEnumMessage(line) newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
comments = "" comments = ""
newmsg.load()
inMessage = true inMessage = true
if strings.Contains(line, "}") {
newmsg.Footer = "} // blah"
continue
}
newmsg.load()
continue continue
} }
if strings.HasPrefix(line, "message ") { if strings.HasPrefix(line, "message ") {
log.Info("got to message", line) log.Info("got to message", line)
newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE)
newmsg := basemsg.newStdMessage(line)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
comments = "" comments = ""
newmsg.load()
inMessage = true inMessage = true
if strings.Contains(line, "}") {
newmsg.Footer = "} // blah"
continue
}
newmsg.load()
continue continue
} }
@ -156,30 +161,43 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
return newmsg return newmsg
} }
/*
// func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage { // func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
func (msgPB *FormatMsg) newStdMessage(header string) *FormatMsg { func (msgPB *FormatMsg) newStdMessage(header string, comments string) *FormatMsg {
newmsg := newDepth(msgPB, header) newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_MESSAGE newmsg.Type = FormatMsg_MESSAGE
msgPB.Msgs = append(msgPB.Msgs, newmsg) msgPB.Msgs = append(msgPB.Msgs, newmsg)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
return newmsg return newmsg
} }
*/
func (msgPB *FormatMsg) newOneofMessage(header string) *FormatMsg { func (msgPB *FormatMsg) newMessage(header string, comments string, msgType FormatMsg_Type) *FormatMsg {
newmsg := newDepth(msgPB, header) newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ONEOF newmsg.Type = msgType
msgPB.Msgs = append(msgPB.Msgs, newmsg) msgPB.Msgs = append(msgPB.Msgs, newmsg)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
return newmsg return newmsg
} }
func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg { /*
func (msgPB *FormatMsg) newEnumMessage(header string, comments string) *FormatMsg {
newmsg := newDepth(msgPB, header) newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ENUM newmsg.Type = FormatMsg_ENUM
msgPB.Msgs = append(msgPB.Msgs, newmsg) msgPB.Msgs = append(msgPB.Msgs, newmsg)
comments = strings.TrimSpace(comments)
newmsg.Notes = strings.Split(comments, "\n")
return newmsg return newmsg
} }
*/
// proto files can be defined as trees // proto files can be defined as trees
// func loadMsgDefinition(msg *StdMessage) { // func loadMsgDefinition(msg *StdMessage) {
@ -196,18 +214,27 @@ func (msg *FormatMsg) load() {
for allTheLines.Scan() { for allTheLines.Scan() {
line := allTheLines.Next() line := allTheLines.Next()
if strings.HasPrefix(line, "oneof ") { if strings.HasPrefix(line, "oneof ") {
newmsg := msg.newOneofMessage(line) newmsg := msg.newMessage(line, "", FormatMsg_ONEOF)
if strings.Contains(line, "}") {
return
}
newmsg.load() newmsg.load()
continue continue
} }
if strings.HasPrefix(line, "enum ") { if strings.HasPrefix(line, "enum ") {
newmsg := msg.newEnumMessage(line) newmsg := msg.newMessage(line, "", FormatMsg_ENUM)
if strings.Contains(line, "}") {
return
}
newmsg.load() newmsg.load()
continue continue
} }
if strings.HasPrefix(line, "message ") { if strings.HasPrefix(line, "message ") {
// message inception. search for the architect. don't forget your totem // message inception. search for the architect. don't forget your totem
newmsg := msg.newStdMessage(line) newmsg := msg.newMessage(line, "", FormatMsg_MESSAGE)
if strings.Contains(line, "}") {
return
}
newmsg.load() newmsg.load()
continue continue
} }
@ -471,7 +498,8 @@ func formatMessage(curmsg *FormatMsg) []string {
if curmsg.Footer == "" { if curmsg.Footer == "" {
newmsg = append(newmsg, "// footer was empty") newmsg = append(newmsg, "// footer was empty")
} else { } else {
newmsg = append(newmsg, curmsg.Footer) // +" //footer") newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer")
newmsg = append(newmsg, newline)
} }
return newmsg return newmsg
} }