nvim-treesitter/queries/nix/highlights.scm

107 lines
2.6 KiB
Scheme
Raw Normal View History

2020-11-18 16:52:41 -05:00
; basic keywords
[
("assert")
("with")
("let")
("in")
("rec")
("inherit")
] @keyword
; if/then/else
[
("if")
("then")
("else")
] @conditional
2020-11-19 12:42:34 -05:00
; field access default (`a.b or c`)
2020-11-18 16:52:41 -05:00
("or") @keyword.operator
; comments
(comment) @comment
; strings
2022-05-22 13:22:01 +02:00
[ (string_expression) (indented_string_expression) ] @string
2020-11-18 16:52:41 -05:00
; paths and URLs
2022-05-22 13:22:01 +02:00
[ (path_expression) (spath_expression) (uri_expression) ] @string.special
2020-11-18 16:52:41 -05:00
2020-11-19 15:16:07 -05:00
; escape sequences
(escape_sequence) @string.escape
2020-11-18 16:52:41 -05:00
; delimiters
[
"."
";"
","
] @punctuation.delimiter
; brackets
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
; `?` in `{ x ? y }:`, used to set defaults for named function arguments
; I'm not really sure what group this should go in, but it should probably have highlighting, so I'm putting it in @punctuation.special
(formal "?" @punctuation.special)
; `...` in `{ ... }`, used to ignore unknown named function arguments (see above)
(ellipses) @punctuation.special
; `:` in `x: y`, used to separate function argument from body (see above)
2022-05-22 13:22:01 +02:00
(function_expression ":" @punctuation.special)
2020-11-18 16:52:41 -05:00
; basic identifiers
2022-05-22 13:22:01 +02:00
(variable_expression) @variable
2020-11-18 16:52:41 -05:00
; builtin functions
((identifier) @_i (#match? @_i "^(builtins|baseNameOf|dirOf|fetchTarball|map|removeAttrs|toString)$")) @variable.builtin
; display entire builtins path as builtin (ex. `builtins.filter` is highlighted as one long builtin)
2022-05-22 13:22:01 +02:00
(select_expression
expression: ((variable_expression) @_i (#eq? @_i "builtins"))
attrpath: (attrpath attr: (identifier) @variable.builtin)) @variable.builtin
2020-11-18 16:52:41 -05:00
; import
((identifier) @_i (#eq? @_i "import")) @include
2020-11-19 13:35:30 -05:00
; null
((identifier) @_i (#eq? @_i "import")) @constant.builtin
2020-11-18 16:52:41 -05:00
; these are technically functions but they act more like keywords (abort and throw are control flow, derivation is a core language construct)
((identifier) @_i (#match? @_i "^(abort|derivation|throw)$")) @keyword
; booleans
((identifier) @_i (#match? @_i "^(true|false)$")) @boolean
; string interpolation (this was very annoying to get working properly)
(interpolation "${" @punctuation.special (_) "}" @punctuation.special) @none
2020-11-18 17:43:17 -05:00
; fields (the `.` in `a.b = c;` isn't included)
2022-05-22 13:22:01 +02:00
(attrset_expression (binding_set (binding . (attrpath (identifier) @field))))
(rec_attrset_expression (binding_set (binding . (attrpath (identifier) @field))))
2020-11-18 17:43:17 -05:00
2020-11-18 16:52:41 -05:00
; unary operators
2022-05-22 13:22:01 +02:00
(unary_expression operator: _ @operator)
2020-11-18 16:52:41 -05:00
; binary operators
2022-05-22 13:22:01 +02:00
(binary_expression operator: _ @operator)
2020-11-19 12:47:10 -05:00
; integers, also highlight a unary -
[
2022-05-22 13:22:01 +02:00
(unary_expression "-" (integer_expression))
(integer_expression)
2020-11-19 12:47:10 -05:00
] @number
; floats, also highlight a unary -
[
2022-05-22 13:22:01 +02:00
(unary_expression "-" (float_expression))
(float_expression)
2020-11-19 12:47:10 -05:00
] @float