Python library for parsing code of any language into an AST?

Question:

I’m looking for a Python library for parsing code into its abstract syntax tree representation. There exists a built-in module, named ast, however, it is only designed for parsing Python code, to my understanding. I’m wondering if there is a similar Python library that suits the same purpose, but works with other programming languages. In particular, I’m looking for one that can parse JavaScript code.

If one does not exist, any direction on how I could get started designing my own?

Asked By: Ryan Rudes

||

Answers:

In general, when you need to parse code written in a language, it’s almost always better to use that language instead.

For parsing JavaScript from Python, you may want to check out this module, which can be installed using pip and should work well enough.

Answered By: BattleMage_

The library tree-sitter has a python binding, tons of language parsers!

Answered By: Lance