Barry the reason I use python and don't parse syntax directly as I want to have python as meta programming environment for my DSLs. I can mostly work within the python syntax (with some pretty heavy metaclasses) I rarely have to touch the AST. Their only two places where I ever have to touch the AST, in assignment statements and in control flow. Theres no easy way around needing to rewrite control flow but an assignment operator would drastically decrease the amount of AST manipulation I do. In class bodies it is easy to redefine what assignment means, in every other context its very annoying, I don't see why that must be the case.
Caleb On Wed, Jun 12, 2019 at 2:28 PM Chris Angelico <ros...@gmail.com> wrote: > On Thu, Jun 13, 2019 at 6:51 AM Yanghao Hua <yanghao...@gmail.com> wrote: > > > > On Wed, Jun 12, 2019 at 9:39 AM Chris Angelico <ros...@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 > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/BCGYTPPODZCFLFSETZOXPAQFKPGJ6ZVT/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MGOCHF4YT37637BBS7U6PSCWKFHXP4IN/ Code of Conduct: http://python.org/psf/codeofconduct/