proto-schema-parser icon indicating copy to clipboard operation
proto-schema-parser copied to clipboard

Parsing of comments and options

Open rnorth opened this issue 1 year ago • 3 comments

As mentioned here thanks for a really useful library - it's working well enough for me, but I've noticed some errors that (currently) don't affect my usage. I'd be happy to raise a PR but might not get around to it in the next few days.

Extending this example from the docs:

from proto_schema_parser.parser import Parser

text = """
syntax = "proto3";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

service SearchService {
    // Do the search
    rpc Search(SearchRequest) returns (SearchResponse) {
        option (google.api.http) = {
          // some comment about the option
          get: "/v1/search/{query}"
        };
    }
}
    
"""

result = Parser().parse(text)
print(result)

A few different problems emerge in the stdout output:

line 11:4 extraneous input '// Do the search' expecting {'option', 'rpc', ';', '}'}
line 14:10 mismatched input '// some comment about the option' expecting '}'
line 15:10 extraneous input 'get' expecting {<EOF>, LINE_COMMENT, BLOCK_COMMENT, 'import', 'package', 'option', 'enum', 'message', 'extend', 'service', ';'}
line 17:4 extraneous input '}' expecting {<EOF>, LINE_COMMENT, BLOCK_COMMENT, 'import', 'package', 'option', 'enum', 'message', 'extend', 'service', ';'}
File(syntax='proto3', file_elements=[Message(name='SearchRequest', elements=[Field(name='query', number=1, type='string', cardinality=None, options=[]), Field(name='page_number', number=2, type='int32', cardinality=None, options=[]), Field(name='result_per_page', number=3, type='int32', cardinality=None, options=[])]), Service(name='SearchService', elements=[Method(name='Search', input_type=MessageType(type='SearchRequest', stream=False), output_type=MessageType(type='SearchResponse', stream=False), elements=[Option(name='(google.api.http)', value='{')])]), Comment(text='// some comment about the option'), None])
  • Comments inside of a Service element don't seem to be expected
  • I think parameters of an option are not supported and/or the comment is interfering with the parsing

I hope this is useful, and if you'd prefer that I raise a PR please let me know! Thanks

rnorth avatar Mar 07 '24 13:03 rnorth

A PR would be greatly appreciated. I merged the previous comment support PRs optimistically, knowing they were incomplete. Any help you can provide from additional PRs would be much appreciated!

criccomini avatar Mar 08 '24 06:03 criccomini

@rnorth checking in: any chance you have time for a PR?

criccomini avatar Apr 18 '24 00:04 criccomini

@criccomini I'm very sorry - no, I haven't had time or focus to do it - apologies.

rnorth avatar May 19 '24 17:05 rnorth

Hi @criccomini,

This library is really useful, I was wondering if there's a chance to get a fix for this issue. Let me know if you can. Thanks!

dbottai avatar Aug 29 '24 08:08 dbottai

Fixed and published as 1.3.6

https://pypi.org/project/proto-schema-parser/1.3.6/

@rnorth @dbottai

criccomini avatar Aug 30 '24 21:08 criccomini

Fixed and published as 1.3.6

https://pypi.org/project/proto-schema-parser/1.3.6/

@rnorth @dbottai

Thank you @criccomini! You're the best.

dbottai avatar Sep 02 '24 08:09 dbottai