Skip to content

Converting a small parser from 0.9 to 1alpha - missing chain method #496

Answered by zesterer
dovreshef asked this question in Q&A
Discussion options

You must be logged in to vote

Right, in that case you can just put the separated case first:

let byte = any().filter(char::is_ascii_hexdigit)
    .repeated()
    .exactly(2)
    .map_slice(|s| u8::from_str_radix(s, 16).unwrap());

let hex = byte
    .separated_by(just(':'))
    .at_least(2)
    .collect::<Vec<_>>()
    .or(byte
        .repeated()
        .at_least(1)
        .collect());

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@zesterer
Comment options

@Zij-IT
Comment options

@dovreshef
Comment options

@zesterer
Comment options

Answer selected by dovreshef
@dovreshef
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
3 participants