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

"unable to find enum member" when using binary notation #150

Closed
bersbersbers opened this issue Nov 8, 2022 · 2 comments · Fixed by #166
Closed

"unable to find enum member" when using binary notation #150

bersbersbers opened this issue Nov 8, 2022 · 2 comments · Fixed by #166
Labels

Comments

@bersbersbers
Copy link

This throws an error:

meta:
  id: foo
seq:
  - id: first_bit
    type: b1
    enum: my_enum
  - id: other_bits
    type:
      switch-on: first_bit
      cases:
        my_enum::x: b7
        my_enum::y: b15
enums:
  my_enum:
    0b0: x
    0b1: y

This works:

meta:
  id: foo
seq:
  - id: first_bit
    type: b1
    enum: my_enum
  - id: other_bits
    type:
      switch-on: first_bit
      cases:
        my_enum::x: b7
        my_enum::y: b15
enums:
  my_enum:
    0: x
    1: y
@generalmimon
Copy link
Member

generalmimon commented Nov 8, 2022

@bersbersbers Thanks for reporting. This is a Web IDE-specific issue, due to using a crappy YAML parsing library https://github.com/jeremyfa/yaml.js - see https://gitter.im/kaitai_struct/Lobby?at=62e7c3a9cf6cfd27af5f9523.

The YAML parser apparently interprets this:

enums:
  my_enum:
    0b0: x
    0b1: y

as this:

enums:
  my_enum:
    0: x
    0: y

and since duplicate keys cannot be preserved in a YAML map, https://github.com/jeremyfa/yaml.js only keeps the first entry with key 0 (while generating no warning) and we end up with:

enums:
  my_enum:
    0: x

And once this tree is passed to kaitai-struct-compiler running in the browser, it has no way of knowing that this isn't quite what was in the original .ksy source.

At least it's very good that kaitai-struct-compiler since 0.10 handles its part correctly and refuses to compile a .ksy spec that references non-existent enum members.


@bersbersbers So you can't use binary literals as enum keys in the Web IDE at the moment, but hex literals (probably the closest substitute for binary literals) should work just fine:

enums:
  my_enum:
    0x0: x
    0x1: y

@bersbersbers
Copy link
Author

Sounds good, thanks for the explanation. Good luck having this fixed ;)

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

Successfully merging a pull request may close this issue.

2 participants