aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lockfile.json2
-rw-r--r--queries/python/highlights.scm2
-rw-r--r--queries/python/locals.scm7
-rw-r--r--tests/query/highlights/python/pattern_matching.py50
4 files changed, 54 insertions, 7 deletions
diff --git a/lockfile.json b/lockfile.json
index b4b6668b2..bf3841e49 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -207,7 +207,7 @@
"revision": "5875f9a7d94836708119b0a1102bb5792e8bf673"
},
"python": {
- "revision": "e979351ec7b033fc2515ba9b573e3ad0fee8d1c3"
+ "revision": "ed0fe62e55dc617ed9dec8817ebf771aa7cf3c42"
},
"ql": {
"revision": "8e7fd7e638d4a0ec7a792ee16b19dbc6407aa810"
diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm
index 0813c960b..ccbb2e79d 100644
--- a/queries/python/highlights.scm
+++ b/queries/python/highlights.scm
@@ -230,7 +230,7 @@
["from" "import"] @include
(aliased_import "as" @include)
-["if" "elif" "else"] @conditional
+["if" "elif" "else" "match" "case"] @conditional
["for" "while" "break" "continue"] @repeat
diff --git a/queries/python/locals.scm b/queries/python/locals.scm
index 5cfd35435..7699a512e 100644
--- a/queries/python/locals.scm
+++ b/queries/python/locals.scm
@@ -34,11 +34,6 @@
(typed_default_parameter
(identifier) @definition.parameter)
-(with_statement
- (with_clause
- (with_item
- alias: (identifier) @definition.var)))
-
; *args parameter
(parameters
(list_splat_pattern
@@ -113,6 +108,8 @@
(named_expression
(identifier) @definition.var)
+(as_pattern
+ alias: (identifier) @definition.var)
;;; REFERENCES
(identifier) @reference
diff --git a/tests/query/highlights/python/pattern_matching.py b/tests/query/highlights/python/pattern_matching.py
new file mode 100644
index 000000000..38622cf4b
--- /dev/null
+++ b/tests/query/highlights/python/pattern_matching.py
@@ -0,0 +1,50 @@
+match command.split():
+# ^ conditional
+ case ["quit"]:
+ # ^ conditional
+ print("Goodbye!")
+ quit_game()
+ case ["look"]:
+ # ^ conditional
+ current_room.describe()
+ case ["get", obj]:
+ # ^ conditional
+ character.get(obj, current_room)
+ case ["go", direction]:
+ # ^ conditional
+ current_room = current_room.neighbor(direction)
+ # The rest of your commands go here
+
+match command.split():
+# ^ conditional
+ case ["drop", *objects]:
+ # ^ conditional
+ for obj in objects:
+ character.drop(obj, current_room)
+
+match command.split():
+# ^ conditional
+ case ["quit"]: ... # Code omitted for brevity
+ case ["go", direction]: pass
+ case ["drop", *objects]: pass
+ case _:
+ print(f"Sorry, I couldn't understand {command!r}")
+
+match command.split():
+# ^ conditional
+ case ["north"] | ["go", "north"]:
+ # ^ conditional
+ current_room = current_room.neighbor("north")
+ case ["get", obj] | ["pick", "up", obj] | ["pick", obj, "up"]:
+ # ^ conditional
+ pass
+
+match = 2
+# ^ variable
+match, a = 2, 3
+# ^ variable
+match: int = secret
+# ^ variable
+x, match: str = 2, "hey, what's up?"
+# <- variable
+# ^ variable