-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
#11457 added the ability to do speculative parsing via checkpoint - rewind infrastructure and is currently being used for match statement via #11443.
To give a brief background, speculative parsing means that the parser tries to parse a syntax node as one kind and determines at the end if the assumption was right by testing if the parser is at a specific token (or has no errors). This is useful if a syntax is ambiguous and no amount of lookahead (except parsing the whole syntax) is sufficient to determine what syntax it is.
The idea here is to update the current parsing logic for with-items to use the checkpoint - rewind infrastructure. The current logic performs a manual and a bit complex speculative parsing to disambiguate between a parenthesized with-items and parenthesized with-item expression i.e., whether the parenthesis belongs to with-items or the expression of the first with-item. For example,
with (item1, item2): ... # Parenthesized with-items
with (item1, item2) as f: ... # Parenthesized expression