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

Attempt to improve the input manipulation formats #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brendanzab
Copy link
Member

This extracts the notion of “not consuming the input” from the input manipulation formats, and adjusts the names of these formats to work more nicely together.

This was partly inspired by the paper “Interval Parsing Grammars for File Format Parsing” - except here we default to consuming bytes from the input as opposed to defaulting to parsing in-place.

This extracts the notion of “not consuming the input” from the input
manipulation formats, and adjusts the names of these formats to work
more nicely together.

This was partly inspired by the paper “Interval Parsing Grammars for
File Format Parsing” - except here we default to consuming bytes from
the input as opposed to parsing in-place.
Comment on lines +213 to +214
/// Matches a format without consuming the input
WithInput(Box<Format>),
Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite happy with the name of this format.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, so instead of say Intersection(A, B) there would be Cat(WithInput(A), B) 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe intersection would be better… not sure!

TakeBytes(Expr, Box<Format>),
/// Drops a given number of bytes from the start of the input, matching
/// the format against the remaining input
DropBytes(Expr, Box<Format>),
Copy link
Contributor

Choose a reason for hiding this comment

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

DropBytes seems unnecessarily parallel to TakeBytes, seems like it doesn't need the Format argument and could just skip N bytes? Whereas TakeBytes does require the Format argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, TakeBytes can be used to implement something like DropBytes?

def drop-bytes (n : Size) (f : Format) :=
  map _.data {
    skipped <- take-bytes n {},
    data <- f,
  };

Hadn’t thought of that! 🤔

@mikeday
Copy link
Contributor

mikeday commented May 1, 2023

Not sure about the names here! But extracting WithInput from WithRelativeOffset is thought provoking 🤔

@brendanzab
Copy link
Member Author

Yeah not sold on this, thought I’d post in case it was thought provoking! :)

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.

2 participants