nom icon indicating copy to clipboard operation
nom copied to clipboard

Make traits public

Open jayhale opened this issue 2 years ago • 1 comments

nom::traits is private. In order to implement generic parsers, it would be helpful to have access to the type defs.

Or there is another way that I don't know?

Prerequisites

Here are a few things you should provide to help me understand the issue:

  • Rust version : rustc 1.67.0 (fc594f156 2023-01-24)
  • nom version : version = "7.1.3"

Test case

Example test case: Offset and Slice are part of nom's private traits module.

// I want to implement a similar parser to `recognize` that sends back the consumed input and the results
pub fn recognize_children<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(
    mut parser: F,
  ) -> impl FnMut(I) -> IResult<I, (I, O), E>
  where
    F: Parser<I, O, E>,
  {
    move |input: I| {
      let i = input.clone();
      match parser.parse(i) {
        Ok((i, o)) => {
          let index = input.offset(&i);
          Ok((i, (input.slice(..index), o)))
        }
        Err(e) => Err(e),
      }
    }
  }

jayhale avatar Feb 23 '23 01:02 jayhale

all the traits are exported at the root level: https://github.com/rust-bakery/nom/blob/main/src/lib.rs#L440

Geal avatar Mar 14 '23 20:03 Geal