yoheimuta / go-protoparser

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

Support `option (.foo.bar) = {...}` #63

Closed NotFounds closed 2 years ago

NotFounds commented 2 years ago

Hi, thanks for providing an awesome linter and library. I'm introducing the linter to my project. And it raises an exception that found "." but expected [TIDENT]. Use -v for more details.

It fails at parsing like the following statement.

option (.foo.bar) = {…}

It seems invalid, according to https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#option, but protobuf allows this syntax to change the name resolution algorithm. cf. https://github.com/protocolbuffers/protobuf/blob/b696347f80d324c624e65a0b7e3ea5dac7ec5a41/src/google/protobuf/compiler/parser_unittest.cc#L2126-L2141

Could you support this format?

NotFounds commented 2 years ago

Example

example1.proto

syntax = "proto3";
package foo.bar;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
  string name = 50000;
}

example2.proto

syntax = "proto3";
package test.foo.bar;

import "example1.proto";

message Msg {
  option (.foo.bar.name) = "name";
}

linter result

$ protolint lint .
found "." but expected [TIDENT]. Use -v for more details
$ protolint lint -v .
(...)
2022/01/31 22:18:48 [DEBUG] Text=[(], Token=[12], Pos=[example2.proto:8:10] called from option.go:153
2022/01/31 22:18:48 [DEBUG] Text=[.], Token=[21], Pos=[example2.proto:8:11] called from fullIdent.go:8
found "." but expected [TIDENT] at /home/runner/go/pkg/mod/github.com/yoheimuta/go-protoparser/v4@v4.4.0/internal/lexer/fullIdent.go:10
yoheimuta commented 2 years ago

@NotFounds Thank you for reaching out! The parser should support the syntax protobuf allows as much as possible. I'm looking into it.

yoheimuta commented 2 years ago

@NotFounds I've cut a release here: https://github.com/yoheimuta/go-protoparser/releases/tag/v4.5.1. Can you give it a try?

NotFounds commented 2 years ago

@yoheimuta Thank you for your fix and release! I tried to build the linter locally to use the released one and run it in my project. It works well :)

yoheimuta commented 2 years ago

Good to hear that!