track empty message {}

This commit is contained in:
Jeff Carr 2025-04-04 08:07:06 -05:00
parent 167acab354
commit 198b217cfa
2 changed files with 22 additions and 13 deletions

View File

@ -78,8 +78,8 @@ message FormatMsg {
string footer = 8; // the '}' line
Type type = 9; // yep. type. yep. that's what this is for
bool padAfter = 10;
bool isEmpty = 11; // true when things like: message blah {}
}
message Find {
string parent = 1; // `autogenpb:unique` File
string varType = 2; // `autogenpb:unique` MsgName

View File

@ -109,6 +109,7 @@ func doParse(lines []string) *FormatMsg {
if strings.HasPrefix(line, "oneof ") {
if strings.Contains(line, "}") {
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
newmsg.IsEmpty = true
newmsg.Footer = "} // blah"
comments = ""
continue
@ -123,6 +124,7 @@ func doParse(lines []string) *FormatMsg {
newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM)
comments = ""
if strings.Contains(line, "}") {
newmsg.IsEmpty = true
newmsg.Footer = "} // blah"
continue
}
@ -135,6 +137,7 @@ func doParse(lines []string) *FormatMsg {
newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE)
comments = ""
if strings.Contains(line, "}") {
newmsg.IsEmpty = true
newmsg.Footer = "} // blah"
continue
}
@ -196,6 +199,7 @@ func (msg *FormatMsg) load() {
if strings.HasPrefix(line, "oneof ") {
newmsg := msg.newMessage(line, "", FormatMsg_ONEOF)
if strings.Contains(line, "}") {
newmsg.IsEmpty = true
return
}
newmsg.load()
@ -204,6 +208,7 @@ func (msg *FormatMsg) load() {
if strings.HasPrefix(line, "enum ") {
newmsg := msg.newMessage(line, "", FormatMsg_ENUM)
if strings.Contains(line, "}") {
newmsg.IsEmpty = true
return
}
newmsg.load()
@ -213,6 +218,7 @@ func (msg *FormatMsg) load() {
// message inception. search for the architect. don't forget your totem
newmsg := msg.newMessage(line, "", FormatMsg_MESSAGE)
if strings.Contains(line, "}") {
newmsg.IsEmpty = true
return
}
newmsg.load()
@ -328,7 +334,7 @@ func formatEnum(curmsg *FormatMsg) []string {
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "enum footer"))
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "enum footer"))
if curmsg.PadAfter {
newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter"))
newmsg = append(newmsg, curmsg.formatPadAfter())
}
return newmsg
@ -348,7 +354,7 @@ func formatOneof(curmsg *FormatMsg) []string {
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "oneof footer"))
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "oneof footer"))
if curmsg.PadAfter {
newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter"))
newmsg = append(newmsg, curmsg.formatPadAfter())
}
return newmsg
@ -422,6 +428,13 @@ func (msg *FormatMsg) formatFooter(line string, dbg string) string {
return msg.formatLineBase(line, "footer")
}
func (msg *FormatMsg) formatPadAfter() string {
if argv.Debug {
return msg.formatLineBase("", "pad after")
}
return ""
}
func (msg *FormatMsg) formatHeader(line string, dbg string) string {
if line == "" {
if msg.Depth != 0 {
@ -517,6 +530,11 @@ func trimLines(lines []string) []string {
func formatMessage(curmsg *FormatMsg) []string {
var newmsg []string
if curmsg.IsEmpty {
newmsg = append(newmsg, curmsg.formatLineBase("// isEmpty", "IsEmpty"))
return newmsg
}
// add the notes & comments before the header
notes := trimLines(curmsg.Notes)
if len(notes) == 0 {
@ -592,18 +610,9 @@ func formatMessage(curmsg *FormatMsg) []string {
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "footer"))
if curmsg.PadAfter {
newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter"))
newmsg = append(newmsg, curmsg.formatPadAfter())
}
/*
if curmsg.Footer == "" {
newmsg = append(newmsg, "// footer was empty")
} else {
// newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer")
// newmsg = append(newmsg, newline)
newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "msg depth"))
}
*/
return newmsg
}