diff --git a/pdl-live-react/src-tauri/src/pdl/ast.rs b/pdl-live-react/src-tauri/src/pdl/ast.rs index 599304208..b01562af5 100644 --- a/pdl-live-react/src-tauri/src/pdl/ast.rs +++ b/pdl-live-react/src-tauri/src/pdl/ast.rs @@ -550,6 +550,54 @@ pub struct IfBlock { pub metadata: Option, } + +/// Case of a match +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct MatchCase { + /// The condition to check + #[serde(rename = "if")] + pub if_: Option, + + /// Branch to execute if the condition is true + pub then: Box, + +} + + +/// Match control structure. +/// +/// Example: +/// ```PDL +/// defs: +/// answer: +/// read: +/// message: "Enter a number? " +/// match: ${ (answer | int) } +/// with: +/// - case: 42 +/// then: You won! +/// - case: +/// any: +/// def: x +/// if: ${ x > 42 } +/// then: Too high +/// - then: Too low +/// ``` +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct MatchBlock { + /// The expression to match + #[serde(rename = "match")] + pub match_: StringOrBoolean, + + /// Branch to execute if the condition is true + pub with: Vec, + + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, +} + + /// Return the array of values computed by each block of the list of blocks #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(tag = "kind", rename = "array")]