nvim-treesitter/tests/query/highlights/python/pattern_matching.py

52 lines
1.3 KiB
Python
Raw Normal View History

match command.split():
2023-12-24 12:52:21 +01:00
# ^ @conditional
case ["quit"]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
print("Goodbye!")
quit_game()
case ["look"]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
current_room.describe()
case ["get", obj]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
character.get(obj, current_room)
case ["go", direction]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
current_room = current_room.neighbor(direction)
# The rest of your commands go here
match command.split():
2023-12-24 12:52:21 +01:00
# ^ @conditional
case ["drop", *objects]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
for obj in objects:
character.drop(obj, current_room)
match command.split():
2023-12-24 12:52:21 +01:00
# ^ @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}")
2023-12-24 12:52:21 +01:00
# ^^ @@function.macro
match command.split():
2023-12-24 12:52:21 +01:00
# ^ @conditional
case ["north"] | ["go", "north"]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
current_room = current_room.neighbor("north")
case ["get", obj] | ["pick", "up", obj] | ["pick", obj, "up"]:
2023-12-24 12:52:21 +01:00
# ^ @conditional
pass
match = 2
2023-12-24 12:52:21 +01:00
# ^ @variable
match, a = 2, 3
2023-12-24 12:52:21 +01:00
# ^ @variable
match: int = secret
2023-12-24 12:52:21 +01:00
# ^ @variable
x, match: str = 2, "hey, what's up?"
2023-12-24 12:52:21 +01:00
# <- @variable
# ^ @variable