I’ve been thinking about a similar problem I have on a regular basis: I audit a lot of code in many languages, sometimes I’m not even able to build solutions. my toolset pretty much includes git and rudimentary regex. A recent example is a PHP function which is insecure when it’s used at least 3 times in a string concat.<p>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).<p>Automated Code analysers exist, but I want something manual.
I wonder if something like this exists for other languages? Most rewriting/refactoring tools make too many assumptions about the surrounding project. Something simple which supports pattern matching against a CST subtree and invertible parsing/unparsing would be the ideal polyglot macro-system. Suppose I want to find and rename all variables with a certain type or rewrite an expression of a certain shape in multiple languages at once (e.g. Java/JavaScript/C/C++). Something between a regular expressions (too brittle) and a full parser would be great a great solution to have for this use case.
A similar type project. Though I haven't seen much activity recently:<p><a href="https://github.com/facebookincubator/Bowler" rel="nofollow">https://github.com/facebookincubator/Bowler</a>
Would this be a good tool to attempt simple transpiling of typescript code to python?<p>For my use-cases, not much changes between the two -
1. Replace opening and closing braces with colon.
2. Remove semi colons
3. Replace function with def
4. Remove type definitions
5. Replace array manipulation functions with python equivalents.
6. Remove tokens like const, let and var
Nice, I've always thought Python could do better by adopting source transformation tools like babel. I implemented something similar using lib2to3, which preserves whitespace and comments more accurately (than the ast module): <a href="https://github.com/banga/prefactor" rel="nofollow">https://github.com/banga/prefactor</a>
Would this be a good tool to attempt simple transpiling of typescript code to python?<p>For my use-cases, not much changes between the two -<p>1. Replace opening and closing braces with colon.<p>2. Remove semi colons<p>3. Replace function with def<p>4. Remove type definitions<p>5. Replace array manipulation functions with python equivalents.<p>6. Remove tokens like const, let and var
The one thing I hope for when it comes to Python is that PyPy becomes the default runtime everywhere.<p>CPython is so unbelievably slow when compared to languages like PHP and Javascript.<p>When using PyPy, I keep encountering road bumps because many tools are still expecting that one uses CPython.<p>Dear world - please accelerate the conversion to PyPy!