Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
g-berthiaume opened this issue Jul 30, 2021 · 4 comments

Comments

@g-berthiaume
Copy link

g-berthiaume commented Jul 30, 2021

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
Copy link

@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 hit9 closed this as completed in 5bf7f1d Jul 31, 2021
@hit9
Copy link
Owner

hit9 commented Jul 31, 2021

@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
Copy link
Author

g-berthiaume commented Aug 2, 2021

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
Copy link
Owner

hit9 commented Aug 3, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants