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

Allow different formats at the same ref position #322

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

brendanzab
Copy link
Member

@brendanzab brendanzab commented Mar 29, 2022

This allows multiple linked formats to occupy the same position in the binary file.

Currently this just renders the different formats as a list corresponding to each position in the CLI. In the future I'd want to explore a different way of displaying these - perhaps something like pos : Repr format = ... or pos : format = ... (if we add format -> repr coercions) - but this would require glued evaluation of top-level items to avoid swamping users with massive format descriptions.

let parsed_refs = refs.entry(pos).or_insert(Vec::with_capacity(1));

if (parsed_refs.iter())
.find(|r| self.conversion_context().is_equal(&r.format, &format))
Copy link
Member Author

@brendanzab brendanzab Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to make this more efficient. This would be easier if we could somehow assign a unique id to formats at compile time. Either that or have separate position stores for each format we plan to parse (this is is a bit like how Kaitai compiles format parsers, IIUC). This is complicated due to:

  • runtime data dependencies in format descriptions
  • the fact that formats can be constructed at runtime (I think Remove Type-in-Type #316 might resolve this)

Copy link
Member Author

@brendanzab brendanzab Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm curious if Kaitai allows instances to be parametrised by values 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like no, Kaitai does not allow instances to have parameters, as far as I can see. Nor can they handle mutual recursion of the font tables (they seem to skip the tables where this comes up, like htmx?).

Copy link
Contributor

@mikeday mikeday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@brendanzab brendanzab merged commit 707ecec into yeslogic:main Mar 29, 2022
@brendanzab brendanzab deleted the formats/ref-parsing branch March 29, 2022 05:59
@brendanzab brendanzab mentioned this pull request Mar 29, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants