Skip to main content

General purpose preprocessor written in Python

Project description

Prologue

Tests

Prologue is an extensible text preprocessor written in Python. It performs evaluation in a continuous stream, which allows it to run fast and keep a minimal memory footprint with few open file handles.

Directives can be easily added and removed to customise the behaviour of the preprocessor. By default the following directives are supported:

  • define/undef - allows constants to be declared and undeclared
  • if/elif/else/endif - conditional inclusion of blocks of text/other preprocessor directives
  • ifdef/ifndef/else/endif - test whether constants are defined or undefined
  • for/endfor - repeat a block of text for a number of iterations, can also iterate through an array
  • info/warning/error - print messages to a log, or raise an exception, from a directive
  • include/import - allows other files to be included or imported (one time include) into the stream

Example

Input

#define MY_VAL 123
#undef MY_VAL
#define MY_VAL 256

int main() {
#if MY_VAL > 200
    printf("Big value\n");
#else
    printf("Small value\n");
#endif
}

Script

from prologue import Prologue
pro = Prologue()
pro.add_file("path/to/main.c")
for line in pro.evaluate("main.c"):
    print(line)

Output

int main() {
    printf("Big value\n");
}

Examples

A number of examples are available in the examples folder:

  • demo - is a demonstration of many features of Prologue, including loops, conditionals, include and import.
  • c_style - demonstrates how Prologue can be setup to act like GCC's preprocessor.
  • verilog - demonstrates how Prologue can be setup to act like a Verilog/SystemVerilog preprocessor.

Running Tests

Prologue comes with a suite of tests, which use pytest for regression:

$> git clone git@github.com:Intuity/prologue
$> cd prologue
$> python3 setup.py test

Still To Do

Some features that still need to be implemented are:

  • Support for C-style substitution delimiters to provide separation - for example NUMBER_##A_CONST##_IS_THE_BEST
  • Support for macro functions with nested support - for example #define SUM(A, B) A + B

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

prologue-1.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

prologue-1.0-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file prologue-1.0.tar.gz.

File metadata

  • Download URL: prologue-1.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for prologue-1.0.tar.gz
Algorithm Hash digest
SHA256 30142dd08245f9a40479088173bda0a8b297f15988b239107dee8820f423446f
MD5 5c96f7846979ebe41c6a42602e0c1938
BLAKE2b-256 24237b2f2eb02cc220618434a0d3ac2f00a2adc0a4ddcd3635a95bd5af0b70d9

See more details on using hashes here.

File details

Details for the file prologue-1.0-py3-none-any.whl.

File metadata

  • Download URL: prologue-1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for prologue-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a10b9ca7b4d27b334b862ab7e62adf129c01e8204c0dde1b3093d5fd27d9ca3
MD5 f5f885dfcb7ed65e5da28254734ca1eb
BLAKE2b-256 7c1622e23298f8b1d2e4c2109a87e37b8108836287e34d2483285694f258e8ea

See more details on using hashes here.

Supported by

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