more attempts to work on the signal-server proto files
This commit is contained in:
parent
2269ac2c27
commit
81b4b453e7
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"iter"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
sync "sync"
|
||||
|
||||
|
@ -26,6 +27,20 @@ func protoReformat(filename string) error {
|
|||
}
|
||||
|
||||
var newfile string
|
||||
|
||||
/*
|
||||
_, junk := filepath.Split(filename)
|
||||
if junk != "SignalService.proto" {
|
||||
var allLinesIter iter.Seq[string]
|
||||
allLinesIter = makeLineIter(data)
|
||||
// gets the max vartype and varname
|
||||
for line := range allLinesIter {
|
||||
newfile += fmt.Sprintln(commentPreprocessor(line))
|
||||
}
|
||||
return saveFile(filename, newfile)
|
||||
}
|
||||
*/
|
||||
|
||||
var fmtmsg *FormatMsg
|
||||
fmtmsg = new(FormatMsg)
|
||||
|
||||
|
@ -162,13 +177,17 @@ func protoReformat(filename string) error {
|
|||
newfile += fmt.Sprintln(line)
|
||||
}
|
||||
|
||||
return saveFile(filename, newfile)
|
||||
}
|
||||
|
||||
func saveFile(filename string, data string) error {
|
||||
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
log.Info("file open error. permissions?", filename, err)
|
||||
return err
|
||||
}
|
||||
newfile = strings.TrimSpace(newfile)
|
||||
fmt.Fprintln(pf, newfile)
|
||||
data = strings.TrimSpace(data)
|
||||
fmt.Fprintln(pf, data)
|
||||
pf.Close()
|
||||
|
||||
// for i, s := range slices.Backward(pf.ToSort) {
|
||||
|
@ -185,7 +204,7 @@ func getInceptionMsg(fmtmsg *FormatMsg) {
|
|||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||
newmsg.Header = line
|
||||
getInceptionEnum(newmsg)
|
||||
fmtmsg.Enums = append(fmtmsg.Oneofs, newmsg)
|
||||
fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(line, "enum ") {
|
||||
|
@ -329,6 +348,24 @@ func formatMessage(curmsg *FormatMsg) []string {
|
|||
}
|
||||
*/
|
||||
|
||||
for _, msg := range curmsg.Enums {
|
||||
for _, newline := range formatEnum(msg) {
|
||||
newmsg = append(newmsg, newline)
|
||||
}
|
||||
}
|
||||
|
||||
for _, msg := range curmsg.Oneofs {
|
||||
for _, newline := range formatEnum(msg) {
|
||||
newmsg = append(newmsg, newline)
|
||||
}
|
||||
}
|
||||
|
||||
for _, msg := range curmsg.InceptionMsgs {
|
||||
for _, newline := range formatMessage(msg) {
|
||||
newmsg = append(newmsg, newline)
|
||||
}
|
||||
}
|
||||
|
||||
for _, line := range curmsg.Lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
|
@ -387,7 +424,36 @@ func (it *LinesScanner) Next() string {
|
|||
if it.index-1 == len(it.things) {
|
||||
fmt.Println("Next() error in LinesScanner", it.index)
|
||||
}
|
||||
return strings.TrimSpace(it.things[it.index-1])
|
||||
// out := commentPreprocessor(it.things[it.index-1])
|
||||
out := it.things[it.index-1]
|
||||
// return strings.TrimSpace(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// turns: "/* test */ reserved /* linkPreviews */ 4;"
|
||||
// into:
|
||||
func commentPreprocessor(line string) string {
|
||||
|
||||
// Match all /* comment */ blocks
|
||||
re := regexp.MustCompile(`/\*([^*]+)\*/`)
|
||||
matches := re.FindAllStringSubmatch(line, -1)
|
||||
|
||||
// Extract just the comment texts
|
||||
var comments []string
|
||||
for _, match := range matches {
|
||||
comments = append(comments, strings.TrimSpace(match[1]))
|
||||
}
|
||||
|
||||
// Remove the block comments from the original line
|
||||
line = re.ReplaceAllString(line, "")
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
// Append comments at the end with //
|
||||
for _, comment := range comments {
|
||||
line += " // " + comment
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue