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

Sketch: Bytestring diagnostics preservation #143

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Jul 27, 2023

This is a quick hack to show what, based on #142, preservation of diagnostic notation style of strings could look like.

This preserves just the encoding style, i.e. whether it's hex or base64 encoded (with some roughness around ASCII encoding not being preserved right). It does not preserve how the diagnostic notation strings is composed of multiple chunks (all of which could have their own encoding), or comments inside the (eg. hex) string. The latter would be tempting to add, the former I don't see an urgent need for.

It already shows how I think it would make sense to run those diagnostic-representation things: The encoder would have a preference, and if the item doesn't state how it is to be expressed, that encoder style triggers. But if the item has a style choice, that is followed. Methods could be provided to clear the encoding style, or to apply one (maybe in a callback from a walker).

This is a sketch for two reasons:

  • If done properly, Encoding would be hoisted out of its current module and extended to have an explicit value for ASCII, and possibly extension to the rarer ones.
  • It is based on the current Privatize members #142, which is on its own a preview. Once that is complete, this PR will need more than a simple rebase.

This PR primarily serves to illustrate the road that can be taken after #142, and as a storage point for how the information can be passed around in the parser (took me a bit because I haven't used nom or similar before).

No accessors or mutators are specified because the tests didn't need
any.

The .with_bitwidth() method does not perform the plausibility checks it
could because it is not clear whether those should be invariants, or
whether parsing items like 70000_0 should be allowed.
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.

1 participant