mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
This previously only worked in certain circumstances. In particular, assignments such as `match[1] = ...` or even just `match[1]` would fail to parse correctly. Fixing this turned out to be less trivial than anticipated. Consider the fact that ``` match [1]: case (...) ``` can either look the start of a `match` statement, or it could be a type ascription, ascribing the value of `case(...)` (a call) to the item at index 1 of `match`. To fix this, then, we give `match` the identifier and `match` the statement the same precendence in the grammar, and additionally also mark a conflict between `match_statement` and `primary_expression`. This causes the conflict to be resolved dynamically, and seems to do the right thing in all cases.
21 lines
334 B
Python
21 lines
334 B
Python
match[1]
|
|
match[2] = 3
|
|
|
|
match.foo = 4
|
|
|
|
match()
|
|
|
|
match[5] : case
|
|
|
|
|
|
# match used "properly"
|
|
match [6]:
|
|
case 7:
|
|
pass
|
|
|
|
|
|
print >> 8, "hello" # Python 2-style print
|
|
pront >> 9, "world" # How this would be interpreted in Python 3
|
|
|
|
await [10] # In Python 2 this would be an indexing operation, but it's more likely to be an await.
|