@@ -550,6 +550,54 @@ pub struct IfBlock {
550550 pub metadata : Option < Metadata > ,
551551}
552552
553+
554+ /// Case of a match
555+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
556+ pub struct MatchCase {
557+ /// The condition to check
558+ #[ serde( rename = "if" ) ]
559+ pub if_ : Option < StringOrBoolean > ,
560+
561+ /// Branch to execute if the condition is true
562+ pub then : Box < PdlBlock > ,
563+
564+ }
565+
566+
567+ /// Match control structure.
568+ ///
569+ /// Example:
570+ /// ```PDL
571+ /// defs:
572+ /// answer:
573+ /// read:
574+ /// message: "Enter a number? "
575+ /// match: ${ (answer | int) }
576+ /// with:
577+ /// - case: 42
578+ /// then: You won!
579+ /// - case:
580+ /// any:
581+ /// def: x
582+ /// if: ${ x > 42 }
583+ /// then: Too high
584+ /// - then: Too low
585+ /// ```
586+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
587+ pub struct MatchBlock {
588+ /// The expression to match
589+ #[ serde( rename = "match" ) ]
590+ pub match_ : StringOrBoolean ,
591+
592+ /// Branch to execute if the condition is true
593+ pub with : Vec < MatchCase > ,
594+
595+ #[ serde( flatten) ]
596+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
597+ pub metadata : Option < Metadata > ,
598+ }
599+
600+
553601/// Return the array of values computed by each block of the list of blocks
554602#[ derive( Serialize , Deserialize , Debug , Clone ) ]
555603#[ serde( tag = "kind" , rename = "array" ) ]
0 commit comments