blob: 38b413fe4330a51964765acaf0167e11a6e2bfb6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
; basic keywords
[
("assert")
("with")
("let")
("in")
("rec")
("inherit")
] @keyword
; if/then/else
[
("if")
("then")
("else")
] @conditional
; field access default (`a.b or c`)
("or") @keyword.operator
; comments
(comment) @comment
; strings
[ (string) (indented_string) ] @string
; paths and URLs
[ (path) (spath) (uri) ] @string.special
; escape sequences
(escape_sequence) @string.escape
; 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)
(function ":" @punctuation.special)
; basic identifiers
(identifier) @variable
; 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)
(select ((identifier) @_i (#eq? @_i "builtins")) (attrpath (attr_identifier) @variable.builtin)) @variable.builtin
; import
((identifier) @_i (#eq? @_i "import")) @include
; null
((identifier) @_i (#eq? @_i "import")) @constant.builtin
; 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
; fields (the `.` in `a.b = c;` isn't included)
(attrset (bind . (attrpath (attr_identifier) @field)))
(rec_attrset (bind . (attrpath (attr_identifier) @field)))
; unary operators
(unary "-" @operator)
(unary "!" @operator)
; binary operators
(binary "?" @operator)
(binary "++" @operator)
(binary "*" @operator)
(binary "/" @operator)
(binary "+" @operator)
(binary "-" @operator)
(binary "//" @operator)
(binary "<" @operator)
(binary "<=" @operator)
(binary ">" @operator)
(binary ">=" @operator)
(binary "==" @operator)
(binary "!=" @operator)
(binary "&&" @operator)
(binary "||" @operator)
(binary "->" @operator)
; integers, also highlight a unary -
[
(unary "-" (integer))
(integer)
] @number
; floats, also highlight a unary -
[
(unary "-" (float))
(float)
] @float
|