DateTime<Utc>
objects from some input and iterating through all the submatches to find one specific one sounds wrong. Also having a bunch of (defaulted) mutable vars that I fill while iterating feels wrong.
Hi. Given only
ident = @{ (alpha | digit)+ }
, how come "Foo Bar" parses successfully to ident "Foo"? Why isn't this a failure since you didn't find only a single ident, but two of them? IE there's no rule that expects two idents, just one
This is why I made https://github.com/owo-lang/voile-rs/blob/572a1a8550bb228815558ba1c27c697059bf31c7/voile-util/src/pest_util.rs#L24-L43
field = { ident ~ "." ~ ident }
fn strict_parse<'a, P, F, R, T>(rule: R, input: &'a str, f: F)-> Result<T, Error<R>>
where
F: FnOnce(Pair<'a, R>) -> T,
P: Parser<R>,
R: Copy + Debug + Hash + Ord,
{
let rule = P::parse(rule, input)?.next().unwrap();
let end_pos = rule.as_span().end_pos();
if end_pos.pos() < input.len() {
let rest = &input[end_pos.pos()..];
let variant = ErrorVariant::CustomError {
message: format!("Does not consume the following code: '{}'", rest)
};
Err(Error::new_from_pos(variant, end_pos))
} else {
Ok(f(rule))
}
}
Nadri
I had forgotten about this gitter, thanks for reminding me