appnexus / pyrobuf

A Cython alternative to Google's Python Protobuf library
Other
555 stars 71 forks source link

Cross-reference enums causing parsing errors #163

Open alkorolyov opened 1 year ago

alkorolyov commented 1 year ago

Hi,

I noticed that using this type of enum causes an error, but it seems to work with the Google protobuf library. Although it should be fixable by simply removing the enumfrom the messagedeclaration, the authors of the original .proto deliberately used this declaration style. I would like to attempt to implement the patch myself if it is a straightforward fix.

@thirtythreeforty and @tburmeister, I've seen that you both have contributed significantly to this repository and likely have a better understanding of the underlying details. If you have some free time, could you please provide some guidance or a starting point for addressing this issue? Thank you in advance.

message EnumMsg {
  enum EnumType {
    ENUM_FIELD = 0;
  }
}

message Test {
  EnumMsg.EnumType field = 1;
}
Exception while parsing proto\test.proto
Traceback (most recent call last):
  File "C:/Users/ergot/PycharmProjects/pyrobuf/pyrobuf/__main__.py", line 10, in <module>
    main()
  File "C:/Users/ergot/PycharmProjects/pyrobuf/pyrobuf/__main__.py", line 6, in main
    compiler.compile()
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\compile.py", line 88, in compile
    self._compile_spec()
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\compile.py", line 121, in _compile_spec
    self._generate(source)
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\compile.py", line 133, in _generate
    msg_def = self.parser.parse_from_filename(filename, self.includes)
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\parse_proto.py", line 264, in parse_from_filename
    raise e
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\parse_proto.py", line 261, in parse_from_filename
    return cls(s).parse(fname=fname, includes=includes, disabled_tokens=disabled_tokens)
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\parse_proto.py", line 225, in parse
    imported['enums']
  File "C:\Users\ergot\PycharmProjects\pyrobuf\pyrobuf\parse_proto.py", line 376, in _parse_message
    token.token_type, token.line + 1, self.lines[token.line])
AssertionError: unexpected ENUM_FIELD token on line 10: '  EnumMsg.EnumType field = 1;'
tburmeister commented 1 year ago

Hi @alkorolyov,

I have stopped contributing to this project and don't really have the time to continue supporting it. I would consider Pyrobuf essentially dead, though you are free to fork and use it if you like.

-Taylor

alkorolyov commented 1 year ago

Hi @tburmeister !

Thank you for getting back to me. I was wondering if I could ask for your opinion on Cython in general. I really enjoyed using it when learning about Algorithms and Data Structures because of its native integration with Python (which I heavily use in chemoinformatics), the clean look of the code, and the speed-ups it provides. However, as I dive deeper into real-world problems, it seems that Cython has a smaller set of tools compared to more common languages like C++. Do you think it's worth investing in further learning of Cython, or would it be better to gain some competence in C++ (even though its syntax hurts my eyes :)? It would be great to have an opinion from a more experienced programmer on how often Cython is used in production code for real-life problems and what its general use case is.