mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
highlights(python): add support for pattern matching
Fixes #2080 Depends on https://github.com/tree-sitter/tree-sitter-python/pull/140
This commit is contained in:
parent
542d098e14
commit
c4e3564ea3
4 changed files with 54 additions and 7 deletions
50
tests/query/highlights/python/pattern_matching.py
Normal file
50
tests/query/highlights/python/pattern_matching.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue