
On Thu, Jun 13, 2019 at 6:51 AM Yanghao Hua yanghao.py@gmail.com wrote:
On Wed, Jun 12, 2019 at 9:39 AM Chris Angelico rosuav@gmail.com wrote:
If Python is really THAT close, then devise two syntaxes: an abstract syntax for your actual source code, and then a concrete syntax that can be executed. It's okay for things to be a little bit ugly (like "signal[:] = 42") in the concrete form, because you won't actually be editing that. Then your program just has to transform one into the other, and then run the program.
Thought about that too .... but as you can imagine, you can write:
x <== 3 # or x \ <== 3 # or x \ \ ... \ <== 3 # This is crazy but valid python syntax! # more crazy ones are skipped ...
so this is not a simple text replacement problem, eventually you end up writing a python parser? Or a HDL parser.
Yes, you would need some sort of syntactic parser. There are a couple of ways to go about it. One is to make use of Python's own tools, like the ast module; the other is to mandate that your specific syntax be "tidier" than the rest of the Python code, which would permit you to use a more naive and simplistic parser (even a regex).
ChrisA