working again on fruit.proto
This commit is contained in:
parent
41bac3da7b
commit
4e3e05684b
116
protoReformat.go
116
protoReformat.go
|
@ -32,7 +32,6 @@ type StdMessage struct {
|
||||||
|
|
||||||
type Message interface {
|
type Message interface {
|
||||||
name() string
|
name() string
|
||||||
load()
|
|
||||||
addMsg(Message)
|
addMsg(Message)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -91,13 +90,14 @@ func doParse(lines []string) *FormatMsg {
|
||||||
line := allTheLines.NextRaw()
|
line := allTheLines.NextRaw()
|
||||||
|
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
|
|
||||||
comments = ""
|
|
||||||
inMessage = true
|
inMessage = true
|
||||||
|
comments = ""
|
||||||
if strings.Contains(line, "}") {
|
if strings.Contains(line, "}") {
|
||||||
|
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
|
||||||
newmsg.Footer = "} // blah"
|
newmsg.Footer = "} // blah"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF)
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -161,20 +161,6 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
|
||||||
return newmsg
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
|
|
||||||
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) newMessage(header string, comments string, msgType FormatMsg_Type) *FormatMsg {
|
func (msgPB *FormatMsg) newMessage(header string, comments string, msgType FormatMsg_Type) *FormatMsg {
|
||||||
newmsg := newDepth(msgPB, header)
|
newmsg := newDepth(msgPB, header)
|
||||||
newmsg.Type = msgType
|
newmsg.Type = msgType
|
||||||
|
@ -186,29 +172,6 @@ func (msgPB *FormatMsg) newMessage(header string, comments string, msgType Forma
|
||||||
return newmsg
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
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) {
|
|
||||||
// func (newMsg *EnumMessage) load() {
|
|
||||||
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
|
|
||||||
/*
|
|
||||||
func (msg *StdMessage) load() {
|
|
||||||
msg.msgPB.load()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (msg *FormatMsg) load() {
|
func (msg *FormatMsg) load() {
|
||||||
// fmtmsg := msg.msgPB
|
// fmtmsg := msg.msgPB
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
|
@ -409,28 +372,39 @@ func (all *FormatMsg) format() []string {
|
||||||
return formatMessage(all)
|
return formatMessage(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *FormatMsg) formatLineBase(line string, dbg string) string {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if argv.Debug {
|
||||||
|
return fmt.Sprintf("%s%s // %s depth=%d", msg.padBase(), line, dbg, msg.Depth)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s", msg.padBase(), line)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *FormatMsg) formatLine(line string, dbg string) string {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if argv.Debug {
|
||||||
|
return fmt.Sprintf("%s%s // %s depth=%d", msg.pad(), line, dbg, msg.Depth)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s", msg.padBase(), line)
|
||||||
|
}
|
||||||
|
|
||||||
|
func trimLines(lines []string) []string {
|
||||||
|
return strings.Split(strings.TrimSuffix(strings.Join(lines, "\n"), "\n"), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
|
|
||||||
// add the notes & comments before the header
|
// add the notes & comments before the header
|
||||||
// newmsg = append(newmsg, strings.TrimSpace(strings.Join(curmsg.Notes, "\n")))
|
// newmsg = append(newmsg, strings.TrimSpace(strings.Join(curmsg.Notes, "\n")))
|
||||||
for _, line := range strings.Split(strings.TrimSpace(strings.Join(curmsg.Notes, "\n")), "\n") {
|
for _, line := range trimLines(curmsg.Notes) {
|
||||||
if argv.Debug {
|
newmsg = append(newmsg, curmsg.formatLineBase(line, "notes"))
|
||||||
footer := fmt.Sprintf("%s%s // msg notes footer depth=%d", curmsg.padBase(), line, curmsg.Depth)
|
|
||||||
newmsg = append(newmsg, footer)
|
|
||||||
} else {
|
|
||||||
footer := fmt.Sprintf("%s%s", curmsg.padBase(), line)
|
|
||||||
newmsg = append(newmsg, footer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if curmsg.Header != "" {
|
if curmsg.Header != "" {
|
||||||
var line string
|
var line string
|
||||||
if argv.Debug {
|
line = curmsg.formatLineBase(curmsg.Header, "header")
|
||||||
line = fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
|
|
||||||
} else {
|
|
||||||
line = fmt.Sprintf("%s%s", curmsg.padBase(), curmsg.Header)
|
|
||||||
}
|
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
if len(parts) > 3 {
|
if len(parts) > 3 {
|
||||||
// hack to actually indent comments on the message line itself. you're welcome
|
// hack to actually indent comments on the message line itself. you're welcome
|
||||||
|
@ -445,17 +419,13 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
hmm := "%s %" + pad + "s %s"
|
hmm := "%s %" + pad + "s %s"
|
||||||
line = fmt.Sprintf(hmm, start, " ", end)
|
line = fmt.Sprintf(hmm, start, " ", end)
|
||||||
}
|
}
|
||||||
|
newmsg = append(newmsg, line) // " //header")
|
||||||
} else {
|
} else {
|
||||||
if argv.Debug {
|
newmsg = append(newmsg, line) // " //header")
|
||||||
line = fmt.Sprintf("%s // len(parts)=%d depth=%d", line, len(parts), curmsg.Depth)
|
|
||||||
} else {
|
|
||||||
// line = fmt.Sprintf("%s test", line)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
newmsg = append(newmsg, line) // " //header")
|
|
||||||
} else {
|
} else {
|
||||||
if curmsg.Depth != 0 {
|
if curmsg.Depth != 0 {
|
||||||
newmsg = append(newmsg, "// ERROR: header was blank") // +" //header")
|
newmsg = append(newmsg, "// ERROR: header was blank")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,13 +433,16 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case FormatMsg_ENUM:
|
case FormatMsg_ENUM:
|
||||||
for _, line := range formatEnum(msg) {
|
for _, line := range formatEnum(msg) {
|
||||||
// line = fmt.Sprintf("%s%s", curmsg.pad(), line)
|
newmsg = append(newmsg, line)
|
||||||
line = strings.TrimSpace(line)
|
/*
|
||||||
if argv.Debug {
|
// line = fmt.Sprintf("%s%s", curmsg.pad(), line)
|
||||||
line = fmt.Sprintf("%s%s // msg depth=%d", msg.padBase(), line, msg.Depth)
|
line = strings.TrimSpace(line)
|
||||||
} else {
|
if argv.Debug {
|
||||||
line = fmt.Sprintf("%s%s", msg.padBase(), line)
|
line = fmt.Sprintf("%s%s // msg depth=%d", msg.padBase(), line, msg.Depth)
|
||||||
}
|
} else {
|
||||||
|
line = fmt.Sprintf("%s%s", msg.padBase(), line)
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
case FormatMsg_MESSAGE:
|
case FormatMsg_MESSAGE:
|
||||||
for _, line := range msg.format() {
|
for _, line := range msg.format() {
|
||||||
|
@ -483,7 +456,8 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if line == "" {
|
if line == "" {
|
||||||
newmsg = append(newmsg, line)
|
// newmsg = append(newmsg, line)
|
||||||
|
newmsg = append(newmsg, curmsg.formatLine(line, "lines"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "//") {
|
if strings.HasPrefix(line, "//") {
|
||||||
|
@ -511,11 +485,13 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
newline = strings.TrimRight(newline, " ")
|
newline = strings.TrimRight(newline, " ")
|
||||||
newmsg = append(newmsg, newline)
|
newmsg = append(newmsg, newline)
|
||||||
}
|
}
|
||||||
|
|
||||||
if curmsg.Footer == "" {
|
if curmsg.Footer == "" {
|
||||||
newmsg = append(newmsg, "// footer was empty")
|
newmsg = append(newmsg, "// footer was empty")
|
||||||
} else {
|
} else {
|
||||||
newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer")
|
// newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer")
|
||||||
newmsg = append(newmsg, newline)
|
// newmsg = append(newmsg, newline)
|
||||||
|
newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "msg depth"))
|
||||||
}
|
}
|
||||||
return newmsg
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue