-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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.
/// Matches a format without consuming the input | ||
WithInput(Box<Format>), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
🤔
There was a problem hiding this comment.
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>), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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! 🤔
Not sure about the names here! But extracting |
Yeah not sold on this, thought I’d post in case it was thought provoking! :) |
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.