stuff
This commit is contained in:
parent
3b43eea6a3
commit
12b8c5603b
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue