You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell, some nom parsers (like re_find!) aren't generic enough, and must accept &str input. This means you can't pass them a LocatedSpan.
It would be nice if there were a function that accepted one of those parsers and "lifted" it into a LocatedSpan -> LocatedSpan parser.
Here's as far as I got trying to implement this function:
typeSpan<'a> = LocatedSpan<&'a str>;fn wrap<'input,T>(parser:implFn(&'input str) -> IResult<&'input str,T>,) -> implFn(Span<'input>) -> IResult<Span<'input>,T>{
|input:Span<'input>| {let(rest, pos) = position(input)?;// In the following line, how do we map the error?let(rest, res) = parser(rest.fragment()).map_err(|e| e)?;let rest = unsafe{// How should the offset and line be updated here?Span::new_from_raw_offset(pos.location_offset(), pos.location_line(), rest,())};Ok((rest, res))}
The end result is that this function could be used like so:
fnsome_parser(input:Span) -> IResult<Span,Whatever>{let re = |input:&str| re_find!(input,"<some regex here>");wrap(re)(input)}
The text was updated successfully, but these errors were encountered:
As far as I can tell, some nom parsers (like
re_find!
) aren't generic enough, and must accept&str
input. This means you can't pass them aLocatedSpan
.It would be nice if there were a function that accepted one of those parsers and "lifted" it into a LocatedSpan -> LocatedSpan parser.
Here's as far as I got trying to implement this function:
The end result is that this function could be used like so:
The text was updated successfully, but these errors were encountered: