winnow-rs / winnow

Making parsing a breeze
https://docs.rs/winnow
Other
572 stars 44 forks source link

Parse::parse should accept Partial after marking `complete` #389

Closed Dr-Emann closed 9 months ago

Dr-Emann commented 11 months ago

Please complete the following tasks

rust version

rustc 1.74.1 (a28077b28 2023-12-04)

winnow version

0.5.26

Minimal reproducible code

use winnow::prelude::*;
use winnow::Partial;

type Stream<'i> = Partial<&'i str>;

fn hi(input: &mut Stream<'_>) -> PResult<()> {
    "hi".void().parse_next(input)
}

fn main() {
    let mut input = Partial::new("hi");
    let _ = input.complete();

    let res = hi.parse(input);
    assert_eq!(res, Ok(()))
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

thread 'main' panicked at .../winnow-0.5.26/src/parser.rs:54:9:
partial streams need to handle `ErrMode::Incomplete`

stack backtrace:
   0: rust_begin_unwind
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
   2: winnow::parser::Parser::parse
             at .../winnow-0.5.26/src/parser.rs:54:9
   3: winnow_iss::main
             at ./src/main.rs:14:15
   4: core::ops::function::FnOnce::call_once
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/ops/function.rs:250:5

Expected Behaviour

Parser::parse should not assert when the partial stream is configured as complete

Additional Context

No response

epage commented 11 months ago

Could you expand on your use case?

Parser::parse was initially intended to be a top-level parse function, used in isolation. For example, it implicitly captures the offset from where parse started and it assumes that that is an absolute offset, allowing it to be used for line/column numbers.

epage commented 9 months ago

Without extra context, I'm closing this. If there is a reason for us to re-evaluate, let us know!