diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index 423948e51a2..220ec0d74b4 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/tests/query/highlights/python/pattern_matching.py b/tests/query/highlights/python/pattern_matching.py new file mode 100644 index 00000000000..174f0494feb --- /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 + +def get_preserved_filters(self, request): + """ + Return the preserved filters querystring. + """ + match = request.resolver_match +# ^ variable + if foo: + pass + return ''