Python's Full Grammar specification and PEP 617 states:
~ (“cut”): commit to the current alternative and fail the rule even [NB: typo?] if this [alternative] fails to parse
It is not clear to me whether the cut applies to all alternatives in the current parse tree or only the latest alternative. Apparently, there are both types of cuts, as has been discussed in this issue, and I think (?) the conclusion by Guido was
Your first quote convinces me that cut is meant to act locally (which is how I have implemented it).
But the current grammar contains rules where the cut appears (to me) to be useless, for example:
assignment_expression:
| NAME ':=' ~ expression
If cut only acts locally on this single rule, wouldn't the rule be the same without the cut, since there are no alternatives to skip over in case expression fails to parse?
Either way, it would be nice if the documentation could be clarified with regard to which kind of cut is used in Python's grammar.
Linked PRs
Python's Full Grammar specification and PEP 617 states:
It is not clear to me whether the cut applies to all alternatives in the current parse tree or only the latest alternative. Apparently, there are both types of cuts, as has been discussed in this issue, and I think (?) the conclusion by Guido was
But the current grammar contains rules where the cut appears (to me) to be useless, for example:
If cut only acts locally on this single rule, wouldn't the rule be the same without the cut, since there are no alternatives to skip over in case
expressionfails to parse?Either way, it would be nice if the documentation could be clarified with regard to which kind of cut is used in Python's grammar.
Linked PRs