Skip to content

microhod/magma_output_parser

Repository files navigation

DOI

Magma Output File Parser

This repo implements a parser for group record outputs from the computational algebra program 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 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)

Running the script

Install requirements with pip (use a virtualenv if you like them):

pip install -r requirements.txt

Then run the script.

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, 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.txt

Updating the generated files

From the magma_parser directory, just run build.sh to regenerate the generated parser files after a grammar change.

About

Parser for magma group output files

Resources

License

Stars

Watchers

Forks

Packages

No packages published