hit9 / bitproto

The bit level data interchange format for serializing data structures (long term maintenance).
https://bitproto.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
127 stars 16 forks source link

[Bug report] Parsing error when the message name is contained in the message fields #39

Closed g-berthiaume closed 3 years ago

g-berthiaume commented 3 years ago

I think the parser will fail if the message name is contained in the message field type.

Steps to reproduce Using the following schema:

proto mytest

enum payload_data_type_e: uint8 {
    PAYLOAD_DATA_TYPE_UNKNOWN = 1
    PAYLOAD_DATA_TYPE_DETECTOR = 2
}

message payload_data_t {
    payload_data_type_e type = 1 
}

When compiling

$ bitproto -O c .\mytest.bitproto 
error:  .\myschema.bitproto:L9  { => Some grammar error occurred during bitproto grammar parsing.

My guess is that this error is due to a kind of name collision in the lexer.

Yzw-Yogo commented 3 years ago

@g-berthiaume Hi ~ Yeah, there is a name collision mistake. type is a keyword like what the keyword typedef does in C. Example here

Use like: type Timestamp = int64;

it will fix:

proto mytest

enum payload_data_type_e: uint8 {
    PAYLOAD_DATA_TYPE_UNKNOWN = 1
    PAYLOAD_DATA_TYPE_DETECTOR = 2
}

message payload_data_t {
    payload_data_type_e data = 1 
}
hit9 commented 3 years ago

@g-berthiaume

hmm, yep. the word type is a reserved keyword, this breaks parsing, it can't be used as a message field's name.

But I think this word "type" is a very common word, so I decided to solve this.

A newer version of bitproto, v0.4.2 was just uploaded, which fixed this problem.

Now the following message parses well:

message Test {
    uint4 type = 1  // it's ok now
}

You can upgrade bitproto via pip install -U bitproto.

https://github.com/hit9/bitproto/releases/tag/v0.4.2

g-berthiaume commented 3 years ago

Interesting ! As I'm starting to work on a basic compiler, I can appreciate the complexity of those kinds of bugs. Thanks for your work!

On another note: For some reason, I'm having difficulty updating: Pip raise the following exception: FileNotFoundError: [Errno 2] No such file or directory: '../README.rst'

Is it possible that the package builder executes setup.py outside of the compiler/ directory? Maybe it's a problem with my machine ^^

hit9 commented 3 years ago

@g-berthiaume Thanks for reporting this bug.

pip install -U bitproto would work now.

Or you can download the binary directly from https://github.com/hit9/bitproto/releases/tag/v0.4.4