summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-28 08:19:59 -0500
committerJeff Carr <[email protected]>2025-03-28 08:19:59 -0500
commit11ccc557feda86273dc67779a1a2b45723ada3e4 (patch)
tree95f2262dc19acace1d0ab7cafa9cc8540ea20978 /protoReformat.go
parentdfe42d8d2358e1437b1b086bbc420f3ffef9b46e (diff)
closer to back to working again
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go70
1 files changed, 21 insertions, 49 deletions
diff --git a/protoReformat.go b/protoReformat.go
index 664e792..c2296b0 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -127,29 +127,16 @@ func protoReformat(filename string) error {
if strings.HasPrefix(line, "oneof ") {
newmsg := basemsg.newOneofMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
if strings.HasPrefix(line, "enum ") {
newmsg := basemsg.newEnumMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- // loadEnumDefinition(newmsg)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
@@ -158,14 +145,8 @@ func protoReformat(filename string) error {
log.Info("got to message", line)
newmsg := basemsg.newStdMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
@@ -209,37 +190,28 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
}
// func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
-func (msgPB *FormatMsg) newStdMessage(header string) *StdMessage {
+func (msgPB *FormatMsg) newStdMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_MESSAGE
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(StdMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
-func (msgPB *FormatMsg) newOneofMessage(header string) *StdMessage {
+func (msgPB *FormatMsg) newOneofMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ONEOF
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(StdMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
-func (msgPB *FormatMsg) newEnumMessage(header string) *EnumMessage {
+func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ENUM
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(EnumMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
// proto files can be defined as trees
@@ -247,36 +219,34 @@ func (msgPB *FormatMsg) newEnumMessage(header string) *EnumMessage {
// func (newMsg *EnumMessage) load() {
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
func (msg *StdMessage) load() {
+ msg.msgPB.load()
+}
+
+func (msg *FormatMsg) load() {
// fmtmsg := msg.msgPB
- curPB := msg.msgPB
for allTheLines.Scan() {
line := allTheLines.Next()
if strings.HasPrefix(line, "oneof ") {
- newmsg := msg.msgPB.newOneofMessage(line)
+ newmsg := msg.newOneofMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
continue
}
if strings.HasPrefix(line, "enum ") {
- newmsg := msg.msgPB.newEnumMessage(line)
+ newmsg := msg.newEnumMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
- // loadEnumDefinition(newmsg)
continue
}
if strings.HasPrefix(line, "message ") {
// message inception. search for the architect. don't forget your totem
- newmsg := msg.msgPB.newStdMessage(line)
+ newmsg := msg.newStdMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
continue
}
if strings.HasPrefix(line, "}") {
- msg.msgPB.Footer = line
+ msg.Footer = line
return
}
- curPB.Lines = append(curPB.Lines, line)
- // fmtmsg.Lines = append(fmtmsg.Lines, line)
+ msg.Lines = append(msg.Lines, line)
}
return
@@ -425,7 +395,9 @@ func formatMessage(curmsg *FormatMsg) []string {
}
newmsg = append(newmsg, line) // " //header")
} else {
- newmsg = append(newmsg, "// ERROR: header was blank") // +" //header")
+ if curmsg.Depth != 0 {
+ newmsg = append(newmsg, "// ERROR: header was blank") // +" //header")
+ }
}
// find the max length of varname and vartype