Skip to main content

Executable State Model Parser

Parses an .xsm executable state model file into an abstract syntax tree for downstream Blueprint modules

Parses an *.xsm file (Executable State Model) to yield an abstract syntax tree using python named tuples

📖 The xsm modeling language is fully documented in the project wiki.

Why you need this

You need to process an *.xsm file in preparation for populating a database or some other purpose

Installation

Create or use a python 3.11+ environment. Then

% pip install xsm-parser

At this point you can invoke the parser via the command line or from your python script.

From your python script

You need this import statement at a minimum:

from xsm_parser.state_model_parser import StateModelParser

You then specify a path as shown:

result = StateModelParser.parse_file(file_input=path_to_file, debug=False)

Check the code in state_model_parser.py to verify I haven't changed these parameters on you without updating the readme.

In either case, result will be a StateModel_a named tuple holding the parsed state model elements (metadata, domain, lifecycle, assigner_rnum, assigner_pclass, initial_transitions, events and states). A state model is either a class lifecycle or a relationship assigner, so either lifecycle or the assigner_* fields will be filled in, never both. You may find the header of the state_model_visitor.py file helpful in interpreting these results.

From the command line

The xsm command checks a model file, and can render it as a table for reading and review. Since it may leave diagnostic output behind, you may want to create a fresh working directory and cd into it first. From there...

% xsm cabin.xsm

The .xsm extension is not necessary, but the file must contain xsm text. See this repository's wiki for more about the xsm language. The grammar is defined in the state_model.peg file. (if the link breaks after I do some update to the code, just browse through the code looking for the state_model.peg file, and let me know so I can fix it)

You can also specify a debug option like this:

% xsm cabin.xsm -D

This will create a diagnostics folder in your current working directory and deposit a couple of PDFs defining the parse of both the state model grammar: state_model.pdf and your supplied text: state_parse_tree.pdf.

Generating a state transition table

Add -t to write a markdown page presenting the model as a table:

% xsm cabin.xsm -t

You get cabin.md next to cabin.xsm, or somewhere else if you say so:

% xsm cabin.xsm -t -o docs

The page leads with a matrix of the wait states against the events, so you can see at a glance what each state does with each event. Below it, one section per state gives the reasoning behind every declared ignore and can't happen response, with reason tags resolved to the text they stand for.

Two things get flagged as you go. An event that no state answers at all is reported as a likely oversight. And a wait state that says nothing about an event that could actually arrive there is marked ? in the table and counted on the command line:

% xsm door.xsm -t
Wrote door.md
  6 interaction event response(s) not yet decided

Such a response defaults to can't happen, but nobody has said why — which is worth knowing, since it is the difference between a case that was considered and one that was overlooked.

You should also see a file named xsm_parser.log in your current working directory

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xsm_parser-1.0.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xsm_parser-1.0.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file xsm_parser-1.0.0.tar.gz.

File metadata

  • Download URL: xsm_parser-1.0.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for xsm_parser-1.0.0.tar.gz
Algorithm Hash digest
SHA256 322925fdf1e764fe77908e6593fa88467154bd4224732832e0fe5810339bb8a0
MD5 628f63e6b4a59d31a3d3b549b64fe03a
BLAKE2b-256 e61b235bdd0688647ed7c380308917126c582df445becb821b37ded6e07607ff

See more details on using hashes here.

File details

Details for the file xsm_parser-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: xsm_parser-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for xsm_parser-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8651a092ce1a38e7a5d0b4ab9b309a8bf0072bef3deacb219260aa982f9e011
MD5 596b97138f7e36d038628e5a0334836e
BLAKE2b-256 0799a25ed04bfbea4ac22c398f71128c7334ea58267f06955f14ba8243f6b396

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

This release

1.0.0 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page