diff options
| author | leo60228 <iakornfeld@gmail.com> | 2020-11-18 16:52:41 -0500 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-11-22 22:29:55 +0100 |
| commit | ee0e8e8518a65e7ffc06ade7bab891b475caa5a2 (patch) | |
| tree | bf0495cbd0b69ef26476398cff61aa9af791aae9 /queries/nix | |
| parent | typescript: Add optional_parameter ? (diff) | |
| download | nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar.gz nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar.bz2 nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar.lz nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar.xz nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.tar.zst nvim-treesitter-ee0e8e8518a65e7ffc06ade7bab891b475caa5a2.zip | |
Initial Nix queries
Diffstat (limited to 'queries/nix')
| -rw-r--r-- | queries/nix/folds.scm | 11 | ||||
| -rw-r--r-- | queries/nix/highlights.scm | 110 | ||||
| -rw-r--r-- | queries/nix/locals.scm | 15 |
3 files changed, 136 insertions, 0 deletions
diff --git a/queries/nix/folds.scm b/queries/nix/folds.scm new file mode 100644 index 000000000..a62482e8b --- /dev/null +++ b/queries/nix/folds.scm @@ -0,0 +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_str) +] @fold diff --git a/queries/nix/highlights.scm b/queries/nix/highlights.scm new file mode 100644 index 000000000..d10fe6a49 --- /dev/null +++ b/queries/nix/highlights.scm @@ -0,0 +1,110 @@ +; basic keywords +[ + ("assert") + ("with") + ("let") + ("in") + ("rec") + ("inherit") +] @keyword + +; if/then/else +[ + ("if") + ("then") + ("else") +] @conditional + +; undocumented, I'm not actually sure what this does +("or") @keyword.operator + +; comments +(comment) @comment + +; strings +[ (string) (indented_string) ] @string + +; paths and URLs +[ (path) (spath) (uri) ] @string.special + +; 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 (identifier) @variable.builtin)) @variable.builtin + +; import +((identifier) @_i (#eq? @_i "import")) @include + +; 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 + +; integers, also highlight a unary - +[ + (unary "-" (integer)) + (integer) +] @number + +; floats, also highlight a unary - +[ + (unary "-" (float)) + (float) +] @float + +; 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) diff --git a/queries/nix/locals.scm b/queries/nix/locals.scm new file mode 100644 index 000000000..1720a848c --- /dev/null +++ b/queries/nix/locals.scm @@ -0,0 +1,15 @@ +; let bindings +(let (bind . (attrpath) @definition.var)) @scope + +; rec attrsets +(rec_attrset (bind . (attrpath) @definition.field)) @scope + +; functions and parameters +(function . [ + (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 |
