Skip to content

Commit ae3318a

Browse files
reidspencerclaude
andcommitted
Update RIDDL language reference for when/else/end syntax
EBNF grammar: - Updated when_condition to support literal_string | ["!"] identifier - Updated when_statement to include optional else block Language reference: - Added documentation for else block in when statements - Added section on condition types (literal strings, identifiers, negated) - Documented when/else/end syntax with examples Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 91521fe commit ae3318a

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

docs/riddl/references/ebnf-grammar.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ statement = when_statement | match_statement | send_statement | tell_statement |
191191
entity_statement = statement | morph_statement | become_statement ;
192192
193193
(* Control flow *)
194-
when_statement = "when" literal_string "then" pseudo_code_block "end" ;
194+
when_condition = literal_string | ["!"] identifier ;
195+
when_statement = "when" when_condition "then" pseudo_code_block ["else" pseudo_code_block] "end" ;
195196
match_statement = "match" literal_string "{" {match_case}+ ["default" "{" {statement} "}"] "}" ;
196197
match_case = "case" literal_string "{" {statement} "}" ;
197198

docs/riddl/references/language-reference.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,30 @@ when "condition" then {
378378
} end
379379
```
380380

381-
The `end` keyword is required to terminate when statements. Note: there is no
382-
`else` clause - use multiple `when` statements for different conditions.
381+
The `end` keyword is required to terminate when statements.
382+
383+
**Condition Types:**
384+
The `when` statement accepts three forms of conditions:
385+
- Literal string: `when "user is authenticated" then`
386+
- Identifier reference: `when authorized then` (using a `let` binding)
387+
- Negated identifier: `when !authorized then`
388+
389+
**Optional Else Block:**
390+
An `else` clause can handle the false case:
391+
```
392+
let authorized = "user has permission"
393+
when authorized then {
394+
send event ActionCompleted to outlet Events
395+
} else {
396+
error "User not authorized"
397+
} end
398+
```
399+
400+
Alternatively, use multiple `when` statements with negation:
401+
```
402+
when authorized then { ... } end
403+
when !authorized then { ... } end
404+
```
383405

384406
### Match Statement
385407
Pattern matching for multiple conditions:

0 commit comments

Comments
 (0)