Parsing non Python code in the scripting?
Posted: Wed Dec 08, 2021 7:18 am
To begin with, I have minimal experience in working with Python. As a matter of fact, I could probably not do most basic operations, because, as I attempt to learn anything, it makes me wish I was using my native programming tongue instead, Forth. It is probably a confusing and backwards language to anyone who comes to it after learning any other language, but it has become my personal preference in using it now. By random chance, I had located a Forth language parser written in Python, which would allow any Python based environment to read Forth code. It's called forth-py and can be found here, open sourced on Github.
It is a little rough around the edges but it is basically what I wanted in bridging the gap in between languages. I tweaked it slightly to fit my needs, although not completely functional in the way I want yet, it is in some state usable. Great, right? Well, not quite, because I haven't quite been able to figure out how to make RenPy itself parse this parser. I attempted importing the relevant code and declaring the import as python code beforehand, but it gives me this error:
The definition of ForthException being:
Why is it unable to import this?
Yes, I'm aware it would be faster and easier to learn Python and the scripting of RenPy, and write my code in that. I suspect however if I'm not doing this in a way I enjoy, then it won't be enjoyed. And having to learn a new language entirely would curbstomp my enjoyment.
It is a little rough around the edges but it is basically what I wanted in bridging the gap in between languages. I tweaked it slightly to fit my needs, although not completely functional in the way I want yet, it is in some state usable. Great, right? Well, not quite, because I haven't quite been able to figure out how to make RenPy itself parse this parser. I attempted importing the relevant code and declaring the import as python code beforehand, but it gives me this error:
Code: Select all
Traceback (most recent call last):
File "renpy/common/00console.rpy", line 689, in run
renpy.python.py_exec(code)
File "renpy/python.py", line 2258, in py_exec
exec(py_compile(source, 'exec'), store, locals)
File "<none>", line 1, in <module>
File "renpy/loader.py", line 985, in load_module
exec(code, mod.__dict__)
File "forthmain.py", line 1, in <module>
File "renpy/loader.py", line 985, in load_module
exec(code, mod.__dict__)
File "lexer.py", line 2, in <module>
ImportError: cannot import name ForthException
Code: Select all
class ForthException(Exception):
def forth__init__(self, msg):
self.msg = msg
def forth__str__(self):
return self.msg
Yes, I'm aware it would be faster and easier to learn Python and the scripting of RenPy, and write my code in that. I suspect however if I'm not doing this in a way I enjoy, then it won't be enjoyed. And having to learn a new language entirely would curbstomp my enjoyment.