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)
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
, e.g. "ss" -> u"ss" (for pylib to handle escape chars)1:2
->slice(1,2)
...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 keepend
still, as it's a keyword in Nim, so when just have to replace it with others, likeendl
.When developing, I'm trying to mend the difference between Python and Nim's syntax, but there're cases that cannot be avoided.