-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
Enhance match to include multiple targets #911
Conversation
Signed-off-by: max <gmx.sht@gmail.com>
Signed-off-by: max <gmx.sht@gmail.com>
Signed-off-by: max <gmx.sht@gmail.com>
I've removed the comments, forgot to remove them prior to committing... |
askama_parser/src/node.rs
Outdated
pub(super) fn parse(i: &'a str) -> ParseResult<'a, Self> { | ||
map( | ||
separated_list1(ws(tag("or")), Self::parse_one), | ||
|opts| match <[_; 1]>::try_from(opts) { |
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.
I don't find this <[_; 1]>::try_from()
idiom particularly clear. How about this:
match opts.len() {
1 => opts.pop().unwrap(),
_ => Self::OrChain(opts),
}
(Is this actually necessary? What happens if we just always yield a Vec<Target<'a>>
from parse()
?)
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.
I liked the try_from
because it avoided mut
and .unwrap()
, but I can change this.
The match
statement helps avoid one item Target::OrChain
which will help debugging by cleaning up the output of println!("{target:#?}")
or other statements that'll result in pretty printing a target.
Signed-off-by: max <gmx.sht@gmail.com>
…if let` statements Signed-off-by: max <gmx.sht@gmail.com>
This adds ability to
or
patterns in any context (e.g. inwhen
andlet
).This is done by adding an
OrChain
variant to theTarget
enum inaskama_parser
,and simply adding a
|
between or-chained patterns inaskama_derive
.Closes #904