embedded comment parse fail
test.proto
syntax = "proto3";
package test;
import "google/protobuf/descriptor.proto";
message FooOption {
optional bool from = 1;
optional bool to = 2;
}
extend google.protobuf.FieldOptions {
optional FooOption foo_option = 1;
}
message Foo {
message /* ddd
*/
InnerFoo {
optional // aaa
uint64 /* bbb
*/value = 1 // ccc
[(foo_option) // 123
= {from: true, // kkkkk
to: true}
// 123123
];
}
}
main.go
package main
import (
"fmt"
"github.com/emicklei/proto"
"os"
)
func main() {
reader, _ := os.Open("test.proto")
defer reader.Close()
parser := proto.NewParser(reader)
definition, err := parser.Parse()
if err != nil {
fmt.Println(err)
}
proto.Walk(definition,
proto.WithService(handleService),
proto.WithMessage(handleMessage))
}
func handleService(s *proto.Service) {
fmt.Println(s.Name)
}
func handleMessage(m *proto.Message) {
fmt.Println(m.Name)
}
output
<input>:16:12: found "/* ddd\n\n */" but expected [message identifier]
FooOption
google.protobuf.FieldOptions
thank for reporting this issue. It got from my attention radar. Will have a look at it soon
i am closing this as the issue addresses a very uncommon case. Handling this would complicate the package even more.
@emicklei
I ran into this as well, and I am sad to see this resolution. This parser should handle proto files as intended, not disregarding edge cases as being unlikely.
@emicklei
I ran into this as well, and I am sad to see this resolution. This parser should handle proto files as intended, not disregarding edge cases as being unlikely.
At the time of reporting this issue, I found that it was a usecase that very synthesized, almost with the purpose of finding a problem with the parser (like fuzzing). Next it wasn't given any attention for over a year, so I did not felt it was urgent enough to spent much time on it.
So, maybe if you @zack-littke-smith can provide me with an example to replicates your problem, we could work on a solution for that first.
I discovered this via usage of this parser in a downstream library - it is not yet clear to me if the fault is with this parser or that library. Copying my example from the issue I filed with them:
message Example {
optional /* i'm a comment */ bool field = 1;
}
Seems to not be parsed properly, and seems like a reasonable place for a comment. Though again, I am not sure if this parsing library is the one at fault here.
see https://github.com/emicklei/proto/pull/142 that parses this:
message Example {
/* i'm */ optional /* a comment */ bool /* too */ field /* hard */ = /* to */ 1 /* read */;
}
Closed by https://github.com/emicklei/proto/pull/142