Parser and translator for the pseudocode language used in SMPTE ST 2042-1 (VC-2) standards documents.
Project description
SMPTE ST 2042-1 VC-2 Pseudocode Language Parsing Software
This repository contains software tools for parsing the pseudocode language used in the SMPTE ST 2042-1 (VC-2) professional video codec specification documents.
As well as a parser capable of generating Abstract Syntax Trees (ASTs) for pseudocode listings, tools are also provided for translating the pseudocode language into Python and also pretty-printed, syntax highlighted Word documents for inclusions in specifications.
Installation
To install from PyPI use:
$ pip install vc2_pseudocode_parser
Alternatively, to install directly from a checkout of this repository:
$ python setup.py install --user
This software requires Python 3.6 or later.
To enable support for generating Word documents, python-docx
must also be
installed (e.g. using pip install python-docx
).
Example usage
As an example, consider the following pseudocode listing:
color_spec(state, video_parameters):
# (11.4.10.1)
custom_color_spec_flag = read_bool(state)
if (custom_color_spec_flag):
index = read_uint(state)
preset_color_spec(video_parameters, index)
# NB: index 0 is 'custom'
if (index == 0):
color_primaries(state, video_parameters) # 11.3.9.1
color_matrix(state, video_parameters) # 11.3.9.2
transfer_function(state, video_parameters) # 11.3.9.3
This may be converted into Python as follows:
$ vc2-pseudocode-to-python listing.pc listing.py
$ cat listing.py
# This file was automatically translated from a pseudocode listing.
def color_spec(state, video_parameters):
"""
(11.4.10.1)
"""
custom_color_spec_flag = read_bool(state)
if custom_color_spec_flag:
index = read_uint(state)
preset_color_spec(video_parameters, index)
# NB: index 0 is 'custom'
if index == 0:
color_primaries(state, video_parameters) # 11.3.9.1
color_matrix(state, video_parameters) # 11.3.9.2
transfer_function(state, video_parameters) # 11.3.9.3
Or into a Word document with tabular listings as follows:
$ vc2-pseudocode-to-docx listing.pc listing.docx
For a more thorough introduction, see the vc2_pseudocode_parser
manual (also available in PDF
format).
Development
Testing dependencies may be installed using:
$ pip install -r requirements-test.txt
Tests are then run using:
$ py.test
Though typechecking (using MyPy) is performed as part of the test suite, it may be run manually using:
$ ./run_mypy.sh
Documentation build dependencies can be obtained using:
$ pip install -r requirements-docs.txt
And the documentation built using:
$ make -C docs html latexpdf
Experimental software
The tools in this repository are experimental in nature. They are part of an informal thread of work to see how enhanced machine readability of pseudocode specifications may prove valuable to implementers and specification authors alike. Contact Jonathan Heathcote or John Fletcher for more information.
License
This software is distributed under the GNU General Public License version 3, © BBC 2021.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for vc2_pseudocode_parser-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfcd8b14d9ba06ff2ef5b6d5eb5cb5ac56896fda6810a4cca625be4bc5e86b01 |
|
MD5 | 4e635c4077136eab6a12393494342164 |
|
BLAKE2b-256 | d6128080893d2ab2fa0433a033b7cfd64daf06678ed7f499abf7ff0598c85f92 |
Hashes for vc2_pseudocode_parser-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b36cbb0be1e7246f3a5b85cbb79fa5fb38226449f392612020e13993a556a78d |
|
MD5 | 5222f5b2805a12d209f332b135b41a27 |
|
BLAKE2b-256 | b2ee17c3db38dbed61e24b7e950bc15669e7ea2481c2d5c92e89ad038ffaaa7d |