diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2021-12-03 19:10:11 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-01-28 19:11:20 +0100 |
| commit | c4e3564ea31183ddcd00d6192efb2879977b420e (patch) | |
| tree | 0de3067dfe736560a5fd40c263bada51f4ba0cb6 /tests/query | |
| parent | highlights(go): highlight `package_identifier` as `@namespace` (#2371) (diff) | |
| download | nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar.gz nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar.bz2 nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar.lz nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar.xz nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.tar.zst nvim-treesitter-c4e3564ea31183ddcd00d6192efb2879977b420e.zip | |
highlights(python): add support for pattern matching
Fixes #2080
Depends on https://github.com/tree-sitter/tree-sitter-python/pull/140
Diffstat (limited to 'tests/query')
| -rw-r--r-- | tests/query/highlights/python/pattern_matching.py | 50 |
1 files changed, 50 insertions, 0 deletions
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 |
