Skip to content

Initial states

Leon Starr edited this page Jul 30, 2026 · 1 revision

A class with a lifecycle needs each of its instances to start the scenario in some state. Those states are written after the closing brace of a row.

row = ... '}' initial_state* EOL+
initial_state = SP rnum? '>' SP state_name

An initial_state is a space, an optional rnum, a >, a single space, and the state name. The presence or absence of the rnum is what distinguishes the two kinds:

  • > IDLE — the state of the instance's own lifecycle state machine
  • R53> NO TRANSFER — the state of the assigner state machine for relationship R53

The states themselves are the ones defined in the domain's xsm state model files.

Both at once

Shaft carries a lifecycle and also owns the assigner for R53, so its rows give both:

Shaft
ID | In service | R1>Bank
--
{ [S1] [true] @L } R53> NO TRANSFER > IDLE
{ [S2] [true] @L } R53> NO TRANSFER > IDLE
--

Read that as: the R53 assigner starts in NO TRANSFER and this shaft instance starts in IDLE.

Or neither

initial_state* allows zero of them, which is the case for every class without a lifecycle. Floor is just data, so its rows stop at the closing brace:

Floor
Name | Height
--
{ [PH] [35.2] }
{ [8]  [32.0] }
--

Assigner first

The ordering is not free: an rnum qualified state must come before a bare lifecycle state.

{ [S1] [true] @L } R53> NO TRANSFER > IDLE     // fine
{ [S1] [true] @L } > IDLE R53> NO TRANSFER     // parse error

The reason is that a state name may contain spaces, so after > IDLE the parser goes on reading IDLE R53 as a two word state name and only then trips over the >. The same ambiguity means at most one rnum qualified state can appear on a row — R1> A R2> B fails for exactly the same reason. In practice a row gives an assigner state, a lifecycle state, or an assigner state followed by a lifecycle state.

State names

state_name = word (delim word)* r'\?'?

A state name is one or more words separated by single spaces or underscores, with an optional trailing ?.

Unlike class and column names, a state name may start with a lowercase letter, since word admits both initial cap and all lowercase words. And because iword allows any letters after the first character, the all caps style used in the elevator model works: IDLE, NO TRANSFER, PICKUP DROPOFF, NOT REQUESTED.

The trailing ? accommodates the interrogative naming that some state models use, as in Door closed?.

In the parser output

The result reports initial_state as a list, and it is always a list so that a consumer can iterate over it without special casing the empty case:

[]                                  # no states given
[['IDLE']]                          # lifecycle only
[['R53', 'NO TRANSFER']]            # assigner only
[['R53', 'NO TRANSFER'], ['IDLE']]  # both

A one element entry is a lifecycle state and a two element entry is an assigner state paired with its rnum. See Parser output.

Clone this wiki locally