yoheimuta / go-protoparser

Yet another Go package which parses a Protocol Buffer file (proto2+proto3)
MIT License
166 stars 20 forks source link

Custom Option Type map fails to parse #61

Closed hfjn closed 2 years ago

hfjn commented 2 years ago

Hi!

Awesome application, thanks for building this. I hit a minor issue today:

We have enums defined which have custom options pointing to another message for documentation purposes:

e.g. something like this


  REQUEST = 1 [(event_additional_data) = {field_number: 101}];

This fails during parsing with:

failed to parse, err found "\"{\"(Token=14, Pos=some.proto:39:54)" but expected [enumValueOption] at /home/hfjn/go/pkg/mod/github.com/yoheimuta/go-protoparser/v4@v4.4.0/parser/enum.go:280:found "{" but expected [;]

After checking the code I assume the enum type currently only supports String types?

Thanks!

yoheimuta commented 2 years ago

@hfjn That's nearly right! This parser conforms to the spec like enumValueOption = optionName "=" constant.

So that, the part around "{field_number: 101}" should be fullIdent | ( [ "-" | "+" ] intLit ) | ( [ "-" | "+" ] floatLit ) | strLit | boolLit.

yoheimuta commented 2 years ago

To sum up, you can fix a line like below.

- REQUEST = 1 [(event_additional_data) = {field_number: 101}];
+ REQUEST = 1 [(event_additional_data) = "{field_number: 101}"];

[memo] This parser extends a rule regarding a field option beyond the spec to parse a grpc-gateway_a_bit_of_everything.proto.