@@ -4,18 +4,102 @@ draft: false
44---
55
66A condition is a logical (boolean) expression resulting in true or false.
7+ Conditions are used in ` when ` statements to control flow and in ` match `
8+ statements for pattern matching.
79
8- ## Arbitrary Conditional (#arbitrary)
9- * just a string
10+ ## Arbitrary Conditional
1011
11- ## Numeric Expressions (#numeric)
12- TBD
12+ The simplest form is a string that describes the condition in natural language:
1313
14- ## Conditions (Boolean Expressions) {#condition}
15- TBD
14+ ``` riddl
15+ when "user is authenticated" then {
16+ // actions when condition is true
17+ } end
18+ ```
19+
20+ This allows authors to express conditions at the appropriate level of
21+ abstraction. The actual implementation of the condition check is left to
22+ code generation or manual implementation.
23+
24+ ## Identifier Conditions
25+
26+ Conditions can reference identifiers defined with ` let ` :
27+
28+ ``` riddl
29+ let isValid = "order.items.count > 0"
30+ when isValid then {
31+ // actions when valid
32+ } end
33+ ```
34+
35+ Identifiers can be negated:
36+
37+ ``` riddl
38+ when !isValid then {
39+ error "Order must have at least one item"
40+ } end
41+ ```
42+
43+ ## Numeric Expressions
44+
45+ Numeric expressions involve comparisons and arithmetic:
46+
47+ - ** Comparison operators** : ` > ` , ` < ` , ` >= ` , ` <= ` , ` == ` , ` != `
48+ - ** Arithmetic operators** : ` + ` , ` - ` , ` * ` , ` / `
49+
50+ ``` riddl
51+ when "order.total > 100" then {
52+ // apply discount
53+ } end
54+ ```
55+
56+ Note: In RIDDL, these expressions are typically written as strings that
57+ describe the intended logic. The actual parsing and evaluation happens
58+ during code generation.
59+
60+ ## Boolean Expressions
61+
62+ Boolean expressions combine conditions using logical operators:
63+
64+ - ** AND** : Both conditions must be true
65+ - ** OR** : Either condition must be true
66+ - ** NOT** : Negates a condition
67+
68+ ``` riddl
69+ when "user.isVerified AND order.total > 0" then {
70+ // process order
71+ } end
72+ ```
73+
74+ ## Match Expressions
75+
76+ The ` match ` statement provides pattern matching:
77+
78+ ``` riddl
79+ match "orderStatus" {
80+ case "pending" {
81+ // handle pending
82+ }
83+ case "processing" {
84+ // handle processing
85+ }
86+ case "shipped" {
87+ // handle shipped
88+ }
89+ default {
90+ // handle unknown status
91+ }
92+ }
93+ ```
1694
1795## Occurs In
18- * [ Statements] ( statement.md )
96+
97+ * [ Statements] ( statement.md ) - specifically ` when ` and ` match ` statements
1998
2099## Contains
21- Nothing
100+
101+ Conditions are leaf elements containing:
102+
103+ * String literals describing the condition
104+ * Identifier references
105+ * Logical operators combining sub-conditions
0 commit comments