GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jvllmr/rustpython-unparser: A complete unparser for rustpython-parser ASTs (Codeberg mirror)

BranchesTags
Open more actions menu

Latest commit

 

History

114 Commits
114 Commits

Folders and files

NameName
Last commit message
Last commit date
.forgejo/workflows
.forgejo/workflows
 
 
.vscode
.vscode
 
 
fuzzy_test_files
fuzzy_test_files
 
 
fuzzy_test_files_unparsed
fuzzy_test_files_unparsed
 
 
src
src
 
 
test_files
test_files
 
 
test_files_unparsed
test_files_unparsed
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pdm.lock
pdm.lock
 
 
pyproject.toml
pyproject.toml
 
 
renovate.json
renovate.json
 
 

Repository files navigation

rustpython-unparser

Crates.io Downloads (latest version) Crates.io Version CI Badge

A complete unparser for rustpython-parser ASTs.

Acknowledgement

I created this library because I quickly needed a way to turn rustpython-parser ASTs back to some form of Python source code. Since the unparser contained within rustpython-ast only supports expressions and not statements, I started implementing my own unparser by taking heavy inspiration from rustpython's unparser and the unparser in the python standard library. Therefore, most credit goes to the respective teams behind the ast standard library module and RustPython. I only glued the parts I needed together to a complete unparser in this repository.

I personally don't use this crate anymore since I switched over to using ruff's internal AST, but I will still accept PRs. Feel free to contribute if you find out that you are missing something.

Contributing

You can already help a lot by reporting issues with generated code. If you find an issue,please provide example code of the original source and the unparsed source with a concise explanation.

If you would like to fix the issue yourself, you can create an example in one of the matching files in test_files or create a new file with your example if you think your example does not fit into any of the existing files. Then you can run the tests with cargo t and verify your changes by viewing your unparse example in the test_files_unparsed directory. After verifying your changes you can create a Pull Request. If your change is linked to a GitHub issue, please provide a comment in the form of # <link to github issue> next to your example.

Simple usage example

use rustpython_unparser::Unparser;
use rustpython_parser::ast::Suite;
use rustpython_parser::Parse;

fn main() {
    // ...
    let unparser = Unparser::new();
    let stmts = Suite::parse(source_str, file_path);
    for stmt in &stmts {
        unparser.unparse_stmt(stmt);
    }
    let new_source = unparser.source;
    // ...
}

Transformer

This crate also contains a transformer trait for easy transformation of ASTs with the possibility of removing nodes. Enable the transformer feature to use it. It is similar to rustpython-ast's visitor, with the difference that a visit functions always return Option<...> and statements/expressions are passed as mutable.

About

A complete unparser for rustpython-parser ASTs (Codeberg mirror)

codeberg.org/jvllmr/rustpython-unparser

Topics

astrustpythonunparser

Resources

Readme
License

Contributing

Contributing
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.