summaryrefslogtreecommitdiff
path: root/lib/automata.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-03-04 15:15:54 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-03-04 15:16:10 +0100
commit4e37798145fa03bd90880f4ac315529190472eaf (patch)
treed6051e435941d9a4a9ea21f81624d87be1d818b9 /lib/automata.py
parent9abd39d11da2db4d5804d4e8199578bfa3aa9164 (diff)
generate PTA from YAML model, support several types of test harness
Diffstat (limited to 'lib/automata.py')
-rwxr-xr-xlib/automata.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/automata.py b/lib/automata.py
index 922cdaf..96a724e 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -365,6 +365,38 @@ class PTA:
return pta
+ @classmethod
+ def from_yaml(cls, yaml_input: dict):
+ """Return a PTA created from the YAML DFA format (passed as dict)."""
+
+ kwargs = dict()
+
+ if 'parameters' in yaml_input:
+ kwargs['parameters'] = yaml_input['parameters']
+
+ if 'initial_param_values' in yaml_input:
+ kwargs['initial_param_values'] = yaml_input['initial_param_values']
+
+ if 'states' in yaml_input:
+ kwargs['state_names'] = yaml_input['states']
+
+ pta = cls(**kwargs)
+
+ for trans_name in sorted(yaml_input['transition'].keys()):
+ transition = yaml_input['transition'][trans_name]
+ arguments = list()
+ argument_values = list()
+ is_interrupt = False
+ if 'arguments' in transition:
+ for argument in transition['arguments']:
+ arguments.append(argument['name'])
+ argument_values.append(argument['values'])
+ for origin in transition['src']:
+ pta.add_transition(origin, transition['dst'], trans_name,
+ arguments = arguments, argument_values = argument_values)
+
+ return pta
+
def to_json(self) -> dict:
"""
Return JSON encoding of this PTA.