Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch when using sep_by #59

Closed
ghost opened this issue Feb 6, 2016 · 2 comments
Closed

Type mismatch when using sep_by #59

ghost opened this issue Feb 6, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 6, 2016

Not sure if this is a bug, but it seems like it should work. This code fails to compile:

extern crate combine;
use combine::{digit, letter, sep_by, token, Parser, ParserExt};

fn main() {
    let p = sep_by::<Vec<_>, _, _>(digit(), token(','));
    let result = letter().or(p).parse("1,2,3");
}

With this error:

type mismatch resolving `<&str as combine::primitives::Stream>::Item == collections::vec::Vec<char>`:
 expected char,
    found struct `collections::vec::Vec` [E0271]
src/main.rs:6     let result = letter().or(p).parse("1,2,3");

However, this works just fine:

extern crate combine;
use combine::{digit, letter, token, Parser, ParserExt};

fn main() {
    let result = letter().or(digit()).parse("1,2,3");
}
@Marwes
Copy link
Owner

Marwes commented Feb 6, 2016

In this case the error message is a bit confusing but the issue is that letter() outputs a char while sep_by outputs a Vec and or requires that both parsers outputs the same type. I am not sure what you want to output in this case but this thread about an expression parser might help as well #54

@ghost
Copy link
Author

ghost commented Feb 9, 2016

Thanks for the reply. Ultimately, what I'm trying to do is parse a string consisting of letters with optional arguments lists, like this: ABA(1, 2)C(3)DE(4, 5, 6)C. Reading over the thread you linked, it looks like I'll want to make an enum to represent both options. Thanks!

@ghost ghost closed this as completed Feb 9, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant