Commit f700e1d
committed
Disallow lone starred expressions at the grammar level
Statements like the following (where `()` can be any
iterable -- or at the syntax level, any value):
*()
x = *()
yield *()
return *()
for _ in *(): ...
are not valid without a comma after the iterable.
These were allowed by `python.gram` and only rejected
in the codegen step. This means that the
documented "Full Grammar specification" was incomplete.
Change the grammar itself to disallow "lone" starred
expressions.
This interfered with the `invalid_legacy_expression`
rule, where in ``return i*i for _ in _`` the ``i *i``
was parsed similarly to ``print *i``, generating
"can't use starred expression here" from `*i` (before
getting to the "Missing parentheses in call" message
instead of a generic "invalid syntax".
Exclude the star in `invalid_legacy_expression` to
prevent this.
Co-authored-by: Blaise Pabon <blaise@gmail.com>
.1 parent 20e6c2f commit f700e1d
3 files changed
Lines changed: 552 additions & 444 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
735 | | - | |
| 735 | + | |
| 736 | + | |
736 | 737 | | |
737 | 738 | | |
738 | 739 | | |
| |||
1245 | 1246 | | |
1246 | 1247 | | |
1247 | 1248 | | |
1248 | | - | |
| 1249 | + | |
1249 | 1250 | | |
1250 | 1251 | | |
1251 | 1252 | | |
| |||
1295 | 1296 | | |
1296 | 1297 | | |
1297 | 1298 | | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
1298 | 1302 | | |
1299 | 1303 | | |
1300 | 1304 | | |
| |||
1325 | 1329 | | |
1326 | 1330 | | |
1327 | 1331 | | |
| 1332 | + | |
| 1333 | + | |
1328 | 1334 | | |
1329 | 1335 | | |
1330 | 1336 | | |
| |||
0 commit comments