snakes-pnml.txt
19.1 KB
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
This document describes the PNML extensions used bu SNAKES. See
http://www.pnml.org for the definition of the standard PNML. In the
following, we use a simplified RELAX NG Compact Syntax (see
http://relaxng.org). For each element, we provide the Python class
that implements it (see API reference for details), a list of its
attributes and children elements.
##
## Petri net elements
##
element pnml {
element net { ... }*
}
# Several nets may be provided in one PNML file.
element net { # class snakes.nets.PetriNet
attribute id { text } # identity of the net
element place { ... }* # places in the net
element transition { ... }* # transitions in the net
element arc { ... }* # arcs in the net
}
element place { # class snakes.nets.Place
attribute id { text } # identity of the place
element type { ... }? # for a coloured place
element initialMarking { # marking
( element text { num:integer } # for a P/T place
| element multiset { ... } ) # for a coloured place
}?
}
# A P/T place is identified in SNAKES by the fact it has a typing
# constraint "tBlackToken". In such a case, its initial marking is
# given as the number of black tokens held by the place, which
# respects the PNML standard. In the other cases, the place is
# considered to be coloured and its type constraint is given by an
# element <type> and its marking is given by an element <multiset>.
element transition { # class snakes.nets.Transition
attribute id { text } # identity of the transition
element guard {
element expression { ... } # guard if not True
}?
}
# When the guard is True, like in P/T nets, it is not saved in the
# PNML so that the result respects PNML standard. Otherwise, the guard
# is saved inside a tag <guard>.
element declare {
statement
}
# One <declare> tag is added to <net> for each Python statement run
# using PetriNet.declare() for this net.
element global {
attribute name { name:string } # object's name
element * { ... } # value
}
# One <global> is added to <net> for each entry in net.globals that
# is not obtained through the use of PetriNet.declare().
##
## Arcs
##
element arc {
attribute id { text } # identity of the arc
attribute source { text } # identity of source node
attribute target { text } # identity of target node
element inscription {
element text { # for a P/T net
weight:int
}?
element * { ... }? # for a coloured net
}
}
# When the net is a P/T net, a weight is given for the arcs, which
# respects the PNML standard. Otherwise, the inscription is one of the
# possible inscriptions given below.
element value { # class snakes.nets.Value
element object { ... } # value transported on an arc
}
element variable { # class snakes.nets.Variable
name:string # name of the variable
}
element expression { # class snakes.nets.Expression
expr:string # text of the expression (Python code)
}
element test { # class snakes.nets.Test
( element value { ... }
| element variable { ... }
| element expression { ... }
| element multiarc { ... }
| element tuple { ... } ) # tested annotation
}
element multiarc { # class snakes.nets.MultiArc
( element value { ... }
| element variable { ... }
| element expression { ... }
| element multiarc { ... }
| element tuple { ... } )* # list of encapsulated annotations
}
element tuple { # class snakes.nets.Tuple
( element value { ... }
| element variable { ... }
| element expression { ... }
| element multiarc { ... }
| element tuple { ... } )* # list of encapsulated annotations
}
##
## Auxiliary tags
##
element token { # class snakes.nets.BlackToken
} # a standard black token
element marking { # class snakes.nets.Marking
element place { # one for each marked place
attribute id { text } # identity of the place
element tokens {
element multiset { ... } # marking of the place
}
}*
}
element multiset { # class snakes.data.MultiSet
element item { # items in the multiset
element value {
element object { ... } # value of one item
}
element multiplicity { # number of time it is repeated
num:integer
}
}*
}
element substitution { # class snakes.data.Substitution
element item { # mapped variables
element name {
name:string # variable name
}
element value {
element object { ... } # associated value
}
}*
}
##
## Python objects
##
element object {
attribute type { ... } # type of the object
... # depends of attribute type
}
element object {
attribute type { "int" } # object is an integer
value:integer
}
element object {
attribute type { "float" } # object is a float
value:float
}
element object {
attribute type { "str" } # object is a string
value:string
}
element object {
attribute type { "bool" } # object is a Boolean
( "True" | "False" )
}
element object {
attribute type { "list" } # object is a list
element object { ... }* # list items
}
element object {
attribute type { "tuple" } # object is a tuple
element object { ... }* # tuple items
}
element object {
attribute type { "set" } # object is a set
element object { ... }* # set items
}
element object {
attribute type { "method" } # object is a class method
attribute name { path:string} # path to method, including module name
}
element object {
attribute type { "function" } # object is a function
attribute name { path:string} # path to function, including module name
}
element object {
attribute type { "class" } # object is a class
attribute name { path:string} # path to class, including module name
}
element object {
attribute type { "module" } # object is a module
attribute name { path:string} # path to module
}
element object {
attribute type { "pickle" } # object that cannot be handled symbolically
data:string # pickled object
}
element object {
attribute type { "NoneType" } # object is the value None
}
##
## Typing constraints
##
element type {
attribute domain { text } # kind of typing constraint
... # depending on domain
}
# Module snakes.typing defines a full algebra of types, all are saved
# to an element <type>. The attribute "domain" is then the key to
# decompose correctly a type. Below is a list of the different
# domains, with the structure of the corresponding type
element type { # class snakes.typing._And
attribute domain { "intersection" } # intersection of two types
element left { # left operand type
element type { ... }
}
element right { # right operand type
element type { ... }
}
}
element type { # class snakes.typing._Or
attribute domain { "union" } # union of two types
element left { # left operand type
element type { ... }
}
element right { # right operand type
element type { ... }
}
}
element type { # class snakes.typing._Sub
attribute domain { "difference" } # difference of two types
element left { # left operand type
element type { ... }
}
element right { # right operand type
element type { ... }
}
}
element type { # class snakes.typing._Xor
attribute domain { "xor" } # exclusive union of two types
element left { # left operand type
element type { ... }
}
element right { # right operand type
element type { ... }
}
}
element type { # class snakes.typing._Invert
attribute domain { "complement" } # complement of a type
element type { ... } # complemented type
}
element type { # class snakes.typing._All
attribute domain { "universal" } # type with all possible values
}
element type { # class snakes.typing._Nothing
attribute domain { "empty" } # type with no value
}
element type { # class snakes.typing.Instance
attribute domain { "instance" } # type whose values are instances
element object { ... } # class of the instances
}
element type { # class snakes.typing.TypeCheck
attribute domain { "checker" } # type defined by a Boolean function
element checker {
element object { ... } # the Boolean function
}
element iterator {
element object { ... } # a function to enumerate the values
}
}
element type { # class snakes.typing.OneOf
attribute domain { "enum" } # enumerated type
element object { ... }* # values in the type
}
element type { # class snakes.typing.Collection
attribute domain { "collection" } # flat container type (list, set, ...)
element container {
element type { ... } # type of the container
}
element items {
element type { ... } # type of the contained items
}
element min {
element object { ... } # smallest allowed number of elements
}
element max {
element object { ... } # biggest allowed number of elements
}
}
element type { # class snakes.typing.Mapping
attribute domain { "mapping" } # dictionary-like container type
element container {
element type { ... } # type of the container
}
element keys {
element type { ... } # type of the contained keys
}
element items {
element type { ... } # type of the contained items
}
}
element type { # class snakes.typing.Range
attribute domain { "range" } # values in a range
element min {
element object { ... } # smallest allowed value
}
element min {
element object { ... } # smallest excluded value
}
element min {
element object { ... } # step between consecutive values
}
}
element type { # class snakes.typing.Greater
attribute domain { "greater" } # values bigger than a given one
element object { ... } # biggest excluded value
}
element type { # class snakes.typing.GreaterOrEqual
attribute domain { "greatereq" } # values not smaller than a given one
element object { ... } # smallest allowed value
}
element type { # class snakes.typing.Less
attribute domain { "less" } # values smaller than a given one
element object { ... } # smallest excluded value
}
element type { # class snakes.typing.LessOrEqual
attribute domain { "lesseq" } # values not bigger than a given one
element object { ... } # biggest allowed value
}
element type { # class snakes.typing.CrossProduct
attribute domain { "crossproduct" } # cross product of types
element type { ... }* # crossed types
}
##
## Additional elements from plugins
##
element snakes {
attribute version { ... } # SNAKES' version that produced this PNML
element plugins {
element object {
attribute type { "tuple" }
element object { # the base module 'snakes.nets' is listed also
attribute type { "str" }
"snakes.nets"
}
element object { # list of plugins
attribute type { "str" }
plugin:string
}*
}
}
}
# Added to another element in order to specify the plugins necessary
# to load properly the element. <snakes><plugins> tags can be added at
# any position in the PNML, but they are then used globally for a
# whole <pnml> tree.
element status { # class snakes.plugins.status.Status
element name {
name:string # status name
}
element value {
element object { ... } # attached value
}
}
# Added to <place> and <transition> when plugin 'status' is loaded.
element multiaction { # class snakes.plugins.synchro.MultiAction
element action { ... }* # actions in the multi-action
}
# Added to <transition> when plugin 'synchro' is loaded.
element action { # class snakes.plugins.synchro.Action
attribute name { name:string } # action name
attribute send { send:boolean } # send/receive action
element * { ... }* # action parameters
}
element clusters { # class snakes.plugins.clusters.Cluster
element node { id:string }* # nodes at this level
element clusters { ... }* # children clusters
}
# Added to <net> when plugin 'clusters' is loaded.
element label { # class snakes.plugins.labels
attribute name { name:string} # label name
element object { ... } # label content
}
# Added to <net>, <place> and <transition> when plugin 'labels' is
# loaded.
element graphics {
element position { # node position
attribute x { xpos:(integer|float) } # x coordinate
attribute y { ypos:(integer|float) } # y coordinate
}
}
# Added to <place> and <transition> when plugin 'pos' is loaded.
element query { # snakes.plugins.query.Query
attribute name { name:text} # name of the query
element argument { ... }* # arguments of the query
element keyword { # keyword arguments
attribute name { text } # keyword name
element * { ... } # associated value
}*
}
# See file 'queries.txt'
element answer {
attribute status { "ok" | "error" } # status of the answer
message:string? # error message if status=error
element * { ... }? # returned value if status=ok
}
# See file 'queries.txt'
##
## Abstract syntax tree
##
# The following specifies the PNML translation of abstract syntax
# trees for ABCD programs, as inserted into <net> but the ABCD
# compiler.
element ast { # class snakes.compyler.Tree
attribute name { text } # node nature
attribute lineno { num:integer }? # line number in source code
attribute * { ... }* # depending on name
element * { ... }* # depending on name
}
# <ast> trees are obtained by direct translation of
# snakes.compyler.Tree instances: tree name is mapped to an attribute
# 'name', sub-trees are mapped to child tags, and attributes are
# mapped either to attributes or to child tags <attribute> when they
# cannot be represented as a simple string. The following lists the
# more current patterns. The element 'lineno' will be omitted in the
# following.
element ast {
attribute name { "abcd" } # start symbol
element ast { # buffer declarations
attribute name { "buffer" }
...
}*
element ast { # net declarations
attribute name { "net" }
...
}*
element attribute { # ABCD expression
attribute name { "expr" }
...
}
}
# An ABCD program is composed of optional buffer and net declarations,
# followed by an ABCD expression.
element ast {
attribute name { "buffer" } # buffer declaration
attribute ident { text:string } # buffer's name
element attribute {
attribute name { "type" } # buffer's type
...
}
element attribute { # buffer's initial value
attribute name { "init" }
...
}
}
element net {
attribute name { "net" } # net declaration
attribute ident { text:string } # net's name
element ast { # net's body
attribute name { "abcd" }
...
}
}
element ast {
attribute name { "expr" }
element ast {
attribute name { ( "parallel" # binary composition
| "loop"
| "sequence"
| "choice" ) }
element ast { ... } # first operand
element ast { ... } # second operand
}
}
element ast {
attribute name { "expr" }
element ast {
attribute name { "scope" } # name hiding
element ast { ... } # first operand
element object {
attribute type { "str" } # hidden name
name:string
}
}
}
element ast {
attribute name { "action" } # basic action
attribute net { ( name:string | "None" ) } # reference to a net
attribute test { ( "False" | "True" ) }? # trivial condition
element ast {
attribute name { "access" } # buffer access
attribute buffer { name:string } # buffer's name
attribute mode { ("?" | "+" | "-") } # test, put or get
element attribute {
attribute name { "param" } # access' parameter
element python { ... } # Python's AST of the parameter
}
}*
element attribute { # non-trivial condition
attribute name { "test" }
element python { ... } # Python's AST of the condition
}?
}
# A basic action can be the name of a net or a trivial action
# '[False]'. Otherwise, it is composed of a possibly empty list of
# buffer accesses and a condition. If the condition is 'True', it is
# stored as attribute 'test=True", but more complex conditions are
# stored as a Python AST in a child tag <attribute name="test">. Each
# access is composed of a buffer name, an access mode and a parameter.
# Next elements are children of a tag <attribute name="type"> and
# defined the type of a buffer.
element ast {
attribute name { "name } # Python built-in type
attribute value { type:string } # name of the type
}
element ast {
attribute name { "enum" } # enumerated type
element ast {
attribute name { "values" }
element python { # Python's AST node in this case
attribute class { "Tuple" } # is a Tuple of Const
element attribute {
attribute name { "nodes" }
values # eg, "[Const('a'), Const('b')]"
}
}
}
}
element ast {
attribute name { "union" } # union of two types
element ast { ... } # first type
element ast { ... } # second type
}
element ast {
attribute name { "intersection" } # intersection of two types
element ast { ... } # first type
element ast { ... } # second type
}
element ast {
attribute name { "list" } # list type
element ast { ... } # items' type
}
element ast {
attribute name { "dict" } # dict type
element ast { ... } # keys' type
element ast { ... } # values' type
}
element ast {
attribute name { "set" } # set type
element ast { ... } # items' type
}
# A Python AST is serialized as a <python> tag, see the section 31.3.1
# (AST Nodes) of the Python Library Reference for a list of AST nodes.
element python {
attribute * { text }* # direct mapping of simple attributes
element attribute { # complex attributes are serialized
attribute name { text } # in a tag <object>
element object { ... }
}*
data? # when none of the above method works,
# 'repr' is used to convert the AST to text
}