Hello,
I am trying to implement PEP-637, and I started modifying the parser
and the grammar, but I don't know what I am missing.
The PR is here
https://github.com/python/cpython/compare/master...stefanoborini:PEP-637-implementation-attempt-1?expand=1
It includes other stuff but the core is that I extended the Subscript
in the asdl to accept the keyword args
| Subscript(expr value, expr slice, keyword* keywords, expr_context ctx)
which seems to work:
>>> ast.parse('a[3]').body[0].value.keywords
[]
I also added a few "productions" (I believe they are called like this,
my compiler theory is very approximated), one of which is now
primary[expr_ty]:
....
| a=primary '[' b=slices c=[',' k=kwargs {k}]']' {
_Py_Subscript(a, b, c, Load, EXTRA) }
I also tried with additional formats like
| a=primary '[' b=slices c=kwargs ']' { _Py_Subscript(a, b, c,
Load, EXTRA) }
or even just
| a=primary '[' c=kwargs ']' { _Py_Subscript(a, NULL, c, Load, EXTRA) }
but I always get a SyntaxError:
>>> ast.parse('a[k=3]').body[0].value.keywords
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sbo/Work/Projects/stefanoborini/cpython/Lib/ast.py",
line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
a[k=3]
^
SyntaxError: invalid syntax
Note that I always recreated ast parser and pegen.c with 'make
regen-all' and recompiled with make.
I tried to enable debug and print the pegen.c debug, but it's a bit
heavy and I could not immediately spot the issue. I suspect I am
missing something somewhere.
Thanks
--
Kind regards,
Stefano Borini
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/RZYDHYZPTPGLBX4VCR6HTYGJ3GL2CWIX/
Code of Conduct: http://python.org/psf/codeofconduct/
I am trying to implement PEP-637, and I started modifying the parser
and the grammar, but I don't know what I am missing.
The PR is here
https://github.com/python/cpython/compare/master...stefanoborini:PEP-637-implementation-attempt-1?expand=1
It includes other stuff but the core is that I extended the Subscript
in the asdl to accept the keyword args
| Subscript(expr value, expr slice, keyword* keywords, expr_context ctx)
which seems to work:
>>> ast.parse('a[3]').body[0].value.keywords
[]
I also added a few "productions" (I believe they are called like this,
my compiler theory is very approximated), one of which is now
primary[expr_ty]:
....
| a=primary '[' b=slices c=[',' k=kwargs {k}]']' {
_Py_Subscript(a, b, c, Load, EXTRA) }
I also tried with additional formats like
| a=primary '[' b=slices c=kwargs ']' { _Py_Subscript(a, b, c,
Load, EXTRA) }
or even just
| a=primary '[' c=kwargs ']' { _Py_Subscript(a, NULL, c, Load, EXTRA) }
but I always get a SyntaxError:
>>> ast.parse('a[k=3]').body[0].value.keywords
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sbo/Work/Projects/stefanoborini/cpython/Lib/ast.py",
line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
a[k=3]
^
SyntaxError: invalid syntax
Note that I always recreated ast parser and pegen.c with 'make
regen-all' and recompiled with make.
I tried to enable debug and print the pegen.c debug, but it's a bit
heavy and I could not immediately spot the issue. I suspect I am
missing something somewhere.
Thanks
--
Kind regards,
Stefano Borini
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/RZYDHYZPTPGLBX4VCR6HTYGJ3GL2CWIX/
Code of Conduct: http://python.org/psf/codeofconduct/