Merge pull request #19895 from github/tausbn/python-fix-match-as-iden… · osanben/codeql@184dd5b · GitHub
Skip to content

Commit 184dd5b

Browse files
authored
Merge pull request github#19895 from github/tausbn/python-fix-match-as-identifier
Python: Allow use of `match` as an identifier
2 parents de09122 + cd0e463 commit 184dd5b

8 files changed

Lines changed: 31674 additions & 29909 deletions

File tree

Lines changed: 137 additions & 0 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
match[1]
2+
match[2] = 3
3+
4+
match.foo = 4
5+
6+
match()
7+
8+
match[5] : case
9+
10+
11+
# match used "properly"
12+
match [6]:
13+
case 7:
14+
pass
15+
16+
17+
print >> 8, "hello" # Python 2-style print
18+
pront >> 9, "world" # How this would be interpreted in Python 3
19+
20+
await [10] # In Python 2 this would be an indexing operation, but it's more likely to be an await.

‎python/extractor/tsg-python/tsp/grammar.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = grammar({
3636
[$.tuple, $.tuple_pattern],
3737
[$.list, $.list_pattern],
3838
[$.with_item, $._collection_elements],
39+
[$.match_statement, $.primary_expression],
3940
],
4041

4142
supertypes: $ => [
@@ -349,7 +350,7 @@ module.exports = grammar({
349350
))
350351
)),
351352

352-
match_statement: $ => seq(
353+
match_statement: $ => prec(-3, seq(
353354
'match',
354355
field('subject',
355356
choice(
@@ -359,7 +360,7 @@ module.exports = grammar({
359360
),
360361
':',
361362
field('cases', $.cases)
362-
),
363+
)),
363364

364365
cases: $ => repeat1($.case_block),
365366

‎python/extractor/tsg-python/tsp/src/grammar.json‎

Lines changed: 46 additions & 38 deletions

0 commit comments

Comments
 (0)