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

Implement nom traits for slices other than byte slices #1482

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

Conversation

jyn514
Copy link

@jyn514 jyn514 commented Dec 24, 2021

This can be useful in cases where you already have an in-memory flat representation,
but want to use Nom to traverse it in a custom order. See adamchalmers/aoc21@a8fd28a for a real-world example (in that particular case, the in-memory representation is effectively generated by a lexer, then the tokens are parsed using nom).

This has a few opinionated decisions:

  • InputIter is only implemented when T: Copy. This could easily be relaxed to T: Clone,
    but that could be surprising if T is expensive to clone.
  • Compare is only implemented when T: Eq. This could be relaxed to PartialEq.

For some input streams, it doesn't make sense to ignore case when comparing.
Make `CompareIgnoreCase` a separate trait to avoid having to implement it anyway.
This can be useful in cases where you already have an in-memory flat representation,
but want to use Nom to traverse it in a custom order.

This has a few opinionated decisions:
- `InputIter` is only implemented when `T: Copy`. This could easily be relaxed to `T: Clone`,
  but that could be surprising if T is expensive to clone.
- `Compare` is only implemented when `T: Eq`. This could be relaxed to PartialEq.
@Geal Geal added this to the 8.0 milestone Mar 14, 2022
epage added a commit to epage/winnow that referenced this pull request Feb 1, 2023
This does not help with `Compare` (because of ignore case) and `FindSlice` (`memchr`).

Inspired by rust-bakery/nom#1482
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