works again using an interface
This commit is contained in:
parent
5876518571
commit
ebf856a579
129
protoReformat.go
129
protoReformat.go
|
@ -18,11 +18,26 @@ import (
|
||||||
|
|
||||||
var allTheLines *LinesScanner
|
var allTheLines *LinesScanner
|
||||||
|
|
||||||
type Messages interface {
|
type EnumMessage struct {
|
||||||
format() []string
|
msgPB *FormatMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
var allMessages []Messages
|
type StdMessage struct {
|
||||||
|
msgPB *FormatMsg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *EnumMessage) name() string {
|
||||||
|
return "fuckit enum"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *StdMessage) name() string {
|
||||||
|
return "fuckit std"
|
||||||
|
}
|
||||||
|
|
||||||
|
type Messages interface {
|
||||||
|
format() []string
|
||||||
|
name() string
|
||||||
|
}
|
||||||
|
|
||||||
func protoReformat(filename string) error {
|
func protoReformat(filename string) error {
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
|
@ -83,46 +98,41 @@ func protoReformat(filename string) error {
|
||||||
}
|
}
|
||||||
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
||||||
}
|
}
|
||||||
|
fmtmsg.MaxVarname = bigName
|
||||||
|
fmtmsg.MaxVartype = bigType
|
||||||
|
|
||||||
// write out the messages
|
// write out the messages
|
||||||
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newStdMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = bigName
|
loadMsgDefinition(newmsg)
|
||||||
newmsg.MaxVartype = bigType
|
for _, newline := range newmsg.format() {
|
||||||
newmsg.Header = line
|
|
||||||
loadEnumDefinition(newmsg)
|
|
||||||
allMessages = append(allMessages, newmsg)
|
|
||||||
for _, newline := range formatMessage(newmsg) {
|
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newEnumMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = bigName
|
|
||||||
newmsg.MaxVartype = bigType
|
|
||||||
newmsg.Header = line
|
|
||||||
loadEnumDefinition(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
for _, newline := range formatEnum(newmsg) {
|
for _, newline := range newmsg.format() {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "message ") {
|
if strings.HasPrefix(line, "message ") {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newStdMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = bigName
|
|
||||||
newmsg.MaxVartype = bigType
|
|
||||||
newmsg.Header = line
|
|
||||||
|
|
||||||
loadMsgDefinition(newmsg)
|
log.Info("got to message", line)
|
||||||
for _, newline := range formatMessage(newmsg) {
|
for i, msg := range loadMsgDefinition(newmsg) {
|
||||||
|
log.Info("got in", i, msg.name())
|
||||||
|
for _, newline := range msg.format() {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
if len(parts) > 3 {
|
if len(parts) > 3 {
|
||||||
|
@ -159,45 +169,68 @@ func saveFile(filename string, data string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMsgDefinition(fmtmsg *FormatMsg) {
|
func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
|
||||||
|
newmsg := new(FormatMsg)
|
||||||
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
|
newmsg.Header = header
|
||||||
|
|
||||||
|
newstd := new(StdMessage)
|
||||||
|
newstd.msgPB = newmsg
|
||||||
|
|
||||||
|
return newstd
|
||||||
|
}
|
||||||
|
|
||||||
|
func newEnumMessage(fmtmsg *FormatMsg, header string) *EnumMessage {
|
||||||
|
newmsg := new(FormatMsg)
|
||||||
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
|
newmsg.Header = header
|
||||||
|
|
||||||
|
newstd := new(EnumMessage)
|
||||||
|
newstd.msgPB = newmsg
|
||||||
|
|
||||||
|
return newstd
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadMsgDefinition(msg *StdMessage) []Messages {
|
||||||
|
var allMessages []Messages
|
||||||
|
allMessages = append(allMessages, msg)
|
||||||
|
|
||||||
|
fmtmsg := msg.msgPB
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newStdMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
allMessages = append(allMessages, newmsg)
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
// fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
||||||
newmsg.Header = line
|
|
||||||
loadEnumDefinition(newmsg)
|
|
||||||
fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newEnumMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
|
||||||
newmsg.Header = line
|
|
||||||
loadEnumDefinition(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
allMessages = append(allMessages, newmsg)
|
||||||
|
// fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
||||||
// log.Info("got here:", line)
|
// log.Info("got here:", line)
|
||||||
// os.Exit(-1)
|
// os.Exit(-1)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "message ") {
|
if strings.HasPrefix(line, "message ") {
|
||||||
// message inception. search for the architect. don't forget your totem
|
// message inception. search for the architect. don't forget your totem
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newStdMessage(fmtmsg, line)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newAll := loadMsgDefinition(newmsg)
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
allMessages = append(allMessages, newAll...)
|
||||||
newmsg.Header = line
|
// fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
||||||
loadMsgDefinition(newmsg)
|
|
||||||
fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "}") {
|
if strings.HasPrefix(line, "}") {
|
||||||
fmtmsg.Footer = line
|
fmtmsg.Footer = line
|
||||||
return
|
return allMessages
|
||||||
}
|
}
|
||||||
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return allMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns vartype, varname, id, end
|
// returns vartype, varname, id, end
|
||||||
|
@ -244,15 +277,19 @@ func makeLineIter(data []byte) iter.Seq[string] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadEnumDefinition(curmsg *FormatMsg) {
|
func loadEnumDefinition(newMsg *EnumMessage) *EnumMessage {
|
||||||
|
curmsg := newMsg.msgPB
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "}") {
|
if strings.HasPrefix(line, "}") {
|
||||||
curmsg.Footer = line
|
curmsg.Footer = line
|
||||||
return
|
newMsg.msgPB = curmsg
|
||||||
|
return newMsg
|
||||||
}
|
}
|
||||||
curmsg.Lines = append(curmsg.Lines, line)
|
curmsg.Lines = append(curmsg.Lines, line)
|
||||||
}
|
}
|
||||||
|
newMsg.msgPB = curmsg
|
||||||
|
return newMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the max length of varname and vartype
|
// find the max length of varname and vartype
|
||||||
|
@ -278,6 +315,10 @@ func (curmsg *FormatMsg) format() []string {
|
||||||
return formatEnum(curmsg)
|
return formatEnum(curmsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (curmsg *EnumMessage) format() []string {
|
||||||
|
return formatEnum(curmsg.msgPB)
|
||||||
|
}
|
||||||
|
|
||||||
func formatEnum(curmsg *FormatMsg) []string {
|
func formatEnum(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
||||||
|
@ -291,6 +332,10 @@ func formatEnum(curmsg *FormatMsg) []string {
|
||||||
return newmsg
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (curmsg *StdMessage) format() []string {
|
||||||
|
return formatMessage(curmsg.msgPB)
|
||||||
|
}
|
||||||
|
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue