-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ba244b2
to
f0018ee
Compare
Last push looks correct. Will merge in an hour or so. |
No description provided.