Pyparse is a parser for Python hand-written in Javascript. This was heavily inspired by the parser library in the python built-in library. It takes in Python and outputs an AST for use in Spidermonkey, etc. This will be available as a Bower package. Importantly, there are no dependencies for this project. I used Grunt as a build tool and for minification.

The API to the parser is very simple. A call to parse() is made with the python code as an argument. The AST is output from there.

The parser has two main components. First, the call to parse sends the code to the tokenizer. The tokenizer is a finite state machine, moving character by character through the code. The tokenizer returns an array of tokens. The array of tokens is sent into makeTreeFromTokens, which recursively constructs the AST from the token stream.

Thanks for taking a look!

Built With

Share this project:
×

Updates