Skip to main content

Python wrapper for XML output generator for Open Fortran Parser

Project description

XML output generator for Open Fortran Parser

build status from Travis CI license

Implementation has 2 parts: the XML generator written in Java, and Python wrapper for the generator.

In this file, first the Java implementation is described and then the Python wrapper.

Java XML generator for OFP

This is an extension of Open Fortran Parser (OFP), which outputs abstract syntaxt tree (AST) of parsed Fortran file in XML format - to a file or to System.out.

dependencies

how to build

Get dependencies, either manually, or using the provided script:

python3 open_fortran_parser/dev_dependencies.py
export CLASSPATH="${CLASSPATH}:$(pwd)/lib/*"

Build:

ant
export CLASSPATH="${CLASSPATH}:$(pwd)/dist/*"

This will create a .jar file in dist directory.

how to run

java fortran.ofp.FrontEnd --class fortran.ofp.XMLPrinter \
  --output output.xml --verbosity 0~100 input.f

where:

  • The --verbosity flag controls verbosity of the parse tree. Defaluts to 100 when omitted.

    • Maximum, 100, means that all details picked up by Open Fortran Parser will be preserved.

    • Minimum, 0, means that tree will contain only what is needed to reconstruct the program without changing it’s meaning.

  • The --output flag controls where the XML should be written. Defaults to standard output when omitted.

and remaining command-line options are exactly as defined in OFP 0.8.4.

To parse some_fortran_file.f and save XML output in tree.xml with minimum verbosity:

java fortran.ofp.FrontEnd --class fortran.ofp.XMLPrinter \
  --output tree.xml --verbosity 0 some_fortran_file.f

And to dump XML with maximum verbosity to console:

java fortran.ofp.FrontEnd --class fortran.ofp.XMLPrinter \
  --verbosity 100 some_fortran_file.f

AST specification

Root node is <ofp>, it has one subnode <file>.

Combound statements, e.g.:

  • <if>

  • <loop>

each have <header> and <body>.

In the header of the <loop>, at least one <index-variable> is present. It has <lower-bound>, <upper-bound> and <step>.

Remaining specification is being prepared.

Python wrapper for the generator

package version from PyPI test coverage from Coveralls

Using the wrapper should not require any special knowledge about the generator itself, other than knowing the abstract syntax tree (AST) specification.

dependencies

Java 1.8.

Python version >= 3.6.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in dev_requirements.txt.

how to build

pip3 install -U -r dev_requirements.txt
python3 setup.py sdist --formats=gztar,zip
python3 setup.py bdist_wheel

how to run

The wrapper can be used as a script, or as a library.

Before running, however, please make sure that dependencies are configured correctly. You can do that by either following the “how to build” section for Java implementation above, or by executing this:

python3 open_fortran_parser/dependencies.py
export CLASSPATH="${CLASSPATH}:$(pwd)/lib/*"

as script

$ python3 -m open_fortran_parser -h
usage: open_fortran_parser [-h] [-v VERBOSITY] input [output]

Python wrapper around XML generator for Open Fortran Parser 0.8.4

positional arguments:
  input                 path to Fortran source code file
  output                writable path for where to store resulting XML,
                        defaults to stdout if no path provided (default: None)

optional arguments:
  -h, --help            show this help message and exit
  -v VERBOSITY, --verbosity VERBOSITY
                        level of verbosity, from 0 to 100 (default: 100)

Copyright 2017 Mateusz Bysiek https://mbdevpl.github.io/, Apache License 2.0

as library

from open_fortran_parser import parse

xml = parse('my_legacy_code.f', verbosity=0)

testing

python3 -m pylint --load-plugins=pylint.extensions.mccabe --docstring-min-length 5 \
  --no-docstring-rgx "^(test)?_|.*Tests$" --unsafe-load-any-extension y \
  --output-format colorized  --reports y $(find . -name "*.py")
python3 -m coverage run --branch -m unittest discover --verbose
python3 -m coverage report --show-missing
python3 -m coverage html

Project details


Download files

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

Source Distribution

open-fortran-parser-0.2.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

open_fortran_parser-0.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file open-fortran-parser-0.2.0.tar.gz.

File metadata

File hashes

Hashes for open-fortran-parser-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fc7b11956a69b765acaeb23e51686c93252cd1f5a5e53514acb812ce654843c0
MD5 6a9b785a5ad42d344f4008d8f39559af
BLAKE2b-256 7c01f6e7215b22aa5223087bdc7bc4f51573f17855a1d5bc3a327bbc050ecbf3

See more details on using hashes here.

File details

Details for the file open_fortran_parser-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for open_fortran_parser-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4188c28390e851a48364fdeaf4139f4a006b6f08d9cbde0c562fb1ef8fc7d935
MD5 e238259dccdc86848390318b74df2343
BLAKE2b-256 36129b19a58cebd5d994c08ee75f1efe46ed25f488f8bacc1348ec5b05cc27e7

See more details on using hashes here.

Supported by

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