Skip to content

Cross-reference enums causing parsing errors #163

@alkorolyov

Description

@alkorolyov

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 enum from the message declaration, 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;'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions