diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2022-12-02 20:22:58 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-12-02 21:42:11 +0100 |
| commit | d6a2ecb8b7093d6f6673cb6748bce9214a5099d3 (patch) | |
| tree | 787aaf8f5e4b9079bacbdac6e0e8bcb935d5b199 | |
| parent | Update lockfile.json (diff) | |
| download | nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar.gz nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar.bz2 nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar.lz nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar.xz nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.tar.zst nvim-treesitter-d6a2ecb8b7093d6f6673cb6748bce9214a5099d3.zip | |
highlights: create subscoping for ternary operator
After https://github.com/nvim-treesitter/nvim-treesitter/issues/470,
we decided to use `@conditional` for ternary operator instead of
operator despite `@conditional` is documented for keywords only.
A sub-scoping can make it easier for people to highlight this operator
group differently.
Also unify the usage of `@conditional...` across languages.
| -rw-r--r-- | CONTRIBUTING.md | 1 | ||||
| -rw-r--r-- | queries/awk/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/c/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/ecma/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/fusion/highlights.scm | 3 | ||||
| -rw-r--r-- | queries/hack/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/java/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/julia/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/meson/highlights.scm | 3 | ||||
| -rw-r--r-- | queries/perl/highlights.scm | 6 | ||||
| -rw-r--r-- | queries/slint/highlights.scm | 2 | ||||
| -rw-r--r-- | queries/vim/highlights.scm | 2 | ||||
| -rw-r--r-- | tests/query/highlights/fusion/expressions.fusion | 4 |
13 files changed, 20 insertions, 13 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a510f0e7f..9e104f252 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -146,6 +146,7 @@ effect on highlighting. We will work on improving highlighting in the near futur @keyword.return ; keywords like `return` and `yield` @conditional ; keywords related to conditionals (e.g. `if` / `else`) +@conditional.ternary ; Ternary operator: condition ? 1 : 2 @repeat ; keywords related to loops (e.g. `for` / `while`) @debug ; keywords related to debugging @label ; GOTO and other labels (e.g. `label:` in C) diff --git a/queries/awk/highlights.scm b/queries/awk/highlights.scm index 918d0116e..a03c43670 100644 --- a/queries/awk/highlights.scm +++ b/queries/awk/highlights.scm @@ -115,7 +115,7 @@ (ternary_exp [ "?" ":" -] @operator) +] @conditional.ternary) (update_exp [ "++" diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 2de5abe9d..f1cff7467 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -102,7 +102,7 @@ (false) ] @boolean -(conditional_expression [ "?" ":" ] @conditional) +(conditional_expression [ "?" ":" ] @conditional.ternary) (string_literal) @string (system_lib_string) @string diff --git a/queries/ecma/highlights.scm b/queries/ecma/highlights.scm index 377cc43c5..1de0de302 100644 --- a/queries/ecma/highlights.scm +++ b/queries/ecma/highlights.scm @@ -185,7 +185,7 @@ ] @operator (binary_expression "/" @operator) -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) (unary_expression ["!" "~" "-" "+"] @operator) (unary_expression ["delete" "void" "typeof"] @keyword.operator) diff --git a/queries/fusion/highlights.scm b/queries/fusion/highlights.scm index 7109ee651..b093f8872 100644 --- a/queries/fusion/highlights.scm +++ b/queries/fusion/highlights.scm @@ -115,3 +115,6 @@ "." "?" ] @punctuation.delimiter + +(eel_ternary_expression + ["?" ":"] @conditional.ternary) diff --git a/queries/hack/highlights.scm b/queries/hack/highlights.scm index 778a0e146..e79d62c75 100644 --- a/queries/hack/highlights.scm +++ b/queries/hack/highlights.scm @@ -273,7 +273,7 @@ "\\" @punctuation.delimiter) (ternary_expression - ["?" ":"] @conditional) + ["?" ":"] @conditional.ternary) [ "if" diff --git a/queries/java/highlights.scm b/queries/java/highlights.scm index cc9ed99c7..63cb01237 100644 --- a/queries/java/highlights.scm +++ b/queries/java/highlights.scm @@ -226,7 +226,7 @@ "case" ] @conditional -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) ; diff --git a/queries/julia/highlights.scm b/queries/julia/highlights.scm index 116767870..e8d9ac9ff 100644 --- a/queries/julia/highlights.scm +++ b/queries/julia/highlights.scm @@ -134,7 +134,7 @@ (else_clause ["else"] @conditional) (ternary_expression - ["?" ":"] @conditional) + ["?" ":"] @conditional.ternary) (try_statement ["try" "end"] @exception) diff --git a/queries/meson/highlights.scm b/queries/meson/highlights.scm index 41af33063..f687f5ae0 100644 --- a/queries/meson/highlights.scm +++ b/queries/meson/highlights.scm @@ -39,7 +39,8 @@ ">=" ] @operator -"?" @conditional.ternary +(ternaryoperator + ["?" ":"] @conditional.ternary) [ "if" diff --git a/queries/perl/highlights.scm b/queries/perl/highlights.scm index 56ed3ee8a..c6b2c4ee4 100644 --- a/queries/perl/highlights.scm +++ b/queries/perl/highlights.scm @@ -13,6 +13,10 @@ ; Keywords that mark conditional statements [ "if" "elsif" "unless" "else" ] @conditional +(ternary_expression + ["?" ":"] @conditional.ternary) +(ternary_expression_in_hash + ["?" ":"] @conditional.ternary) ; Keywords that mark repeating loops [ "while" "until" "for" "foreach" ] @repeat @@ -142,8 +146,6 @@ (to_reference) (type_glob) (hash_access_variable) -(ternary_expression) -(ternary_expression_in_hash) ] @operator [ diff --git a/queries/slint/highlights.scm b/queries/slint/highlights.scm index f1ac2de2c..54dc20369 100644 --- a/queries/slint/highlights.scm +++ b/queries/slint/highlights.scm @@ -143,4 +143,4 @@ "=>" ] @operator -(ternary_expression [":" "?"] @conditional) +(ternary_expression [":" "?"] @conditional.ternary) diff --git a/queries/vim/highlights.scm b/queries/vim/highlights.scm index 239b0a0b3..ce25b13b9 100644 --- a/queries/vim/highlights.scm +++ b/queries/vim/highlights.scm @@ -271,7 +271,7 @@ ":" ] @punctuation.delimiter -(ternary_expression ["?" ":"] @conditional) +(ternary_expression ["?" ":"] @conditional.ternary) ; Options ((set_value) @number diff --git a/tests/query/highlights/fusion/expressions.fusion b/tests/query/highlights/fusion/expressions.fusion index a0b82b511..ae6e2db33 100644 --- a/tests/query/highlights/fusion/expressions.fusion +++ b/tests/query/highlights/fusion/expressions.fusion @@ -76,7 +76,7 @@ logic = ${!foo && !(bar || baz) and not 'string'} // ^operator ternary = ${ check ? true : false} -// ^punctuation.delimiter -// ^punctuation.delimiter +// ^@conditional.ternary +// ^@conditional.ternary |
