-
Notifications
You must be signed in to change notification settings - Fork 0
Signatures
Each state defines a signature requiring zero or more parameters. And all events leading into a state must conform to that state's signature.
The state's signature is specified only when it defines at least one parameter as a parenthesized parameter list on the state header line.
state Request redirect( new dest: Level Name )
The grammar:
state_header = "state" SP state_name signature? (SP DELETION)? EOL*
signature = '()' / '(' SP? parameter_set SP? ')'
parameter_set = parameter (',' SP parameter)*
parameter = parameter_name SP? ':' SP? type_name
parameter_name = name
type_name = name
A signature is a pair of parentheses directly after the state name, with no space between the name and the opening paren. Inside is a comma separated list of parameters, and each parameter is a name, a colon and a type name.
The spacing rules are worth reading off the grammar carefully, because they are not symmetric:
- Inside the parens, a space after
(and before)is optional —( new dest: Level Name )and(new dest: Level Name)both parse. - Around the colon, spaces are optional on both sides.
- Between parameters, the comma must be followed by exactly one space.
,alone or,will fail.
Here are several real signatures from the elevator models, all of which parse:
state Update location( floor: Level Name )
state Set emergency stop( nearest safe stop : Level Name)
state Changing destination before cabin moves( new dest: Level Name )
The type_name is just a name as far as this grammar is concerned. It isn't resolved or checked here — the
parser hands the string along and a downstream module decides whether Level Name is a real type in this
domain. Types like Level Name and Direction are modeled types from the domain, not programming language
primitives.
By convention, a type name has each initial character in uppercase.
The grammar explicitly allows ():
state OPENING()
There's no reason to write it, since a state with no parameters simply omits the signature, but if it turns
up in a file it will parse. Be aware of one quirk if you're consuming the parse result: for the () case
the signature field comes back as the literal string '()' rather than an empty list.
A signature describes what arrives with the event that causes the transition into this state. So if
Try redirect carries a new destination, then the state that Try redirect leads to is the state that
declares ( new dest: Level Name ). The activity (see Activities) then refers to the parameter with a
caret, as in ^new dest.
Copyright 2023-2026 © Leon Starr under MIT Open Source License