diff options
| author | Minijackson <minijackson@riseup.net> | 2022-05-22 13:22:01 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-05-24 01:06:15 +0200 |
| commit | 29b0ea8093c49fe1ae639f41279f23a1a95f5cf0 (patch) | |
| tree | 4415730c311a15cd5ce43f0334cc7b7608b06e5f /queries/nix | |
| parent | 3e0cc6b872116d829e56629b442526e057e5724e (diff) | |
fix(nix): update parser and queries
Diffstat (limited to 'queries/nix')
| -rw-r--r-- | queries/nix/folds.scm | 16 | ||||
| -rw-r--r-- | queries/nix/highlights.scm | 44 | ||||
| -rw-r--r-- | queries/nix/locals.scm | 10 |
3 files changed, 28 insertions, 42 deletions
diff --git a/queries/nix/folds.scm b/queries/nix/folds.scm index 72050aa6..a89a5b24 100644 --- a/queries/nix/folds.scm +++ b/queries/nix/folds.scm @@ -1,11 +1,11 @@ ; Nix doesn't really have blocks, so just guess what people might want folds for [ - (if) - (with) - (let) - (function) - (attrset) - (rec_attrset) - (list) - (indented_string) + (if_expression) + (with_expression) + (let_expression) + (function_expression) + (attrset_expression) + (rec_attrset_expression) + (list_expression) + (indented_string_expression) ] @fold diff --git a/queries/nix/highlights.scm b/queries/nix/highlights.scm index 38b413fe..25f192b0 100644 --- a/queries/nix/highlights.scm +++ b/queries/nix/highlights.scm @@ -22,10 +22,10 @@ (comment) @comment ; strings -[ (string) (indented_string) ] @string +[ (string_expression) (indented_string_expression) ] @string ; paths and URLs -[ (path) (spath) (uri) ] @string.special +[ (path_expression) (spath_expression) (uri_expression) ] @string.special ; escape sequences (escape_sequence) @string.escape @@ -55,16 +55,18 @@ (ellipses) @punctuation.special ; `:` in `x: y`, used to separate function argument from body (see above) -(function ":" @punctuation.special) +(function_expression ":" @punctuation.special) ; basic identifiers -(identifier) @variable +(variable_expression) @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 +(select_expression + expression: ((variable_expression) @_i (#eq? @_i "builtins")) + attrpath: (attrpath attr: (identifier) @variable.builtin)) @variable.builtin ; import ((identifier) @_i (#eq? @_i "import")) @include @@ -82,39 +84,23 @@ (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))) +(attrset_expression (binding_set (binding . (attrpath (identifier) @field)))) +(rec_attrset_expression (binding_set (binding . (attrpath (identifier) @field)))) ; unary operators -(unary "-" @operator) -(unary "!" @operator) +(unary_expression operator: _ @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) +(binary_expression operator: _ @operator) ; integers, also highlight a unary - [ - (unary "-" (integer)) - (integer) + (unary_expression "-" (integer_expression)) + (integer_expression) ] @number ; floats, also highlight a unary - [ - (unary "-" (float)) - (float) + (unary_expression "-" (float_expression)) + (float_expression) ] @float diff --git a/queries/nix/locals.scm b/queries/nix/locals.scm index 1720a848..1fc06d8b 100644 --- a/queries/nix/locals.scm +++ b/queries/nix/locals.scm @@ -1,15 +1,15 @@ ; let bindings -(let (bind . (attrpath) @definition.var)) @scope +(let_expression (binding_set (binding . (attrpath) @definition.var))) @scope ; rec attrsets -(rec_attrset (bind . (attrpath) @definition.field)) @scope +(rec_attrset_expression (binding_set (binding . (attrpath) @definition.field))) @scope ; functions and parameters -(function . [ +(function_expression . [ (identifier) @definition.parameter (formals (formal . (identifier) @definition.parameter)) ]) @scope ((formals) "@" (identifier) @definition.parameter) ; I couldn't get this to work properly inside the (function) -; some identifiers can't be references, but @reference doesn't seem to have an inverse like @none -(identifier) @reference +(variable_expression (identifier) @reference) +(inherited_attrs attr: (identifier) @reference) |
