we-like-parsers / pegen_experiments

Experiments for the official PEG parser generator for Python
https://github.com/python/cpython/tree/master/Tools/peg_generator
Other
275 stars 29 forks source link

Reject invalid expressions in the for-if clauses of a comprehension #214

Closed lysnikolaou closed 4 years ago

lysnikolaou commented 4 years ago

For example, pegen currently accepts the invalid (a for a in lambda: b).

I found this out, while investigating the Travis failures in #213. This also stresses the need for testing with invalid input.

gvanrossum commented 4 years ago

+1 on the test fix too.

lysnikolaou commented 4 years ago

How did you find this?

I was investigating the Travis failures from #213, which all were related to this.

Also, eventually this may point to some possible relaxation of the grammar? Or would there be some ambiguity that PEG resolves by taking the first match?

What do you mean relaxation of the grammar?

gvanrossum commented 4 years ago

Relaxation: turn e.g. disjunction into expression. But in this case probably there’s a reason.

lysnikolaou commented 4 years ago

Relaxation: turn e.g. disjunction into expression.

But doesn't this PR then do the opposite of relaxation?

gvanrossum commented 4 years ago

Indeed, but presumably that to match the old parser.

I was hypothesizing that using pegen will allow us to see some restrictions in the grammar and let us relax them. Though on second thought probably not this case.