Changed grammar for states

This commit is contained in:
Johan Maasing 2025-04-22 20:28:17 +02:00
parent bc458299dc
commit c1c062b6cf
3 changed files with 13 additions and 13 deletions

View file

@ -163,9 +163,9 @@ name it from the last path segment and add 'Response' to the end of the data typ
### State DSL
This is an example of a state file:
```
start -> middle: message,
middle -> middle: selfmessage,
middle -> end: endmessage
start -> message -> middle ,
middle -> selfmessage -> middle,
middle -> endmessage -> end
```
The file declares 3 transitions. The first line states: Transition from the 'start' state to the 'middle' state with
the message 'message'.
@ -178,18 +178,18 @@ Since the parser will extract datatypes it is possible to define the fields of t
complicated example:
```
start -> middle: message(a: String),
middle(bar:Bar) -> middle: selfmessage,
middle -> end: endmessage
start -> message -> middle,
middle -> selfmessage -> middle(bar:bar),
middle -> message -> end
```
The data type for `middle` will have a field declaration with the name `bar` and the type `Bar`.
Fields for the same state data type, or message data type, will be merged. Here is a complex example:
```
start(s:S) -> middle(foo:foo): message(foo:foo),
middle -> middle(bar:bar): selfmessage(bar:bar),
middle -> end: message(bar:baz)
start(s:S) -> message(foo:foo) -> middle(foo:foo) ,
middle -> selfmessage(bar:bar) -> middle(bar:bar),
middle -> message(bar:baz) -> end
```
Note that we can declare fields on both the `from` and `to` state declarations. The `middle` datat type will have field

View file

@ -15,7 +15,7 @@ grammar States;
import Common;
document : generatorconfig? transition (',' transition)* ;
transition : from RIGHT_ARROW to COLON message ;
transition : from RIGHT_ARROW message RIGHT_ARROW to ;
from : state ;
to : state ;
message : typeName typeDeclaration? ;

View file

@ -16,6 +16,6 @@
{ title: SomeNodes, package: nu.zoom.dsl.states }
start(s:S) -> middle(foo:foo): message(foo:foo),
middle -> middle(bar:bar): selfmessage(bar:bar),
middle -> end: message(bar:baz)
start(s:S) -> message(foo:foo) -> middle(foo:foo) ,
middle -> selfmessage(bar:bar) -> middle(bar:bar),
middle -> message(bar:baz) -> end