statelyai / xstate-python

XState for Python
MIT License
179 stars 18 forks source link

Initial tags are not properly handled #27

Closed Aluriak closed 3 years ago

Aluriak commented 3 years ago

In current implementation, the initial state of a super state is the first sub-state, rather than the sub-state indicated in the initial tag.

SCXML example :

<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="SM">
    <state id="global" initial="A2">
        <state id="A1">
        </state>
        <state id="A2">
        </state>
    </state>
</scxml>

Xstate-python call:

print(scxml_to_machine(scxml_file))

Output:

{
  "id": "machine",
  "initial": "global",
  "states": {
    "global": {
      "type": null,
      "id": "global",
      "key": "global",
      "exit": null,
      "entry": null,
      "states": {
        "A1": {
          "type": null,
          "id": "A1",
          "key": "A1",
          "exit": null,
          "entry": null,
          "states": {},
          "initial": null
        },
        "A2": {
          "type": null,
          "id": "A2",
          "key": "A2",
          "exit": null,
          "entry": null,
          "states": {},
          "initial": null
        }
      },
      "initial": "A1"
    }
  }
}

I will try to come up with a merge request.