Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middle-ground betwixt ast and baron for parsing source code, and emitting only what changed in FST from AST #209

Open
SamuelMarks opened this issue Dec 16, 2021 · 1 comment

Comments

@SamuelMarks
Copy link

What I'm imagining is using ast to find and modify nodes, and when ready to emit (unparse) align with the FST so that only what the AST has changed will be modified.

Some caveats:

  • Cannot delete nodes (I assume)
  • Maybe difficulty in converting single line to multiline, and multiline to single line

What do you think?

I am modifying AST nodes, changing: docstrings; ast.Assign; ast.AnnAssign; and ast.FunctionDef/ast.AsyncFunctionDef. Inferring types, adding them as a type comment xor annotation; converting between docstring formats (incl. adding/remove types); and updating the return attribute of a function definition.

Currently my library only uses ast and inspect for this… which means it can support 3.6, 3.7, 3.8, 3.9, 3.10 & 3.11. https://github.com/SamuelMarks/cdd-python

…but adding/removing type annotations, for example, has the [unexpected] side-effect of removing all comments and reducing whitespace.

Tossing up betwixt rewriting my library around redbaron | LibCST and hacking together a basic parser & emitter to replace ast.parse and ast.unparse with some line-aware copypasta.

Related: #207

Thanks for sharing your perspective

@Erotemic
Copy link

FYI: this project is not actively updated. Parso is another FST that I've been pointed towards in the past (although I haven't checked it in detail).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants