You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this structure, the if clauses are associated globally with the entire comprehension rather than individually with each for clause. This is incorrect because, in Python, each for clause in a comprehension can have its own set of if filters.
To Reproduce
I’m unable to provide a simple standalone reproduction script, but as described above, the provided example:
fails to parse correctly under the current grammar. The issue is that the if clauses are incorrectly attached to the comprehension rule as a whole, rather than being associated with their respective comp_for. Each for loop in a comprehension should be able to have its own if filters.
Proposed Fix
In my project, the issue was resolved by modifying the grammar as follows:
Describe the Bug
In Python, the following syntax is valid:
However, in the current
python.lark
grammar, the relevant rule is defined as:With this grammar definition, the two
if
conditions cannot be parsed correctly. It only allows cases such as:In this structure, the
if
clauses are associated globally with the entire comprehension rather than individually with eachfor
clause. This is incorrect because, in Python, eachfor
clause in a comprehension can have its own set ofif
filters.To Reproduce
I’m unable to provide a simple standalone reproduction script, but as described above, the provided example:
fails to parse correctly under the current grammar. The issue is that the
if
clauses are incorrectly attached to thecomprehension
rule as a whole, rather than being associated with their respectivecomp_for
. Eachfor
loop in a comprehension should be able to have its ownif
filters.Proposed Fix
In my project, the issue was resolved by modifying the grammar as follows:
This change allows each
for
clause to optionally have its ownif
filters, which aligns with Python’s actual comprehension syntax.The text was updated successfully, but these errors were encountered: