@@ -563,25 +563,44 @@ impl<'a> Macro<'a> {
563
563
#[ derive( Debug , PartialEq ) ]
564
564
pub struct FilterBlock < ' a > {
565
565
pub ws1 : Ws ,
566
- pub filter_name : & ' a str ,
567
- pub args : Vec < Expr < ' a > > ,
566
+ pub filters : Expr < ' a > ,
568
567
pub nodes : Vec < Node < ' a > > ,
569
568
pub ws2 : Ws ,
570
569
}
571
570
572
571
impl < ' a > FilterBlock < ' a > {
573
572
fn parse ( i : & ' a str , s : & State < ' _ > ) -> ParseResult < ' a , Self > {
573
+ #[ allow( clippy:: type_complexity) ]
574
+ fn filter ( i : & str , level : crate :: Level ) -> ParseResult < ' _ , ( & str , Option < Vec < Expr < ' _ > > > ) > {
575
+ let ( i, ( _, fname, args) ) = tuple ( (
576
+ char ( '|' ) ,
577
+ ws ( identifier) ,
578
+ opt ( |i| Expr :: arguments ( i, level, false ) ) ,
579
+ ) ) ( i) ?;
580
+ Ok ( ( i, ( fname, args) ) )
581
+ }
582
+
574
583
let mut start = tuple ( (
575
584
opt ( Whitespace :: parse) ,
576
585
ws ( keyword ( "filter" ) ) ,
577
586
cut ( tuple ( (
578
587
ws ( identifier) ,
579
588
opt ( |i| Expr :: arguments ( i, s. level . get ( ) , false ) ) ,
589
+ many0 ( |i| filter ( i, s. level . get ( ) ) ) ,
580
590
opt ( Whitespace :: parse) ,
581
591
|i| s. tag_block_end ( i) ,
582
592
) ) ) ,
583
593
) ) ;
584
- let ( i, ( pws1, _, ( filter_name, params, nws1, _) ) ) = start ( i) ?;
594
+ let ( i, ( pws1, _, ( filter_name, params, extra_filters, nws1, _) ) ) = start ( i) ?;
595
+
596
+ let mut filters = Expr :: Filter ( filter_name, params. unwrap_or_default ( ) ) ;
597
+ for ( filter_name, args) in extra_filters {
598
+ filters = Expr :: Filter ( filter_name, {
599
+ let mut args = args. unwrap_or_default ( ) ;
600
+ args. insert ( 0 , filters) ;
601
+ args
602
+ } ) ;
603
+ }
585
604
586
605
let mut end = cut ( tuple ( (
587
606
|i| Node :: many ( i, s) ,
@@ -598,8 +617,7 @@ impl<'a> FilterBlock<'a> {
598
617
i,
599
618
Self {
600
619
ws1 : Ws ( pws1, nws1) ,
601
- filter_name,
602
- args : params. unwrap_or_default ( ) ,
620
+ filters,
603
621
nodes,
604
622
ws2 : Ws ( pws2, nws2) ,
605
623
} ,
0 commit comments