On Thu, Jun 13, 2019 at 12:52 AM Yanghao Hua <yanghao...@gmail.com> wrote: > > On Wed, Jun 12, 2019 at 11:27 PM Chris Angelico <ros...@gmail.com> wrote: > > 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). > > Yep ... I just tried to use MacroPy3 to handle this but failed, seems > MacroPy3 does expect valid Python syntax in the first place for > anything else to happen. I also tried the raw ast module which seems > also the case. So it means if one want to use python ast module to > parse user input, the user input has to be valid python syntax (e.g. > no <==) at the first place. Seems this is a chicken-egg problem.
Attaching the trace: Traceback (most recent call last): File "tt.py", line 34, in <module> main() File "tt.py", line 8, in main tree = ast.parse(source.read()) File "/usr/lib/python3.6/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "<unknown>", line 1 x <== 3 ^ SyntaxError: invalid syntax _______________________________________________ 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/RTAAWQZ74VTP244FBK5K2WFNJTFTDJSW/ Code of Conduct: http://python.org/psf/codeofconduct/