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
About map_slice
in zero-copy
#243
Comments
Yep, definitely! It's the magic sauce that makes this enormous and soul-destroying refactor worth it 😁 I've yet to start on docs for the new stuff, but I'll be sure to put it front & centre!
This is probably a good idea. My reason for having
Yes, that is correct. You're right that it might be somewhat unintuitive at first, but this is already the behaviour of If you want to only see the slice of the input after the let hex_digits = one_of("0123456789ABCDEF").repeated().at_least(1).map_slice(|x| x);
let verbose_hex = just("0x").ignore_then(hex_digits);
// later
let only_hex_digits = verbose_hex; One thing you have made me consider is whether |
Hmm but that would change it to an emitting parser, not just zero-copy checking, no? |
It would, yes. Maybe both are needed. |
Some thoughts on |
You have a point that this could produce confusing behaviour. I've also been more broadly concerned about this with One alternative might be to have |
One idea is to only make it work when the result of the inner parser is |
This is now pretty much solved for the fact that collecting into a separate type is an explicit operation on the |
Yay the IterParser looks really cool! I think there might still be something to do / experiment with:
(writing plainly, as I'm not sure how to write it yet, I can try to expand on this later if needed) What do you think? |
I'm still not quite sure what's being asked, sorry. |
Extracted from #240 (comment)
Reply from @zesterer:
Continuing this question/discussion here to avoid 'polluting' that PR
With this info and after digging into the sources, I think I fully understand it now.. and I have to say: IT'S BRILLIANT!
The way you implemented the zero-copy system, with different modes, using check/emit parsing as needed for the different parsers is JUST PERFECT ❤️ ❤️
map_slice
(currently undocumented) seems to be one of the core combinator of the zero-copy system, I think it'll be important to emphasis it's importance! (and how it works)Idea: make it the default for sliceable
repeated
combinator (and others) ?Thinking a bit more, have you considered making it more 'visible' (increase the chance people will use it 'by default') by having it integrated into the
repeated
combinator? (and others that outputs 'lists' of X)The only consideration I see is that
repeated
can be used on inputs that are notSliceInput
.👉 Would it be possible(/a good idea?) to make a dedicated
repeated
implementation that is automatically usingmap_slice(|x| x)
when the input is aSliceInput
?Question: Handling of
ignore_then
?Can't manage to test it locally (can't find how to type the parser correctly..), so this is hypothesis only
I'm wondering about the handling of something like this:
According to the implementation:
chumsky/src/zero_copy/combinator.rs
Lines 33 to 39 in 1d5f110
The cursor is saved before consuming any input from the
verbose_hex
parser, so before parsing0x
, leading to a slice that include0x
, right?(and same issue with
then_ignore
at the end of the pattern, or a wholedelimited_by
, ..)If so, it kinda looks like a bug, do you think there's a another way to implement
map_slice
to work properly?(without putting the
map_slice
inverbose_hex
)The text was updated successfully, but these errors were encountered: