Skip to content

py2nim #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
litlighilit opened this issue Jun 17, 2024 · 3 comments
Open

py2nim #9

litlighilit opened this issue Jun 17, 2024 · 3 comments
Labels
help wanted Extra attention is needed idea Creative Idea

Comments

@litlighilit
Copy link
Member

litlighilit commented Jun 17, 2024

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:

  • str literal with single quotes like 'ss' -> u"ss", wrap str literal with double quotation mark with str, e.g. "ss" -> u"ss" (for pylib to handle escape chars)
  • tabs in indentation -> spaces (tabs are invalid for Nim)
  • extend slice literal with step 1:10:3 -> slice(1,10,3)...
  • list/dict/set comprehension -> list/dict/set(map(.... filter(...) ))
  • ...

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 litlighilit added help wanted Extra attention is needed idea Creative Idea labels Jun 17, 2024
@litlighilit
Copy link
Member Author

litlighilit commented Jun 17, 2024

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
Copy link
Member Author

TODO to interact with py2many

  • provide a way for py2many to list available Lib (py stdlib)

@litlighilit
Copy link
Member Author

After that, maybe published via a pip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed idea Creative Idea
Projects
None yet
Development

No branches or pull requests

1 participant