Read
. I would like to avoid reading the entire file into a string before parsing it, for a few reasons. IndexPositioner
is not very useful here – it would be very excellent to have SourcePositioner
implemented for u8
. Would you accept a PR to that effect?
Positioner<u8>
should be possible, then you can construct the stream with https://docs.rs/combine/4.0.0-beta.1/combine/stream/position/struct.Stream.html#method.with_positioner
impl Parser
, but since they're different opaque types, rustc doesn't like it at all
dispatch!
parser which does exactly this https://docs.rs/combine/4.0.0-beta.1/src/combine/parser/choice.rs.html#800-816
FnOpaque
impl Trait
and which are generic over Input
. my compile times have absolutely skyrocketed and i'm looking for a way to bring them down. i've isolated all of my parser logic into a separate crate, but that doesn't seem to help – the outer crate compile times are still brutal.
impl Trait
shouldn't harm compiletimes much on its own
R: Read
fn n_digits<Input>(min: usize, max: usize) -> impl Parser<Input, Output = i32>
where
Input: Stream<Token = char>,
// Necessary due to rust-lang/rust#24159
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
count_min_max(min, max, digit()).map(|s: String| {
s.parse::<i32>().unwrap()
})
}
s.parse
fails, but despite diving into a few codebases that use combine and trying many things, I'm not getting anywhere. Can anyone help me out?
from_str(count_min_max::<String, _, _>(min, max, digit()))
parse::<i32>
is acceptable
and_then
like from_str
does and substitute your own message https://github.com/Marwes/combine/blob/a358c88933bb58c4df0d9a0212b4a33d2b24be7b/src/parser/combinator.rs#L1165-L1169
I did stumble onto StreamErrorFor::<Input>::other
eventually yesterday, and ended up with
fn n_digits<Input>(min: usize, max: usize) -> impl Parser<Input, Output = i32>
where
Input: Stream<Token = char>,
// Necessary due to rust-lang/rust#24159
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
count_min_max(min, max, digit()).and_then(|s: String| {
s.parse().map_err(StreamErrorFor::<Input>::other)
})
}
Which was acceptable. I'll try out from_str
tonight though and compare the error messages that they generate, looks like they may arrive at different errors, though I'm not sure how they'll differ.
captures
I get some incredible error spam that's hard to sort through.