https://github.com/microhod/magma_output_parser
Parser for magma group output files
https://github.com/microhod/magma_output_parser
Last synced: 5 months ago
JSON representation
Parser for magma group output files
- Host: GitHub
- URL: https://github.com/microhod/magma_output_parser
- Owner: microhod
- License: mit
- Created: 2024-06-22T15:48:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-07T09:30:40.000Z (about 1 year ago)
- Last Synced: 2025-06-07T10:26:11.223Z (about 1 year ago)
- Language: Python
- Size: 142 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://doi.org/10.5281/zenodo.12520164)
# Magma Output File Parser
This repo implements a parser for group record outputs from the computational algebra program [Magma](http://magma.maths.usyd.edu.au/magma/).
⚠️ This repo is experimential and not particularly generic, it's not meant as a parser for ANY form of magma output (although the grammar may provide a decent starting point for this so feel free to fork).
This repo provides:
* [magma_parser](./magma_parser/) a module for parsing magma group output files (see [tests/testdata](./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](./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)
## Running the script
Install requirements with [pip](https://pip.pypa.io/en/stable/) (use a [virtualenv](https://virtualenv.pypa.io/en/latest/) if you like them):
```shell
pip install -r requirements.txt
```
Then run the script.
```shell
python3 magma.py '[INPUT_FILE]' '[OUTPUT_DIRECTORY]' '[WRITER=csv|xlsx]'
```
Defaults:
* `OUTPUT_DIRECTORY`: the current directory
* `WRITER`: `xlsx`
## `magma_parser`
The parser is implemented using [ANTLR](https://www.antlr.org/), which allows us to describe the structure of the files in a [formal grammar](https://en.wikipedia.org/wiki/Formal_grammar) and have the parser generated automatically.
The grammar files are stored in the [magma_parser/grammar](./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`
```shell
pip install -r requirements-dev.txt
```
### Updating the generated files
From the [magma_parser](./magma_parser/) directory, just run [build.sh](./magma_parser/build.sh) to regenerate the generated parser files after a grammar change.