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

Cond/Map and Parse use #2

Closed
r4v3n6101 opened this issue Jun 21, 2020 · 2 comments
Closed

Cond/Map and Parse use #2

r4v3n6101 opened this issue Jun 21, 2020 · 2 comments

Comments

@r4v3n6101
Copy link
Contributor

I can't use Cond, Map and Parse at the same time. Such code won't be compiled:

#[nom(
    Cond = "a == 0"
    Parse = "take_till(|b| b == b'0')",
    Map = "bytes_to_cstring"
)]
cstring: Option<CString>
@chifflier
Copy link
Collaborator

Thanks for the report!

Note: a comma is missing after Cond (Cond = "a == 0",)

I get the following error:

message: A condition was given on field cstring, which is not an option type.
Hint: use Option<...>

It seems the parser does not get the type correctly. I'll investigate

@chifflier
Copy link
Collaborator

Fixed in f8cdf02

The tested parser (added in unit tests) is:

#[derive(Debug, Nom)]
pub struct MultipleAttributes1 {
    pub a: u32,
    #[nom(
        Cond = "a == 0",
        Parse = "take_till(|b| b == 0)",
        Map = "bytes_to_cstring"
    )]
    cstring: Option<CString>,
}

(note: take_till leaves a trailing \0 unparsed, I don't know if that was intended here)

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

2 participants