Pablo Galindo Salgado <[email protected]> added the comment:
The Python grammar is already not LL(1) strictly. Take for example the
production for "argument":
argument: ( test [comp_for] | test '=' test | '**' test | '*' test )
obviously the first sets of test and test are the same and is ambiguous, but
the NDFAs are still able to produce DFAs that can generate a concrete syntax
tree that allows the AST generation to disambiguate that the second test is a
NAME and not any other thing.
The rule with_stmt: 'with' ( with_item (',' with_item)* | '(' with_item (','
with_item)* [','] ')' ) ':' suite
will generate a similar scenario. The NDFAs will generate DFAs that will
ultimately allow us to just skip the more external group of parenthesis when
generating the nodes. This makes valid all these expressions:
with (manager() as x, manager() as y):
pass
with (manager() as x, manager() as y,):
pass
with (manager()):
pass
with (manager() as x):
pass
with (((manager()))):
pass
with ((((manager()))) as x):
but not this one:
with (((manager()))) as x:
the reason is that it assigns the first LPAR to the second production and it
fails when searching for the one that is at the end. I think this limitation is
OK.
If you want to play with that. here is a prototype of the implementation with
some tests:
https://github.com/pablogsal/cpython/tree/parenthesized_with
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue12782>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com