Message326645
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 |
|
Date |
User |
Action |
Args |
2018-09-28 16:36:05 | pablogsal | set | recipients:
+ pablogsal, barry, georg.brandl, ishimoto, ncoghlan, benjamin.peterson, ezio.melotti, eric.araujo, steven.daprano, r.david.murray, lukasz.langa, Julian, serhiy.storchaka, ulope |
2018-09-28 16:36:05 | pablogsal | set | messageid: <1538152565.2.0.545547206417.issue12782@psf.upfronthosting.co.za> |
2018-09-28 16:36:05 | pablogsal | link | issue12782 messages |
2018-09-28 16:36:05 | pablogsal | create | |
|