Re:Show HN: Python Source Code Refactoring Toolkit via AST
by woile on Monday August 02, 2021 @02:32AM
(#28033504)
Maybe something like this:
I found it last week. It may be able to detect a potential issue in multiple languages, but not sure if it supports refactoring.
Re:Show HN: Python Source Code Refactoring Toolkit via AST
by chrisphilip on Monday August 02, 2021 @12:58AM
(#28033060)
I wrote a library that takes a language specification (BNF, ABNF, etc) into a custom AST in Python. Then you can define a set of visitors for the custom AST to transform the tree into whatever you want. I implemented some checks integrated into the Python type system to type-check the visitors and I've used the library to do some non-trivial manipulations before.
It's mostly a pet project and I just wanted to share since it could maybe at least inspire something.
Re:Show HN: Python Source Code Refactoring Toolkit via AST
by jay-aye-see-key on Monday August 02, 2021 @12:18AM
(#28032826)
This is not a problem I'd had, but it sounds like something tree-sitter might be able to help with.
I've been using tree-sitter for syntax highlighting, simple refactors, and custom text objects in NeoVim recently (and love it, thanks NeoVim devs!). Have a play with the syntax tree it generates https://tree-sitter.github.io/tree-sitter/playground (it can generate a tree for most languages, not just the ones in this playground).
Any suggestion on an AST ‘framework’ that would help me parse code easier? Language specific or generic, even if it only sort-of fits (I don’t even know what I want).
Automated Code analysers exist, but I want something manual.