pyfcstm 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. pyfcstm/__init__.py +0 -0
  2. pyfcstm/__main__.py +4 -0
  3. pyfcstm/config/__init__.py +0 -0
  4. pyfcstm/config/meta.py +20 -0
  5. pyfcstm/dsl/__init__.py +6 -0
  6. pyfcstm/dsl/error.py +226 -0
  7. pyfcstm/dsl/grammar/Grammar.g4 +190 -0
  8. pyfcstm/dsl/grammar/Grammar.interp +168 -0
  9. pyfcstm/dsl/grammar/Grammar.tokens +118 -0
  10. pyfcstm/dsl/grammar/GrammarLexer.interp +214 -0
  11. pyfcstm/dsl/grammar/GrammarLexer.py +523 -0
  12. pyfcstm/dsl/grammar/GrammarLexer.tokens +118 -0
  13. pyfcstm/dsl/grammar/GrammarListener.py +521 -0
  14. pyfcstm/dsl/grammar/GrammarParser.py +4373 -0
  15. pyfcstm/dsl/grammar/__init__.py +3 -0
  16. pyfcstm/dsl/listener.py +440 -0
  17. pyfcstm/dsl/node.py +1581 -0
  18. pyfcstm/dsl/parse.py +155 -0
  19. pyfcstm/entry/__init__.py +1 -0
  20. pyfcstm/entry/base.py +126 -0
  21. pyfcstm/entry/cli.py +12 -0
  22. pyfcstm/entry/dispatch.py +46 -0
  23. pyfcstm/entry/generate.py +83 -0
  24. pyfcstm/entry/plantuml.py +67 -0
  25. pyfcstm/model/__init__.py +3 -0
  26. pyfcstm/model/base.py +51 -0
  27. pyfcstm/model/expr.py +764 -0
  28. pyfcstm/model/model.py +1392 -0
  29. pyfcstm/render/__init__.py +3 -0
  30. pyfcstm/render/env.py +36 -0
  31. pyfcstm/render/expr.py +180 -0
  32. pyfcstm/render/func.py +77 -0
  33. pyfcstm/render/render.py +279 -0
  34. pyfcstm/utils/__init__.py +6 -0
  35. pyfcstm/utils/binary.py +38 -0
  36. pyfcstm/utils/doc.py +64 -0
  37. pyfcstm/utils/jinja2.py +121 -0
  38. pyfcstm/utils/json.py +125 -0
  39. pyfcstm/utils/text.py +91 -0
  40. pyfcstm/utils/validate.py +102 -0
  41. pyfcstm-0.0.1.dist-info/LICENSE +165 -0
  42. pyfcstm-0.0.1.dist-info/METADATA +205 -0
  43. pyfcstm-0.0.1.dist-info/RECORD +46 -0
  44. pyfcstm-0.0.1.dist-info/WHEEL +5 -0
  45. pyfcstm-0.0.1.dist-info/entry_points.txt +2 -0
  46. pyfcstm-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,3 @@
1
+ from .GrammarLexer import GrammarLexer
2
+ from .GrammarListener import GrammarListener
3
+ from .GrammarParser import GrammarParser
@@ -0,0 +1,440 @@
1
+ from .grammar import GrammarListener, GrammarParser
2
+ from .node import *
3
+ from ..utils import format_multiline_comment
4
+
5
+
6
+ class GrammarParseListener(GrammarListener):
7
+ def __init__(self):
8
+ super().__init__()
9
+ self.nodes = {}
10
+
11
+ def exitCondition(self, ctx: GrammarParser.ConditionContext):
12
+ super().exitCondition(ctx)
13
+ self.nodes[ctx] = Condition(self.nodes[ctx.cond_expression()])
14
+
15
+ def exitUnaryExprNum(self, ctx: GrammarParser.UnaryExprNumContext):
16
+ super().exitUnaryExprNum(ctx)
17
+ node = UnaryOp(
18
+ op=ctx.op.text,
19
+ expr=self.nodes[ctx.num_expression()],
20
+ )
21
+ self.nodes[ctx] = node
22
+
23
+ def exitFuncExprNum(self, ctx: GrammarParser.FuncExprNumContext):
24
+ super().exitFuncExprNum(ctx)
25
+ node = UFunc(
26
+ func=ctx.function.text,
27
+ expr=self.nodes[ctx.num_expression()],
28
+ )
29
+ self.nodes[ctx] = node
30
+
31
+ def exitBinaryExprNum(self, ctx: GrammarParser.BinaryExprNumContext):
32
+ super().exitBinaryExprNum(ctx)
33
+ node = BinaryOp(
34
+ expr1=self.nodes[ctx.num_expression(0)],
35
+ op=ctx.op.text,
36
+ expr2=self.nodes[ctx.num_expression(1)],
37
+ )
38
+ self.nodes[ctx] = node
39
+
40
+ def exitLiteralExprNum(self, ctx: GrammarParser.LiteralExprNumContext):
41
+ super().exitLiteralExprNum(ctx)
42
+ self.nodes[ctx] = self.nodes[ctx.num_literal()]
43
+
44
+ def exitMathConstExprNum(self, ctx: GrammarParser.MathConstExprNumContext):
45
+ super().exitMathConstExprNum(ctx)
46
+ self.nodes[ctx] = self.nodes[ctx.math_const()]
47
+
48
+ def exitParenExprNum(self, ctx: GrammarParser.ParenExprNumContext):
49
+ super().exitParenExprNum(ctx)
50
+ node = Paren(self.nodes[ctx.num_expression()])
51
+ self.nodes[ctx] = node
52
+
53
+ def exitIdExprNum(self, ctx: GrammarParser.IdExprNumContext):
54
+ super().exitIdExprNum(ctx)
55
+ node = Name(ctx.getText())
56
+ self.nodes[ctx] = node
57
+
58
+ def exitBinaryExprFromNumCond(self, ctx: GrammarParser.BinaryExprFromNumCondContext):
59
+ super().exitBinaryExprFromNumCond(ctx)
60
+ node = BinaryOp(
61
+ expr1=self.nodes[ctx.num_expression(0)],
62
+ op=ctx.op.text,
63
+ expr2=self.nodes[ctx.num_expression(1)],
64
+ )
65
+ self.nodes[ctx] = node
66
+
67
+ def exitBinaryExprFromCondCond(self, ctx: GrammarParser.BinaryExprFromCondCondContext):
68
+ super().exitBinaryExprFromNumCond(ctx)
69
+ node = BinaryOp(
70
+ expr1=self.nodes[ctx.cond_expression(0)],
71
+ op=ctx.op.text,
72
+ expr2=self.nodes[ctx.cond_expression(1)],
73
+ )
74
+ self.nodes[ctx] = node
75
+
76
+ def exitBinaryExprCond(self, ctx: GrammarParser.BinaryExprCondContext):
77
+ super().exitBinaryExprCond(ctx)
78
+ node = BinaryOp(
79
+ expr1=self.nodes[ctx.cond_expression(0)],
80
+ op=ctx.op.text,
81
+ expr2=self.nodes[ctx.cond_expression(1)],
82
+ )
83
+ self.nodes[ctx] = node
84
+
85
+ def exitUnaryExprCond(self, ctx: GrammarParser.UnaryExprCondContext):
86
+ super().exitUnaryExprCond(ctx)
87
+ node = UnaryOp(
88
+ op=ctx.op.text,
89
+ expr=self.nodes[ctx.cond_expression()],
90
+ )
91
+ self.nodes[ctx] = node
92
+
93
+ def exitParenExprCond(self, ctx: GrammarParser.ParenExprCondContext):
94
+ super().exitParenExprCond(ctx)
95
+ node = Paren(self.nodes[ctx.cond_expression()])
96
+ self.nodes[ctx] = node
97
+
98
+ def exitLiteralExprCond(self, ctx: GrammarParser.LiteralExprCondContext):
99
+ super().exitLiteralExprCond(ctx)
100
+ self.nodes[ctx] = self.nodes[ctx.bool_literal()]
101
+
102
+ def exitNum_literal(self, ctx: GrammarParser.Num_literalContext):
103
+ super().exitNum_literal(ctx)
104
+ if ctx.INT():
105
+ node = Integer(str(ctx.INT()))
106
+ elif ctx.FLOAT():
107
+ node = Float(str(ctx.FLOAT()))
108
+ elif ctx.HEX_INT():
109
+ node = HexInt(str(ctx.HEX_INT()))
110
+ else:
111
+ assert False, f'Should not reach this line - {ctx!r}.' # pragma: no cover
112
+ self.nodes[ctx] = node
113
+
114
+ def exitBool_literal(self, ctx: GrammarParser.Bool_literalContext):
115
+ super().exitBool_literal(ctx)
116
+ node = Boolean(ctx.getText().lower())
117
+ self.nodes[ctx] = node
118
+
119
+ def exitMath_const(self, ctx: GrammarParser.Math_constContext):
120
+ super().exitMath_const(ctx)
121
+ node = Constant(ctx.getText())
122
+ self.nodes[ctx] = node
123
+
124
+ def exitOperation_program(self, ctx: GrammarParser.Operation_programContext):
125
+ super().exitOperation_program(ctx)
126
+ self.nodes[ctx] = Operation([self.nodes[stat] for stat in ctx.operational_assignment()])
127
+
128
+ def exitPreamble_program(self, ctx: GrammarParser.Preamble_programContext):
129
+ super().exitPreamble_program(ctx)
130
+ self.nodes[ctx] = Preamble([self.nodes[stat] for stat in ctx.preamble_statement()])
131
+
132
+ def exitPreamble_statement(self, ctx: GrammarParser.Preamble_statementContext):
133
+ super().exitPreamble_statement(ctx)
134
+ self.nodes[ctx] = self.nodes[ctx.initial_assignment() or ctx.constant_definition()]
135
+
136
+ def exitInitial_assignment(self, ctx: GrammarParser.Initial_assignmentContext):
137
+ super().exitInitial_assignment(ctx)
138
+ self.nodes[ctx] = InitialAssignment(
139
+ name=str(ctx.ID()),
140
+ expr=self.nodes[ctx.init_expression()],
141
+ )
142
+
143
+ def exitConstant_definition(self, ctx: GrammarParser.Constant_definitionContext):
144
+ super().exitConstant_definition(ctx)
145
+ self.nodes[ctx] = ConstantDefinition(
146
+ name=str(ctx.ID()),
147
+ expr=self.nodes[ctx.init_expression()],
148
+ )
149
+
150
+ def exitOperational_assignment(self, ctx: GrammarParser.Operational_assignmentContext):
151
+ super().exitOperational_assignment(ctx)
152
+ self.nodes[ctx] = OperationalDeprecatedAssignment(
153
+ name=str(ctx.ID()),
154
+ expr=self.nodes[ctx.num_expression()],
155
+ )
156
+
157
+ def exitFuncExprInit(self, ctx: GrammarParser.FuncExprInitContext):
158
+ super().exitFuncExprInit(ctx)
159
+ self.nodes[ctx] = UFunc(
160
+ func=ctx.function.text,
161
+ expr=self.nodes[ctx.init_expression()],
162
+ )
163
+
164
+ def exitUnaryExprInit(self, ctx: GrammarParser.UnaryExprInitContext):
165
+ super().exitUnaryExprInit(ctx)
166
+ self.nodes[ctx] = UnaryOp(
167
+ op=ctx.op.text,
168
+ expr=self.nodes[ctx.init_expression()],
169
+ )
170
+
171
+ def exitBinaryExprInit(self, ctx: GrammarParser.BinaryExprInitContext):
172
+ super().exitBinaryExprInit(ctx)
173
+ self.nodes[ctx] = BinaryOp(
174
+ expr1=self.nodes[ctx.init_expression(0)],
175
+ op=ctx.op.text,
176
+ expr2=self.nodes[ctx.init_expression(1)],
177
+ )
178
+
179
+ def exitLiteralExprInit(self, ctx: GrammarParser.LiteralExprInitContext):
180
+ super().exitLiteralExprInit(ctx)
181
+ self.nodes[ctx] = self.nodes[ctx.num_literal()]
182
+
183
+ def exitMathConstExprInit(self, ctx: GrammarParser.MathConstExprInitContext):
184
+ super().exitMathConstExprInit(ctx)
185
+ self.nodes[ctx] = self.nodes[ctx.math_const()]
186
+
187
+ def exitParenExprInit(self, ctx: GrammarParser.ParenExprInitContext):
188
+ super().exitParenExprInit(ctx)
189
+ self.nodes[ctx] = Paren(self.nodes[ctx.init_expression()])
190
+
191
+ def exitConditionalCStyleExprNum(self, ctx: GrammarParser.ConditionalCStyleExprNumContext):
192
+ super().exitConditionalCStyleExprNum(ctx)
193
+ self.nodes[ctx] = ConditionalOp(
194
+ cond=self.nodes[ctx.cond_expression()],
195
+ value_true=self.nodes[ctx.num_expression(0)],
196
+ value_false=self.nodes[ctx.num_expression(1)],
197
+ )
198
+
199
+ def exitConditionalCStyleCondNum(self, ctx: GrammarParser.ConditionalCStyleCondNumContext):
200
+ super().exitConditionalCStyleCondNum(ctx)
201
+ self.nodes[ctx] = ConditionalOp(
202
+ cond=self.nodes[ctx.cond_expression(0)],
203
+ value_true=self.nodes[ctx.cond_expression(1)],
204
+ value_false=self.nodes[ctx.cond_expression(2)],
205
+ )
206
+
207
+ def exitDef_assignment(self, ctx: GrammarParser.Def_assignmentContext):
208
+ super().exitDef_assignment(ctx)
209
+ self.nodes[ctx] = DefAssignment(
210
+ name=str(ctx.ID()),
211
+ type=ctx.deftype.text,
212
+ expr=self.nodes[ctx.init_expression()],
213
+ )
214
+
215
+ def exitState_machine_dsl(self, ctx: GrammarParser.State_machine_dslContext):
216
+ super().exitState_machine_dsl(ctx)
217
+ self.nodes[ctx] = StateMachineDSLProgram(
218
+ definitions=[self.nodes[item] for item in ctx.def_assignment()],
219
+ root_state=self.nodes[ctx.state_definition()],
220
+ )
221
+
222
+ def exitLeafStateDefinition(self, ctx: GrammarParser.LeafStateDefinitionContext):
223
+ super().exitLeafStateDefinition(ctx)
224
+ self.nodes[ctx] = StateDefinition(
225
+ name=str(ctx.ID()),
226
+ substates=[],
227
+ transitions=[],
228
+ enters=[],
229
+ durings=[],
230
+ exits=[],
231
+ )
232
+
233
+ def exitCompositeStateDefinition(self, ctx: GrammarParser.CompositeStateDefinitionContext):
234
+ super().exitCompositeStateDefinition(ctx)
235
+ self.nodes[ctx] = StateDefinition(
236
+ name=str(ctx.ID()),
237
+ substates=[self.nodes[item] for item in ctx.state_inner_statement()
238
+ if item in self.nodes and isinstance(self.nodes[item], StateDefinition)],
239
+ transitions=[self.nodes[item] for item in ctx.state_inner_statement()
240
+ if item in self.nodes and isinstance(self.nodes[item], TransitionDefinition)],
241
+ enters=[self.nodes[item] for item in ctx.state_inner_statement()
242
+ if item in self.nodes and isinstance(self.nodes[item], EnterStatement)],
243
+ durings=[self.nodes[item] for item in ctx.state_inner_statement()
244
+ if item in self.nodes and isinstance(self.nodes[item], DuringStatement)],
245
+ exits=[self.nodes[item] for item in ctx.state_inner_statement()
246
+ if item in self.nodes and isinstance(self.nodes[item], ExitStatement)],
247
+ during_aspects=[self.nodes[item] for item in ctx.state_inner_statement()
248
+ if item in self.nodes and isinstance(self.nodes[item], DuringAspectStatement)],
249
+ force_transitions=[self.nodes[item] for item in ctx.state_inner_statement()
250
+ if item in self.nodes and isinstance(self.nodes[item], ForceTransitionDefinition)],
251
+ )
252
+
253
+ def exitEntryTransitionDefinition(self, ctx: GrammarParser.EntryTransitionDefinitionContext):
254
+ super().exitEntryTransitionDefinition(ctx)
255
+ self.nodes[ctx] = TransitionDefinition(
256
+ from_state=INIT_STATE,
257
+ to_state=ctx.to_state.text,
258
+ event_id=self.nodes[ctx.chain_id()] if ctx.chain_id() else None,
259
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
260
+ post_operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
261
+ )
262
+
263
+ def exitNormalTransitionDefinition(self, ctx: GrammarParser.NormalTransitionDefinitionContext):
264
+ super().exitNormalTransitionDefinition(ctx)
265
+ event_id = None
266
+ if ctx.chain_id():
267
+ event_id = self.nodes[ctx.chain_id()]
268
+ elif ctx.from_id:
269
+ event_id = ChainID([ctx.from_state.text, ctx.from_id.text])
270
+ self.nodes[ctx] = TransitionDefinition(
271
+ from_state=ctx.from_state.text,
272
+ to_state=ctx.to_state.text,
273
+ event_id=event_id,
274
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
275
+ post_operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
276
+ )
277
+
278
+ def exitExitTransitionDefinition(self, ctx: GrammarParser.ExitTransitionDefinitionContext):
279
+ super().exitExitTransitionDefinition(ctx)
280
+ event_id = None
281
+ if ctx.chain_id():
282
+ event_id = self.nodes[ctx.chain_id()]
283
+ elif ctx.from_id:
284
+ event_id = ChainID([ctx.from_state.text, ctx.from_id.text])
285
+ self.nodes[ctx] = TransitionDefinition(
286
+ from_state=ctx.from_state.text,
287
+ to_state=EXIT_STATE,
288
+ event_id=event_id,
289
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
290
+ post_operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
291
+ )
292
+
293
+ def exitChain_id(self, ctx: GrammarParser.Chain_idContext):
294
+ super().exitChain_id(ctx)
295
+ self.nodes[ctx] = ChainID(
296
+ path=list(map(str, ctx.ID())),
297
+ is_absolute=bool(ctx.isabs),
298
+ )
299
+
300
+ def exitOperational_statement(self, ctx: GrammarParser.Operational_statementContext):
301
+ super().exitOperational_statement(ctx)
302
+ if ctx.operation_assignment():
303
+ self.nodes[ctx] = self.nodes[ctx.operation_assignment()]
304
+
305
+ def exitState_inner_statement(self, ctx: GrammarParser.State_inner_statementContext):
306
+ super().exitState_inner_statement(ctx)
307
+ if ctx.state_definition():
308
+ self.nodes[ctx] = self.nodes[ctx.state_definition()]
309
+ elif ctx.transition_definition():
310
+ self.nodes[ctx] = self.nodes[ctx.transition_definition()]
311
+ elif ctx.enter_definition():
312
+ self.nodes[ctx] = self.nodes[ctx.enter_definition()]
313
+ elif ctx.during_definition():
314
+ self.nodes[ctx] = self.nodes[ctx.during_definition()]
315
+ elif ctx.exit_definition():
316
+ self.nodes[ctx] = self.nodes[ctx.exit_definition()]
317
+ elif ctx.during_aspect_definition():
318
+ self.nodes[ctx] = self.nodes[ctx.during_aspect_definition()]
319
+ elif ctx.transition_force_definition():
320
+ self.nodes[ctx] = self.nodes[ctx.transition_force_definition()]
321
+
322
+ def exitOperation_assignment(self, ctx: GrammarParser.Operation_assignmentContext):
323
+ super().exitOperation_assignment(ctx)
324
+ self.nodes[ctx] = OperationAssignment(
325
+ name=str(ctx.ID()),
326
+ expr=self.nodes[ctx.num_expression()],
327
+ )
328
+
329
+ def exitEnterOperations(self, ctx: GrammarParser.EnterOperationsContext):
330
+ super().exitEnterOperations(ctx)
331
+ self.nodes[ctx] = EnterOperations(
332
+ name=ctx.func_name.text if ctx.func_name else None,
333
+ operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes],
334
+ )
335
+
336
+ def exitEnterAbstractFunc(self, ctx: GrammarParser.EnterAbstractFuncContext):
337
+ super().exitEnterAbstractFunc(ctx)
338
+ self.nodes[ctx] = EnterAbstractFunction(
339
+ name=ctx.func_name.text if ctx.func_name else None,
340
+ doc=format_multiline_comment(ctx.raw_doc.text) if ctx.raw_doc else None,
341
+ )
342
+
343
+ def exitExitOperations(self, ctx: GrammarParser.ExitOperationsContext):
344
+ super().exitExitOperations(ctx)
345
+ self.nodes[ctx] = ExitOperations(
346
+ name=ctx.func_name.text if ctx.func_name else None,
347
+ operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
348
+ )
349
+
350
+ def exitExitAbstractFunc(self, ctx: GrammarParser.ExitAbstractFuncContext):
351
+ super().exitExitAbstractFunc(ctx)
352
+ self.nodes[ctx] = ExitAbstractFunction(
353
+ name=ctx.func_name.text if ctx.func_name else None,
354
+ doc=format_multiline_comment(ctx.raw_doc.text) if ctx.raw_doc else None,
355
+ )
356
+
357
+ def exitDuringOperations(self, ctx: GrammarParser.DuringOperationsContext):
358
+ super().exitDuringOperations(ctx)
359
+ self.nodes[ctx] = DuringOperations(
360
+ name=ctx.func_name.text if ctx.func_name else None,
361
+ aspect=ctx.aspect.text if ctx.aspect else None,
362
+ operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
363
+ )
364
+
365
+ def exitDuringAbstractFunc(self, ctx: GrammarParser.DuringAbstractFuncContext):
366
+ super().exitDuringAbstractFunc(ctx)
367
+ self.nodes[ctx] = DuringAbstractFunction(
368
+ name=ctx.func_name.text if ctx.func_name else None,
369
+ aspect=ctx.aspect.text if ctx.aspect else None,
370
+ doc=format_multiline_comment(ctx.raw_doc.text) if ctx.raw_doc else None,
371
+ )
372
+
373
+ def exitGeneric_expression(self, ctx: GrammarParser.Generic_expressionContext):
374
+ if ctx.num_expression():
375
+ self.nodes[ctx] = self.nodes[ctx.num_expression()]
376
+ elif ctx.cond_expression():
377
+ self.nodes[ctx] = self.nodes[ctx.cond_expression()]
378
+
379
+ def exitDuringAspectOperations(self, ctx: GrammarParser.DuringAspectOperationsContext):
380
+ super().exitDuringAspectOperations(ctx)
381
+ self.nodes[ctx] = DuringAspectOperations(
382
+ name=ctx.func_name.text if ctx.func_name else None,
383
+ aspect=ctx.aspect.text if ctx.aspect else None,
384
+ operations=[self.nodes[item] for item in ctx.operational_statement() if item in self.nodes]
385
+ )
386
+
387
+ def exitDuringAspectAbstractFunc(self, ctx: GrammarParser.DuringAspectAbstractFuncContext):
388
+ super().exitDuringAspectAbstractFunc(ctx)
389
+ self.nodes[ctx] = DuringAspectAbstractFunction(
390
+ name=ctx.func_name.text if ctx.func_name else None,
391
+ aspect=ctx.aspect.text if ctx.aspect else None,
392
+ doc=format_multiline_comment(ctx.raw_doc.text) if ctx.raw_doc else None,
393
+ )
394
+
395
+ def exitNormalForceTransitionDefinition(self, ctx: GrammarParser.NormalForceTransitionDefinitionContext):
396
+ super().exitNormalForceTransitionDefinition(ctx)
397
+ event_id = None
398
+ if ctx.chain_id():
399
+ event_id = self.nodes[ctx.chain_id()]
400
+ elif ctx.from_id:
401
+ event_id = ChainID([ctx.from_state.text, ctx.from_id.text])
402
+ self.nodes[ctx] = ForceTransitionDefinition(
403
+ from_state=ctx.from_state.text,
404
+ to_state=ctx.to_state.text,
405
+ event_id=event_id,
406
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
407
+ )
408
+
409
+ def exitExitForceTransitionDefinition(self, ctx: GrammarParser.ExitForceTransitionDefinitionContext):
410
+ super().exitExitForceTransitionDefinition(ctx)
411
+ event_id = None
412
+ if ctx.chain_id():
413
+ event_id = self.nodes[ctx.chain_id()]
414
+ elif ctx.from_id:
415
+ event_id = ChainID([ctx.from_state.text, ctx.from_id.text])
416
+ self.nodes[ctx] = ForceTransitionDefinition(
417
+ from_state=ctx.from_state.text,
418
+ to_state=EXIT_STATE,
419
+ event_id=event_id,
420
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
421
+ )
422
+
423
+ def exitNormalAllForceTransitionDefinition(self, ctx: GrammarParser.NormalAllForceTransitionDefinitionContext):
424
+ super().exitNormalAllForceTransitionDefinition(ctx)
425
+ self.nodes[ctx] = ForceTransitionDefinition(
426
+ from_state=ALL,
427
+ to_state=ctx.to_state.text,
428
+ event_id=self.nodes[ctx.chain_id()] if ctx.chain_id() else None,
429
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
430
+ )
431
+
432
+ def exitExitAllForceTransitionDefinition(self, ctx: GrammarParser.ExitAllForceTransitionDefinitionContext):
433
+ super().exitExitAllForceTransitionDefinition(ctx)
434
+ # print(self.nodes[ctx.chain_id()] if ctx.chain_id() else None)
435
+ self.nodes[ctx] = ForceTransitionDefinition(
436
+ from_state=ALL,
437
+ to_state=EXIT_STATE,
438
+ event_id=self.nodes[ctx.chain_id()] if ctx.chain_id() else None,
439
+ condition_expr=self.nodes[ctx.cond_expression()] if ctx.cond_expression() else None,
440
+ )