You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How does it generate the python source from AST? #5
maybe this is out of scope of the current question, but I have the suggestion about getting base python typeshed. What if parse Python pyi into some json with some python tool (need to check if pytypo can do this). Then generate a F# AST basing on it.
Yes, the idea I had was to parse the .pyi using ast.parse and then convert to Python AST since it's already using unions and records. That would then be easier to translate to e.g F# AST.
Correct me if wrong,pyi files contains sometimes conditions, evaluations. How much deep asp.parse should sniff? There are many modules functions like html.escape. But it also contains classes with if's depends on python version for example.
Yes, we would need to create a mini Python to F# transpiler handling if statements as needed. The idea is not to generate perfect code, but something that can be manually edited and fixed before making a PR.
It looks ugly for now (i'm newbie in F# yet). But It could the start for making some helptool for generating files based on pyi's. @dbrattli could you pleasecheck it out?
Very nice that you want to try and build a Python type-hint parser. I would probably use the Ast-module myself, but I currently have more than enough with the Fable2Python parser. If you could make it work, then it would be really great!
Activity
dbrattli commentedon Oct 19, 2021
Try
unparse:alexpantyukhin commentedon Oct 21, 2021
maybe this is out of scope of the current question, but I have the suggestion about getting base python
typeshed. What if parse Pythonpyiinto some json with some python tool (need to check if pytypo can do this). Then generate a F# AST basing on it.dbrattli commentedon Oct 22, 2021
Yes, the idea I had was to parse the
.pyiusingast.parseand then convert to Python AST since it's already using unions and records. That would then be easier to translate to e.g F# AST.alexpantyukhin commentedon Oct 27, 2021
Correct me if wrong,pyi files contains sometimes conditions, evaluations. How much deep
asp.parseshouldsniff? There are many modules functions likehtml.escape. But it also contains classes withif's depends on python version for example.dbrattli commentedon Oct 27, 2021
Yes, we would need to create a mini Python to F# transpiler handling if statements as needed. The idea is not to generate perfect code, but something that can be manually edited and fixed before making a PR.
alexpantyukhin commentedon Oct 29, 2021
I have played a little bit with parsing definitions of function.
Tests with demo: https://github.com/alexpantyukhin/PythonParser/blob/master/PythonParser.Test/ParserTests.fs
Source: https://github.com/alexpantyukhin/PythonParser/blob/master/PythonParser/Parser.fs
It looks ugly for now (i'm newbie in F# yet). But It could the start for making some helptool for generating files based on pyi's. @dbrattli could you pleasecheck it out?
dbrattli commentedon Oct 30, 2021
Very nice that you want to try and build a Python type-hint parser. I would probably use the Ast-module myself, but I currently have more than enough with the Fable2Python parser. If you could make it work, then it would be really great!