diff options
author | PizzasBear <43722034+PizzasBear@users.noreply.github.com> | 2023-11-22 15:56:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 14:56:14 +0100 |
commit | 48c6cd327d3c1df4218898be509250efcc56597c (patch) | |
tree | 6db2748a99e036960a0421070c222af096f040b7 /askama_parser/src | |
parent | ea7267dfc2914cdc340bae1a823c0660daef19e6 (diff) | |
download | askama-48c6cd327d3c1df4218898be509250efcc56597c.tar.gz askama-48c6cd327d3c1df4218898be509250efcc56597c.tar.bz2 askama-48c6cd327d3c1df4218898be509250efcc56597c.zip |
Enhance match to include multiple targets (#911)
Signed-off-by: max <gmx.sht@gmail.com>
Diffstat (limited to 'askama_parser/src')
-rw-r--r-- | askama_parser/src/node.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index 4da1742..ba117c5 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -128,10 +128,23 @@ pub enum Target<'a> { CharLit(&'a str), BoolLit(&'a str), Path(Vec<&'a str>), + OrChain(Vec<Target<'a>>), } impl<'a> Target<'a> { + /// Parses multiple targets with `or` separating them pub(super) fn parse(i: &'a str) -> ParseResult<'a, Self> { + map( + separated_list1(ws(tag("or")), Self::parse_one), + |mut opts| match opts.len() { + 1 => opts.pop().unwrap(), + _ => Self::OrChain(opts), + }, + )(i) + } + + /// Parses a single target without an `or`, unless it is wrapped in parentheses. + fn parse_one(i: &'a str) -> ParseResult<'a, Self> { let mut opt_opening_paren = map(opt(ws(char('('))), |o| o.is_some()); let mut opt_closing_paren = map(opt(ws(char(')'))), |o| o.is_some()); let mut opt_opening_brace = map(opt(ws(char('{'))), |o| o.is_some()); |