nimpylib / pylib

Python builtins/standard-Lib functions ported to Nim
https://nimpylib.github.io/pylib/
MIT License
3 stars 0 forks source link

py2nim #9

Open litlighilit opened 1 week ago

litlighilit commented 1 week ago

It'll be useful if a intermedia rewriter exists, which take responsibility to handle the ast that Nim disallows, rewrite Python code to codes valid for pylib to compile, and try to keep it a valid python when possible:

For example:

Above are some examples where the rewritten result is still valid Python, yet handle-able for Nim.


There're also some code that cannot keep valid for python when rewriting, some examples come when it comes to keyword,

e.g. print("123", end=""), we cannot keep end still, as it's a keyword in Nim, so when just have to replace it with others, like endl.

When developing, I'm trying to mend the difference between Python and Nim's syntax, but there're cases that cannot be avoided.

litlighilit commented 1 week ago

May ref: py2many's nim rewriter https://github.com/py2many/py2many/tree/main/pynim,

relative issue: py2many: 229, (the team had noted the original nimpylib)

litlighilit commented 1 week ago

TODO to interact with py2many