Skip to content

[Help] How can I implement this parser? #393

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

You must be logged in to vote

It'd help to know what problems you are having with it so we can have an idea of how to steer things. I'm goin to make some guesses

The first problem I'm noticing is your return type is impl Parser but you are trying to return PResult<Bank16View, E> because you have (input) at the end. If you remove that, you'll be returning a closure (FnMut) which, when the signature is correct, will match impl Parser and work.

take(4).try_map(std::str::from_utf8).verify(|s: &str| s.len() == 4)

The last verify should be redundant as take guarantees that only 4 tokens were consumed.

You mentioned the name should be alphanumeric which this doesn't check. You could do take_while(4, (b'a'..='z', b'A'..='Z'…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@DJDuque
Comment options

@epage
Comment options

@epage
Comment options

@DJDuque
Comment options

@epage
Comment options

Answer selected by DJDuque
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