Skip to content

Commit

Permalink
assigning comment to ast nodes (visitee). Issue emicklei#5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest Micklei authored and Ernest Micklei committed Apr 12, 2017
1 parent 7833ed3 commit 8d1c32d
Show file tree
Hide file tree
Showing 34 changed files with 832 additions and 469 deletions.
40 changes: 40 additions & 0 deletions cmd/protofmt/comments.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
begin
*/

// comment 1
// comment 2
syntax = "proto"; // inline 1

// comment 3
// comment 4
package test; // inline 2

// comment 5
// comment 6
message Test {
// comment 7
// comment 8
int64 i = 1; // inline 3
/*
cstyle
*/
}

// comment 9
enum Codes {
// comment 10
Unknown = 0; // inline 4
}

// comment 11
service API {
// comment 12
rpc doit (In) returns (Out); // inline 5
}

// comment 13
import "some.proto"; // inline 6

// comment 14
option (test.option) = 42; // inline 7
8 changes: 6 additions & 2 deletions cmd/protofmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import (
)

var (
overwrite = flag.Bool("w", false, "write result to (source) file instead of stdout")
oOverwrite = flag.Bool("w", false, "write result to (source) file instead of stdout")
oDebug = flag.Bool("d", false, "dump the AST for debugging")
)

// go run *.go unformatted.proto
Expand Down Expand Up @@ -64,7 +65,7 @@ func readFormatWrite(filename string) error {
if err := format(file, buf); err != nil {
return err
}
if *overwrite {
if *oOverwrite {
// write back to input
if err := ioutil.WriteFile(filename, buf.Bytes(), os.ModePerm); err != nil {
return err
Expand All @@ -84,6 +85,9 @@ func format(input io.Reader, output io.Writer) error {
if err != nil {
return err
}
// if *oDebug {
// spew.Dump(def)
// }
proto.NewFormatter(output, " ").Format(def) // 2 spaces
return nil
}
Loading

0 comments on commit 8d1c32d

Please sign in to comment.