compiles and runs again
This commit is contained in:
parent
1b7d44ec42
commit
be94cbe320
|
@ -85,8 +85,7 @@ message Find {
|
||||||
bool needAll = 4; //
|
bool needAll = 4; //
|
||||||
}
|
}
|
||||||
|
|
||||||
message File {
|
message File { // `autogenpb:var:w io.Writer`
|
||||||
// `autogenpb:var:w io.Writer`
|
|
||||||
string Package = 1; // whatever the package name is at the top of the .go file
|
string Package = 1; // whatever the package name is at the top of the .go file
|
||||||
string filename = 2; // yellow.proto
|
string filename = 2; // yellow.proto
|
||||||
string pbfilename = 3; // yellow.pb.go
|
string pbfilename = 3; // yellow.pb.go
|
||||||
|
|
130
protoReformat.go
130
protoReformat.go
|
@ -20,10 +20,12 @@ var allTheLines *LinesScanner
|
||||||
|
|
||||||
type EnumMessage struct {
|
type EnumMessage struct {
|
||||||
msgPB *FormatMsg
|
msgPB *FormatMsg
|
||||||
|
all []Message
|
||||||
}
|
}
|
||||||
|
|
||||||
type StdMessage struct {
|
type StdMessage struct {
|
||||||
msgPB *FormatMsg
|
msgPB *FormatMsg
|
||||||
|
all []Message
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *EnumMessage) name() string {
|
func (msg *EnumMessage) name() string {
|
||||||
|
@ -31,12 +33,17 @@ func (msg *EnumMessage) name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *StdMessage) name() string {
|
func (msg *StdMessage) name() string {
|
||||||
|
if msg.msgPB != nil {
|
||||||
|
return msg.msgPB.Header
|
||||||
|
}
|
||||||
return "fuckit std"
|
return "fuckit std"
|
||||||
}
|
}
|
||||||
|
|
||||||
type Messages interface {
|
type Message interface {
|
||||||
format() []string
|
format() []string
|
||||||
name() string
|
name() string
|
||||||
|
load()
|
||||||
|
addMsg(Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func protoReformat(filename string) error {
|
func protoReformat(filename string) error {
|
||||||
|
@ -104,8 +111,8 @@ func protoReformat(filename string) error {
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := newStdMessage(fmtmsg, line)
|
newmsg := fmtmsg.newOneofMessage(line)
|
||||||
loadMsgDefinition(newmsg)
|
newmsg.load()
|
||||||
for _, newline := range newmsg.format() {
|
for _, newline := range newmsg.format() {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
@ -113,8 +120,9 @@ func protoReformat(filename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := newEnumMessage(fmtmsg, line)
|
newmsg := fmtmsg.newEnumMessage(line)
|
||||||
loadEnumDefinition(newmsg)
|
newmsg.load()
|
||||||
|
// loadEnumDefinition(newmsg)
|
||||||
for _, newline := range newmsg.format() {
|
for _, newline := range newmsg.format() {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
@ -122,28 +130,12 @@ func protoReformat(filename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "message ") {
|
if strings.HasPrefix(line, "message ") {
|
||||||
newmsg := newStdMessage(fmtmsg, line)
|
newmsg := fmtmsg.newStdMessage(line)
|
||||||
|
newmsg.load()
|
||||||
log.Info("got to message", line)
|
log.Info("got to message", line)
|
||||||
for i, msg := range loadMsgDefinition(newmsg) {
|
for _, newline := range newmsg.format() {
|
||||||
log.Info("got in", i, msg.name())
|
|
||||||
for _, newline := range msg.format() {
|
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/*
|
|
||||||
parts := strings.Fields(line)
|
|
||||||
if len(parts) > 3 {
|
|
||||||
// hack to actually indent comments on the message line itself. you're welcome
|
|
||||||
start := parts[0] + " " + parts[1] + " " + parts[2]
|
|
||||||
end := strings.Join(parts[3:], " ")
|
|
||||||
offset := int(bigName) + int(bigType) + 16 - len(start)
|
|
||||||
pad := fmt.Sprintf("%d", offset)
|
|
||||||
hmm := "%s %" + pad + "s %s"
|
|
||||||
line = fmt.Sprintf(hmm, start, " ", end)
|
|
||||||
}
|
|
||||||
newfile += fmt.Sprintln(line)
|
|
||||||
*/
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,11 +159,21 @@ func saveFile(filename string, data string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
|
func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := new(FormatMsg)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
newmsg.Header = header
|
newmsg.Header = header
|
||||||
|
newmsg.Depth = fmtmsg.Depth + 1
|
||||||
|
|
||||||
|
return newmsg
|
||||||
|
}
|
||||||
|
|
||||||
|
// func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
|
||||||
|
func (msgPB *FormatMsg) newStdMessage(header string) *StdMessage {
|
||||||
|
newmsg := newDepth(msgPB, header)
|
||||||
|
newmsg.Type = FormatMsg_MESSAGE
|
||||||
|
msgPB.Msgs = append(msgPB.Msgs, newmsg)
|
||||||
|
|
||||||
newstd := new(StdMessage)
|
newstd := new(StdMessage)
|
||||||
newstd.msgPB = newmsg
|
newstd.msgPB = newmsg
|
||||||
|
@ -179,11 +181,21 @@ func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
|
||||||
return newstd
|
return newstd
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEnumMessage(fmtmsg *FormatMsg, header string) *EnumMessage {
|
func (msgPB *FormatMsg) newOneofMessage(header string) *StdMessage {
|
||||||
newmsg := new(FormatMsg)
|
newmsg := newDepth(msgPB, header)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newmsg.Type = FormatMsg_ONEOF
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
msgPB.Msgs = append(msgPB.Msgs, newmsg)
|
||||||
newmsg.Header = header
|
|
||||||
|
newstd := new(StdMessage)
|
||||||
|
newstd.msgPB = newmsg
|
||||||
|
|
||||||
|
return newstd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msgPB *FormatMsg) newEnumMessage(header string) *EnumMessage {
|
||||||
|
newmsg := newDepth(msgPB, header)
|
||||||
|
newmsg.Type = FormatMsg_ENUM
|
||||||
|
msgPB.Msgs = append(msgPB.Msgs, newmsg)
|
||||||
|
|
||||||
newstd := new(EnumMessage)
|
newstd := new(EnumMessage)
|
||||||
newstd.msgPB = newmsg
|
newstd.msgPB = newmsg
|
||||||
|
@ -191,44 +203,44 @@ func newEnumMessage(fmtmsg *FormatMsg, header string) *EnumMessage {
|
||||||
return newstd
|
return newstd
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMsgDefinition(msg *StdMessage) []Messages {
|
// proto files can be defined as trees
|
||||||
var allMessages []Messages
|
// func loadMsgDefinition(msg *StdMessage) {
|
||||||
allMessages = append(allMessages, msg)
|
// func (newMsg *EnumMessage) load() {
|
||||||
|
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
|
||||||
fmtmsg := msg.msgPB
|
func (msg *StdMessage) load() {
|
||||||
|
// fmtmsg := msg.msgPB
|
||||||
|
curPB := 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 := newStdMessage(fmtmsg, line)
|
newmsg := msg.msgPB.newOneofMessage(line)
|
||||||
allMessages = append(allMessages, newmsg)
|
newmsg.load()
|
||||||
// fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
curPB = newmsg.msgPB
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := newEnumMessage(fmtmsg, line)
|
newmsg := msg.msgPB.newEnumMessage(line)
|
||||||
loadEnumDefinition(newmsg)
|
newmsg.load()
|
||||||
allMessages = append(allMessages, newmsg)
|
curPB = newmsg.msgPB
|
||||||
// fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
// loadEnumDefinition(newmsg)
|
||||||
// log.Info("got here:", line)
|
|
||||||
// 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 := newStdMessage(fmtmsg, line)
|
newmsg := msg.msgPB.newStdMessage(line)
|
||||||
newAll := loadMsgDefinition(newmsg)
|
newmsg.load()
|
||||||
allMessages = append(allMessages, newAll...)
|
curPB = newmsg.msgPB
|
||||||
// fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "}") {
|
if strings.HasPrefix(line, "}") {
|
||||||
fmtmsg.Footer = line
|
msg.msgPB.Footer = line
|
||||||
return allMessages
|
return
|
||||||
}
|
}
|
||||||
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
curPB.Notes = append(curPB.Notes, line)
|
||||||
|
// fmtmsg.Lines = append(fmtmsg.Lines, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
return allMessages
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns vartype, varname, id, end
|
// returns vartype, varname, id, end
|
||||||
|
@ -275,19 +287,17 @@ func makeLineIter(data []byte) iter.Seq[string] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadEnumDefinition(newMsg *EnumMessage) *EnumMessage {
|
// func loadEnumDefinition(newMsg *EnumMessage) *EnumMessage {
|
||||||
curmsg := newMsg.msgPB
|
func (newMsg *EnumMessage) load() {
|
||||||
|
curPB := 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
|
curPB.Footer = line
|
||||||
newMsg.msgPB = curmsg
|
return
|
||||||
return newMsg
|
|
||||||
}
|
}
|
||||||
curmsg.Lines = append(curmsg.Lines, line)
|
curPB.Lines = append(curPB.Lines, line)
|
||||||
}
|
}
|
||||||
newMsg.msgPB = curmsg
|
|
||||||
return newMsg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the max length of varname and vartype
|
// find the max length of varname and vartype
|
||||||
|
|
Loading…
Reference in New Issue