mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
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.
This commit is contained in:
parent
74c46c8917
commit
d6a2ecb8b7
13 changed files with 20 additions and 13 deletions
|
|
@ -146,6 +146,7 @@ effect on highlighting. We will work on improving highlighting in the near futur
|
||||||
@keyword.return ; keywords like `return` and `yield`
|
@keyword.return ; keywords like `return` and `yield`
|
||||||
|
|
||||||
@conditional ; keywords related to conditionals (e.g. `if` / `else`)
|
@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`)
|
@repeat ; keywords related to loops (e.g. `for` / `while`)
|
||||||
@debug ; keywords related to debugging
|
@debug ; keywords related to debugging
|
||||||
@label ; GOTO and other labels (e.g. `label:` in C)
|
@label ; GOTO and other labels (e.g. `label:` in C)
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@
|
||||||
(ternary_exp [
|
(ternary_exp [
|
||||||
"?"
|
"?"
|
||||||
":"
|
":"
|
||||||
] @operator)
|
] @conditional.ternary)
|
||||||
|
|
||||||
(update_exp [
|
(update_exp [
|
||||||
"++"
|
"++"
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@
|
||||||
(false)
|
(false)
|
||||||
] @boolean
|
] @boolean
|
||||||
|
|
||||||
(conditional_expression [ "?" ":" ] @conditional)
|
(conditional_expression [ "?" ":" ] @conditional.ternary)
|
||||||
|
|
||||||
(string_literal) @string
|
(string_literal) @string
|
||||||
(system_lib_string) @string
|
(system_lib_string) @string
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
(binary_expression "/" @operator)
|
(binary_expression "/" @operator)
|
||||||
(ternary_expression ["?" ":"] @conditional)
|
(ternary_expression ["?" ":"] @conditional.ternary)
|
||||||
(unary_expression ["!" "~" "-" "+"] @operator)
|
(unary_expression ["!" "~" "-" "+"] @operator)
|
||||||
(unary_expression ["delete" "void" "typeof"] @keyword.operator)
|
(unary_expression ["delete" "void" "typeof"] @keyword.operator)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,3 +115,6 @@
|
||||||
"."
|
"."
|
||||||
"?"
|
"?"
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
(eel_ternary_expression
|
||||||
|
["?" ":"] @conditional.ternary)
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@
|
||||||
"\\" @punctuation.delimiter)
|
"\\" @punctuation.delimiter)
|
||||||
|
|
||||||
(ternary_expression
|
(ternary_expression
|
||||||
["?" ":"] @conditional)
|
["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
[
|
[
|
||||||
"if"
|
"if"
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@
|
||||||
"case"
|
"case"
|
||||||
] @conditional
|
] @conditional
|
||||||
|
|
||||||
(ternary_expression ["?" ":"] @conditional)
|
(ternary_expression ["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@
|
||||||
(else_clause
|
(else_clause
|
||||||
["else"] @conditional)
|
["else"] @conditional)
|
||||||
(ternary_expression
|
(ternary_expression
|
||||||
["?" ":"] @conditional)
|
["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
(try_statement
|
(try_statement
|
||||||
["try" "end"] @exception)
|
["try" "end"] @exception)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@
|
||||||
">="
|
">="
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
"?" @conditional.ternary
|
(ternaryoperator
|
||||||
|
["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
[
|
[
|
||||||
"if"
|
"if"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@
|
||||||
|
|
||||||
; Keywords that mark conditional statements
|
; Keywords that mark conditional statements
|
||||||
[ "if" "elsif" "unless" "else" ] @conditional
|
[ "if" "elsif" "unless" "else" ] @conditional
|
||||||
|
(ternary_expression
|
||||||
|
["?" ":"] @conditional.ternary)
|
||||||
|
(ternary_expression_in_hash
|
||||||
|
["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
; Keywords that mark repeating loops
|
; Keywords that mark repeating loops
|
||||||
[ "while" "until" "for" "foreach" ] @repeat
|
[ "while" "until" "for" "foreach" ] @repeat
|
||||||
|
|
@ -142,8 +146,6 @@
|
||||||
(to_reference)
|
(to_reference)
|
||||||
(type_glob)
|
(type_glob)
|
||||||
(hash_access_variable)
|
(hash_access_variable)
|
||||||
(ternary_expression)
|
|
||||||
(ternary_expression_in_hash)
|
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -143,4 +143,4 @@
|
||||||
"=>"
|
"=>"
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
(ternary_expression [":" "?"] @conditional)
|
(ternary_expression [":" "?"] @conditional.ternary)
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@
|
||||||
":"
|
":"
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
(ternary_expression ["?" ":"] @conditional)
|
(ternary_expression ["?" ":"] @conditional.ternary)
|
||||||
|
|
||||||
; Options
|
; Options
|
||||||
((set_value) @number
|
((set_value) @number
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ logic = ${!foo && !(bar || baz) and not 'string'}
|
||||||
// ^operator
|
// ^operator
|
||||||
|
|
||||||
ternary = ${ check ? true : false}
|
ternary = ${ check ? true : false}
|
||||||
// ^punctuation.delimiter
|
// ^@conditional.ternary
|
||||||
// ^punctuation.delimiter
|
// ^@conditional.ternary
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue