Skip to main content

A Python source-code generator based on the ``compiler.ast`` abstract syntax tree.

Project description

Overview

This package provides a module-level source-code generator which operates on the AST from the built-in compiler.ast module.

Note that this AST is not compatible with the new ast module in Python 2.6.

Usage

The generator works on AST parse trees.

>>> from compiler import parse
>>> tree = parse("""\
...     print 'Hello, world!'
... """)

We can now generate Python-code equivalent to the original using the source-code generator.

>>> from sourcecodegen import ModuleSourceCodeGenerator
>>> generator = ModuleSourceCodeGenerator(tree)
>>> print generator.getSourceCode()
print 'Hello, world!'

Author

Malthe Borch <mborch@gmail.com>

Changelog

0.6.2 (released 14/12/2008)

  • Fixed issue where lambda blocks would be incorrectly indented; also, function bodies are now always properly cleared. [malthe]

0.6.1 (released 13/12/2008)

  • Fixed issue where generators would not be prioritized in certain cases. [malthe]

0.6 (released 13/12/2008)

  • Operator precedence is now taken into account such that we can avoid unnecessary use of parentheses. This is done not only for aesthetic reasons, but more importantly to avoid running into parser errors due to Python’s nesting limitation. [malthe]

0.5 (released 28/11/2008)

  • Added yield and unary operators. [malthe]

0.4 (released 28/11/2008)

  • Make sure all binary operators get parentheses around them; we may be able to improve upon this in the future (for legibility-reasons). [malthe]

0.3 (released 27/11/2008)

  • Added logical operators. [malthe]

  • Fixed tuple unpacking issues. [malthe]

  • Added for-loop. [malthe]

0.2 (released 27/11/2008)

  • Fixed issue with tuples and parentheses. [malthe]

  • Fixed issue with multiple assignments. [malthe]

  • Added support for not operator. [malthe]

  • Fixed issue where default arguments would be written incorrectly if no non-keyword arguments were present. [malthe]

  • Fixed issue where statements would not be cleared properly. [malthe]

  • Assignments are statements and should terminate. [malthe]

0.1 (released 26/11/2008)

  • Initial release.

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

sourcecodegen-0.6.2.tar.gz (11.4 kB view details)

Uploaded Source

File details

Details for the file sourcecodegen-0.6.2.tar.gz.

File metadata

  • Download URL: sourcecodegen-0.6.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sourcecodegen-0.6.2.tar.gz
Algorithm Hash digest
SHA256 8092631297defcff57e9c1ff5f4dca6ea8d158d698d84197511ae4eb5f9eb748
MD5 cb6aafe946d7a8e266dcddadbf35304a
BLAKE2b-256 6db03faf297d482838c72f84f483182e87d306787ce2cd06e1ce9a2c1f9c9ff9

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