common_sequence_diagram_io 0.2.0

A generic interface to parse, print and draw interaction languages
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429


I initially wrote this code for these projects : 
- [hibou_label]https://github.com/erwanM974/hibou_label 
- [hibou_efm]https://github.com/erwanM974/hibou_efm
- [hibou_passing]https://github.com/erwanM974/hibou_passing

Since then I decided to generalize it using generics and repackage it on its own as a library.


# Common IO features for interaction languages

This crates provide generic input (i.e., parsing from text files) and output (i.e., encoding into text and drawing as PNG images) features
for interaction languages.

Interaction Languages are languages that encode distributed processes that can be drawn in the form of Sequence Diagrams 
(such as UML Sequence Diagrams or Message Sequence Charts).

In this crate, we do not define any specific Interaction Language but rather provide an interface that can be implemented for any specific Interaction Language
so as to automatically benefit from the aforementioned IO features.


Interaction Languages such as the one in [hibou](https://github.com/erwanM974/hibou_label) are provided with
a formal semantics.
However, in order to simply parse interactions and draw them (as sequence diagrams), a formal semantics is not necessary : only a syntax is required.


As such, in this library, we do not have any semantic requirement for the Interaction Language.
Only a syntax is required and we also need to know the arity of operators and wether or not any given binary operator is associative.


Below, we give two example languages.


## A minimal Interaction Language

We provide a complete minimal Interaction Language that uses the public interface of this crate in the "src/z_test_minimal_lang/" package.

The atomic "leaves" of this Interaction Language can be either 
the empty interaction,
the emission of a message from a lifeline,
or the reception of a message by a lifeline. 

The language includes the following operators:
- the classical "strict" strict sequencing and "seq" weak sequencing operators 
- the alternative "alt"
- parallel composition "par"
- a "loop"

Except for "loop" which is unary, these 4 operators are binary associative operators.
(see [hibou_label](https://github.com/erwanM974/hibou_label) for details about these operators)


In "src/z_test_minimal_lang/", we use the library interface to implement:
- a parser in "src/z_test_minimal_lang/from_text"
- a printer in "src/z_test_minimal_lang/to_text"
- a drawer in "src/z_test_minimal_lang/to_image"



Generic syntaxic sugar is automatically handled by the parser.

For instance, for any associative binary operator "op", we may write "op(a,b,c)" instead of "op(a,op(b,c))" or "op(op(a,b),c)".

The library code also facilitates handling (i.e., parsing and drawing) of message passing and broadcast patterns (which are important in Interaction Languages).

For instance, a pattern of the form "strict(emission,reception)", if the "emission" and "reception" involve the exact same message, may be automatically interpreted (and drawn) as a message passing arrow. 
Likewise, for "strict(emission,seq(rec1,rec2))" if all three involve the same message, we have a broadcast.









<table>
<tr>
<td> Drawing as a Sequence Diagram </td> <td> Input Text </td> <td> Parsed Internal Representation </td> <td> Interaction Term (in the Minimal Language) </td> 
</tr>
<tr>

<td>

<img src="./README_images/test1.png" alt="test1">

</td>

<td> 

```
seq(
    a -- m -> b,
    alt(
            b -- m -> a,
            0
    )
)
```

</td>
<td>
<h6>

```
Operator(Seq, 
    [
        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern { origin_lf_id: Some(0), msg_id: 0, targets: [1] })), 
        Operator(Alt, 
            [
                LeafPattern(BROADCAST(MinimalBroadcastLeafPattern { origin_lf_id: Some(1), msg_id: 0, targets: [0] })), 
                LeafPattern(EMPTY)
            ]
        )
    ]
)
```

</h6>
</td>

<td>
<h6>

```
Seq(
    Strict(
        Action(MinimalAction { lf_id: 0, ms_id: 0, kind: Emission }), 
        Action(MinimalAction { lf_id: 1, ms_id: 0, kind: Reception })
    ), 
    Alt(
        Strict(
            Action(MinimalAction { lf_id: 1, ms_id: 0, kind: Emission }), 
            Action(MinimalAction { lf_id: 0, ms_id: 0, kind: Reception })
        ), 
        Empty
    )
)
```

</h6>
</td>




</tr>


<tr>

<td>

<img src="./README_images/test2.png" alt="test2">

</td>

<td> 

```
seq(
    a -- m -> b,
    a -- n -> c,
    loop(
        a -- p -> (b,c)
    )
)
```

</td>
<td>
<h6>

```
Operator(Seq,
    [
        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:0,targets:[1]})),
        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:1,targets:[2]})),
        Operator(Loop,
            [
                LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:2,targets:[1,2]}))
            ]
        )
    ]
)
```

</h6>
</td>

<td>
<h6>

```
Seq(
    Strict(
        Action(MinimalAction{lf_id:0,ms_id:0,kind:Emission}),
        Action(MinimalAction{lf_id:1,ms_id:0,kind:Reception})
    ),
    Seq(
        Strict(
            Action(MinimalAction{lf_id:0,ms_id:1,kind:Emission}),
            Action(MinimalAction{lf_id:2,ms_id:1,kind:Reception})
        ),
        Loop(
            Strict(
                Action(MinimalAction{lf_id:0,ms_id:2,kind:Emission}),
                Seq(
                    Action(MinimalAction{lf_id:1,ms_id:2,kind:Reception}),
                    Action(MinimalAction{lf_id:2,ms_id:2,kind:Reception})
                )
            )
        )
    )
)
```

</h6>
</td>




</tr>





<tr>

<td>

<img src="./README_images/test3.png" alt="test3">

</td>

<td> 

```
seq(
    a -- m -> b,
    par(
        a -- n -> c,
        alt(
            c -- o -> c,
            c -- p -> b     
        )
    ),
    loop(
        a -- q -> (a,b,c)
    )
)
```

</td>
<td>
<h6>

```
Operator(Seq,
    [
        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:0,targets:[1]})),
        Operator(Par,
            [
                LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:1,targets:[2]})),
                Operator(Alt,
                    [
                        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(2),msg_id:2,targets:[2]})),
                        LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(2),msg_id:3,targets:[1]}))
                    ]
                )
            ]
        ),
        Operator(Loop,
            [
                LeafPattern(BROADCAST(MinimalBroadcastLeafPattern{origin_lf_id:Some(0),msg_id:4,targets:[0,1,2]}))
            ]
        )
    ]
)
```

</h6>
</td>

<td>
<h6>

```
Seq(
    Strict(
        Action(MinimalAction{lf_id:0,ms_id:0,kind:Emission}),
        Action(MinimalAction{lf_id:1,ms_id:0,kind:Reception})
    ),
    Seq(
        Par(
            Strict(
                Action(MinimalAction{lf_id:0,ms_id:1,kind:Emission}),
                Action(MinimalAction{lf_id:2,ms_id:1,kind:Reception})
            ),
            Alt(
                Strict(
                    Action(MinimalAction{lf_id:2,ms_id:2,kind:Emission}),
                    Action(MinimalAction{lf_id:2,ms_id:2,kind:Reception})
                ),
                Strict(
                    Action(MinimalAction{lf_id:2,ms_id:3,kind:Emission}),
                    Action(MinimalAction{lf_id:1,ms_id:3,kind:Reception})
                )
            )
        ),
        Loop(
            Strict(
                Action(MinimalAction{lf_id:0,ms_id:4,kind:Emission}),
                Seq(
                    Action(MinimalAction{lf_id:0,ms_id:4,kind:Reception}),
                    Seq(
                        Action(MinimalAction{lf_id:1,ms_id:4,kind:Reception}),
                        Action(MinimalAction{lf_id:2,ms_id:4,kind:Reception})
                    )
                )
            )
        )
    )
)
```

</h6>
</td>


</tr>
</table>




## A colorful Nonsensical Interaction Language 

The second example language is a nonsensical Interaction Language that we use here to showcase the graphical features of the image drawer interface.
See the implementation in the "src/z_test_colorful/" package with:
- the parser in "src/z_test_colorful/from_text"
- the drawer in "src/z_test_colorful/to_image"

The language has the following operators:
- "TPC" (short for "Team Pain Au Chocolat"), which is a unary operator
- A family of operators that corresponds to all the "Rougail{.}", "." denoting any chain of alphabetic characters. All of these operators are binary and associative.
- "brocoli", which is a non-associative binary operator.
- A co-region operator similar to the one of real-life Interaction Languages (see [hibou_label]https://github.com/erwanM974/hibou_label ).

Unlike in the previous example Minimal Language, 
here, the atomic actions of this language are already Transmission Events,
but they also include accompagnying notes about something more or less related
and they can involve outside gates in addition to lifelines.






<table>
<tr>
<td> Drawing as a Sequence Diagram </td> <td> Input Text </td>
</tr>

<tr>

<td> 
<img src="./README_images/bob.png" alt="bob">
</td> 

<td>

```
seq(
    {IgetIt}bob--discombobulate->{why;powerlevel}alice{coffepause},
    brocoli(
        cr{carl}(
            alice{gotIt}--befuddle->carl,
            alice{nah}--flummox->carl{ready}
        ),
        binturong--discombobulate->alice
    ),
    carl--secret->bob,
    rougail{dakatine}(
        bob--befuddle->quokka,
        rougail{tomate}(
            seq(
                bob--flummox->alice,
                alice{a;b;c}--flummox->alice
            ),
            TPC(
                alice--secret->kakapo
            ),
            carl--discombobulate->bob
        )
    )
)
```

</td>

</tr>

</table>









## Dependencies

This is a pure Rust library.

The other pure Rust crates it depends on are:
- for the parser : [nom]https://crates.io/crates/nom 
- for the drawer : [image]https://crates.io/crates/image (and other crates in its ecosystem)