Skip to content

How to parse dot's HTML-like strings? #423

Closed Answered by epage
NeverGivinUp asked this question in Q&A
Discussion options

You must be logged in to vote

unpeek(p_html_inner).recognize()

unpeek takes the old nom-like purely functional function signature and turns it into an impl Parser<I, O, E>.

You could also do

fn p_html_inner(input: &mut &str) -> PResult<()> {
    let bracket = '<'.parse_next(input)?;
    let mut balance = 1;
    while balance != 0 {
        let (before_bracket, bracket) =
            (take_until0(['<', '>']), any).parse_next(input)?;
        match bracket {
            '<' => balance += 1,
            '>' => balance -= 1,
            _ => unreachable!("angular bracket is not a bracket"),
        }
    }
    Ok(())
}

and then you could do p_html_inner.recognize() since we have impl Parser for FnMut... for that signature.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@epage
Comment options

Answer selected by NeverGivinUp
@epage
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants