track empty message {}
This commit is contained in:
parent
167acab354
commit
198b217cfa
|
@ -78,8 +78,8 @@ message FormatMsg {
|
||||||
string footer = 8; // the '}' line
|
string footer = 8; // the '}' line
|
||||||
Type type = 9; // yep. type. yep. that's what this is for
|
Type type = 9; // yep. type. yep. that's what this is for
|
||||||
bool padAfter = 10;
|
bool padAfter = 10;
|
||||||
|
bool isEmpty = 11; // true when things like: message blah {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message Find {
|
message Find {
|
||||||
string parent = 1; // `autogenpb:unique` File
|
string parent = 1; // `autogenpb:unique` File
|
||||||
string varType = 2; // `autogenpb:unique` MsgName
|
string varType = 2; // `autogenpb:unique` MsgName
|
||||||
|
|
|
@ -109,6 +109,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
|
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
|
||||||
|
newmsg.IsEmpty = true
|
||||||
newmsg.Footer = "} // blah"
|
newmsg.Footer = "} // blah"
|
||||||
comments = ""
|
comments = ""
|
||||||
continue
|
continue
|
||||||
|
@ -123,6 +124,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM)
|
newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM)
|
||||||
comments = ""
|
comments = ""
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg.IsEmpty = true
|
||||||
newmsg.Footer = "} // blah"
|
newmsg.Footer = "} // blah"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -135,6 +137,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE)
|
newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE)
|
||||||
comments = ""
|
comments = ""
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg.IsEmpty = true
|
||||||
newmsg.Footer = "} // blah"
|
newmsg.Footer = "} // blah"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -196,6 +199,7 @@ func (msg *FormatMsg) load() {
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := msg.newMessage(line, "", FormatMsg_ONEOF)
|
newmsg := msg.newMessage(line, "", FormatMsg_ONEOF)
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg.IsEmpty = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -204,6 +208,7 @@ func (msg *FormatMsg) load() {
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := msg.newMessage(line, "", FormatMsg_ENUM)
|
newmsg := msg.newMessage(line, "", FormatMsg_ENUM)
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg.IsEmpty = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -213,6 +218,7 @@ func (msg *FormatMsg) load() {
|
||||||
// message inception. search for the architect. don't forget your totem
|
// message inception. search for the architect. don't forget your totem
|
||||||
newmsg := msg.newMessage(line, "", FormatMsg_MESSAGE)
|
newmsg := msg.newMessage(line, "", FormatMsg_MESSAGE)
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg.IsEmpty = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -328,7 +334,7 @@ func formatEnum(curmsg *FormatMsg) []string {
|
||||||
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "enum footer"))
|
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "enum footer"))
|
||||||
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "enum footer"))
|
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "enum footer"))
|
||||||
if curmsg.PadAfter {
|
if curmsg.PadAfter {
|
||||||
newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter"))
|
newmsg = append(newmsg, curmsg.formatPadAfter())
|
||||||
}
|
}
|
||||||
|
|
||||||
return newmsg
|
return newmsg
|
||||||
|
@ -348,7 +354,7 @@ func formatOneof(curmsg *FormatMsg) []string {
|
||||||
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "oneof footer"))
|
// newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "oneof footer"))
|
||||||
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "oneof footer"))
|
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "oneof footer"))
|
||||||
if curmsg.PadAfter {
|
if curmsg.PadAfter {
|
||||||
newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter"))
|
newmsg = append(newmsg, curmsg.formatPadAfter())
|
||||||
}
|
}
|
||||||
|
|
||||||
return newmsg
|
return newmsg
|
||||||
|
@ -422,6 +428,13 @@ func (msg *FormatMsg) formatFooter(line string, dbg string) string {
|
||||||
return msg.formatLineBase(line, "footer")
|
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 {
|
func (msg *FormatMsg) formatHeader(line string, dbg string) string {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
if msg.Depth != 0 {
|
if msg.Depth != 0 {
|
||||||
|
@ -517,6 +530,11 @@ func trimLines(lines []string) []string {
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
|
|
||||||
|
if curmsg.IsEmpty {
|
||||||
|
newmsg = append(newmsg, curmsg.formatLineBase("// isEmpty", "IsEmpty"))
|
||||||
|
return newmsg
|
||||||
|
}
|
||||||
|
|
||||||
// add the notes & comments before the header
|
// add the notes & comments before the header
|
||||||
notes := trimLines(curmsg.Notes)
|
notes := trimLines(curmsg.Notes)
|
||||||
if len(notes) == 0 {
|
if len(notes) == 0 {
|
||||||
|
@ -592,18 +610,9 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
|
|
||||||
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "footer"))
|
newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "footer"))
|
||||||
if curmsg.PadAfter {
|
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
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue