This repo implements a parser for group record outputs from the computational algebra program Magma.
This repo provides:
- magma_parser a module for parsing magma group output files (see tests/testdata for examples of the file structures it supports).
- This was designed to not fit too tightly to only my usecase so it might be a useful reference for others. If there's any interest it could be broken out into a separate package.
- magma.py a script to parse a magma file and export to a CSV or Excel Spreadsheet (this is quite specific to my usecase so might not be of much use to anyone else)
Install requirements with pip (use a virtualenv if you like them):
pip install -r requirements.txtThen run the script.
python3 magma.py '[INPUT_FILE]' '[OUTPUT_DIRECTORY]' '[WRITER=csv|xlsx]'Defaults:
OUTPUT_DIRECTORY: the current directoryWRITER:xlsx
The parser is implemented using ANTLR, which allows us to describe the structure of the files in a formal grammar and have the parser generated automatically.
The grammar files are stored in the magma_parser/grammar directory. For developing these, it can be useful to have the antlr4-parse CLI tool, which can be installed from dev-requirements.txt
pip install -r requirements-dev.txtFrom the magma_parser directory, just run build.sh to regenerate the generated parser files after a grammar change.