summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-29 21:10:22 -0500
committerJeff Carr <[email protected]>2025-03-29 21:10:22 -0500
commit12b8c5603b682e4e4572c3412078c3319e2b4fe4 (patch)
treeaf04ecd5143a4972c09ad8c9a2e2bf84594638b0 /protoReformat.go
parent3b43eea6a39f3b64459ff6f82b28adafbaf26e8d (diff)
stuff
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go70
1 files changed, 49 insertions, 21 deletions
diff --git a/protoReformat.go b/protoReformat.go
index 1f04680..f6fc96b 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -91,34 +91,39 @@ func doParse(lines []string) *FormatMsg {
line := allTheLines.NextRaw()
if strings.HasPrefix(line, "oneof ") {
- newmsg := basemsg.newOneofMessage(line)
- comments = strings.TrimSpace(comments)
- newmsg.Notes = strings.Split(comments, "\n")
+ newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
comments = ""
- newmsg.load()
inMessage = true
+ if strings.Contains(line, "}") {
+ newmsg.Footer = "} // blah"
+ continue
+ }
+ newmsg.load()
continue
}
if strings.HasPrefix(line, "enum ") {
- newmsg := basemsg.newEnumMessage(line)
- comments = strings.TrimSpace(comments)
- newmsg.Notes = strings.Split(comments, "\n")
+ newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM)
comments = ""
- newmsg.load()
inMessage = true
+ if strings.Contains(line, "}") {
+ newmsg.Footer = "} // blah"
+ continue
+ }
+ newmsg.load()
continue
}
if strings.HasPrefix(line, "message ") {
log.Info("got to message", line)
-
- newmsg := basemsg.newStdMessage(line)
- comments = strings.TrimSpace(comments)
- newmsg.Notes = strings.Split(comments, "\n")
+ newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE)
comments = ""
- newmsg.load()
inMessage = true
+ if strings.Contains(line, "}") {
+ newmsg.Footer = "} // blah"
+ continue
+ }
+ newmsg.load()
continue
}
@@ -156,30 +161,43 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
return newmsg
}
+/*
// 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.Type = FormatMsg_MESSAGE
msgPB.Msgs = append(msgPB.Msgs, newmsg)
+ comments = strings.TrimSpace(comments)
+ newmsg.Notes = strings.Split(comments, "\n")
+
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.Type = FormatMsg_ONEOF
+ newmsg.Type = msgType
msgPB.Msgs = append(msgPB.Msgs, newmsg)
+ comments = strings.TrimSpace(comments)
+ newmsg.Notes = strings.Split(comments, "\n")
+
return newmsg
}
-func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg {
+/*
+func (msgPB *FormatMsg) newEnumMessage(header string, comments string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ENUM
msgPB.Msgs = append(msgPB.Msgs, newmsg)
+ comments = strings.TrimSpace(comments)
+ newmsg.Notes = strings.Split(comments, "\n")
+
return newmsg
}
+*/
// proto files can be defined as trees
// func loadMsgDefinition(msg *StdMessage) {
@@ -196,18 +214,27 @@ func (msg *FormatMsg) load() {
for allTheLines.Scan() {
line := allTheLines.Next()
if strings.HasPrefix(line, "oneof ") {
- newmsg := msg.newOneofMessage(line)
+ newmsg := msg.newMessage(line, "", FormatMsg_ONEOF)
+ if strings.Contains(line, "}") {
+ return
+ }
newmsg.load()
continue
}
if strings.HasPrefix(line, "enum ") {
- newmsg := msg.newEnumMessage(line)
+ newmsg := msg.newMessage(line, "", FormatMsg_ENUM)
+ if strings.Contains(line, "}") {
+ return
+ }
newmsg.load()
continue
}
if strings.HasPrefix(line, "message ") {
// 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()
continue
}
@@ -471,7 +498,8 @@ func formatMessage(curmsg *FormatMsg) []string {
if curmsg.Footer == "" {
newmsg = append(newmsg, "// footer was empty")
} else {
- newmsg = append(newmsg, curmsg.Footer) // +" //footer")
+ newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer")
+ newmsg = append(newmsg, newline)
}
return newmsg
}