forked from nvim-treesitter/nvim-treesitter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
highlights(python): add support for pattern matching
Fixes nvim-treesitter#2080 Depends on tree-sitter/tree-sitter-python#140
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |