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

Implement more error explanations #405

Merged
merged 1 commit into from
Dec 27, 2024
Merged

Conversation

lu-zero
Copy link

@lu-zero lu-zero commented Dec 27, 2024

No description provided.

Copy link
Owner

@pacak pacak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, pretty much, but I think the check can be simplified/corrected...

@@ -127,6 +130,25 @@ impl<'a> ExplainUnparsed<'a> {
}
None
}
fn is_redundant(&self, parsed: &[Name], unparsed: Name) -> Option<Error> {
let unparsed_info = self.all_names.get(&unparsed)?;
if unparsed_info.in_many {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check makes sense. If parser is annotated with many in any way - it can be accepted several times so this diagnostic is no longer applies.

if unparsed_info.in_many {
return None;
}
for p in parsed {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the rest can simply be parsed.contains(&unparsed) of some sort - "if name can be parsed only once (first condition) and we already parsed it (this condition)" then we tell the user not to pass it twice...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have the information regarding only once stored right now?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!info.in_many would be it I guess. Let me show an example.

#[derive(Bpaf, Clone, Debug)]
#[bpaf(options)]
struct Options {
    a: usize,
    b: usize,
    #[bpaf(argument, many)]
    c: Vec<usize>,
}

So say we have this parser. It takes arguments -a=0 and -b=0 once, -c=0 multiple times.

If user passes -a0 -b3 -c1 -c2 -c3 -c4 -a1parser will run up to-c4and will give up on-a1`.

Visitor gets -a0 -b3 -c1 -c2 -c3 -c4in parsed,-a1` in unparsed (well, just names I guess)...

To explain that name -a can be used only once we only need to look at name -a that it is not inside of many context - it is not.

bpaf_core/src/visitor/explain_unparsed.rs Outdated Show resolved Hide resolved
@pacak
Copy link
Owner

pacak commented Dec 27, 2024

Last push looks correct. Will merge in an hour or so.

@pacak pacak merged commit f32ec6a into pacak:bpaf-core Dec 27, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants