4 ms·
I actually have a prototype of something like that, built on top of Lark. It's still far from being complete or user friendly, but I'm already successfully tran
by erezsh 5y ago
I actually have a prototype of something like that, built on top of Lark. It's still far from being complete or user friendly, but I'm already successfully transpiling a subset of Python to Javascript.
It still needs a lot of handholding, but at the same time I get to use gems like -
... = TemplateTranslator({
'isinstance($a, str)': "typeof($a) == 'string'",
'isinstance($a, bool)': "typeof($a) == 'boolean'",
'len($a)': '$a.length',
'str($a)': '$a.toString()',
'getattr($a, $b)': '$a and $a[$b]',
'getattr($a, $b, $c)': '($a and $a[$b]) or $c',
'hasattr($a, $b)': '$b in $a',
'$a.join($b)': '$b.join($a)',
... })
- bmc7505 5y agoNice! I like the syntax, this reminds me of the structural search and replace feature from IntelliJ IDEA. Is this the project you were referring to? https://github.com/erezsh/py2js https://github.com/erezsh/py2js