skulpt / skulpt

Skulpt is a Javascript implementation of the Python programming language
Other
3.34k stars 892 forks source link

expose ast module #178

Open donkirkby opened 10 years ago

donkirkby commented 10 years ago

I see that you have an ast.js file, and it uses some of the classes I recognize from Python's ast module. Is it feasible to expose it to a script running in Skulpt as the ast module? Here's an example Python script that currently doesn't print anything. In Python, it prints out a small syntax tree for a module with a single assignment.

import ast

code = "x = 5"

tree = ast.parse(code)

print(ast.dump(tree, include_attributes=True))
rixner commented 10 years ago

While this might be possible, it is unlikely that ast.js is an exact match with CPython (it should be close, though). Further, it would probably take some work to expose it in the same way that the CPython ast module does.

ssokolow commented 9 years ago

For the record, I'd have a use for it.

One of my rainy-day projects is a trimmed down spreadsheet GUI (sort of like TinyMCE is to MS Word, but for calculations instead of writing) and I want to use Python expressions for the cell calculations.

Unfortunately, since I'd have to use the AST module to identify inter-cell dependencies from the expressions, I'm currently stuck with PyQt on the blueprints rather than a browser-based solution.

alehander92 commented 8 years ago

any development here?

acbart commented 5 years ago

BlockPy has an ast.js module that's compatible with the new parser. I'll note that I've also extended the parser to capture line endings - I'm not sure whether that prevents this from being used without modification in the main branch, but it shouldn't take much coercing probably:

https://github.com/blockpy-edu/skulpt/blob/master/src/lib/ast.js