Skip to content

Commit

Permalink
feat(lang): Update Nix grammar & improve queries
Browse files Browse the repository at this point in the history
Update grammar and queiries to the latest upstream. Also add improved
indents thanks to @oxalica.
  • Loading branch information
nrdxp committed May 14, 2022
1 parent 823eaad commit 530fcd8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "nix"
source = { git = "https://github.com/cstrahan/tree-sitter-nix", rev = "50f38ceab667f9d482640edfee803d74f4edeba5" }
source = { git = "https://github.com/cstrahan/tree-sitter-nix", rev = "470b15a60520ff7b86f51732b8d8f1118c86041e" }

[[language]]
name = "ruby"
Expand Down
57 changes: 30 additions & 27 deletions runtime/queries/nix/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,81 +1,84 @@
(comment) @comment

[
"if"
"if"
"then"
"else"
"let"
"inherit"
"in"
"rec"
"with"
"with"
"assert"
"or"
] @keyword

((identifier) @variable.builtin
(#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins)$")
(#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins|false|null|true)$")
(#is-not? local))

((identifier) @function.builtin
(#match? @function.builtin "^(__add|__addErrorContext|__all|__any|__appendContext|__attrNames|__attrValues|__bitAnd|__bitOr|__bitXor|__catAttrs|__compareVersions|__concatLists|__concatMap|__concatStringsSep|__deepSeq|__div|__elem|__elemAt|__fetchurl|__filter|__filterSource|__findFile|__foldl'|__fromJSON|__functionArgs|__genList|__genericClosure|__getAttr|__getContext|__getEnv|__hasAttr|__hasContext|__hashFile|__hashString|__head|__intersectAttrs|__isAttrs|__isBool|__isFloat|__isFunction|__isInt|__isList|__isPath|__isString|__langVersion|__length|__lessThan|__listToAttrs|__mapAttrs|__match|__mul|__parseDrvName|__partition|__path|__pathExists|__readDir|__readFile|__replaceStrings|__seq|__sort|__split|__splitVersion|__storePath|__stringLength|__sub|__substring|__tail|__toFile|__toJSON|__toPath|__toXML|__trace|__tryEval|__typeOf|__unsafeDiscardOutputDependency|__unsafeDiscardStringContext|__unsafeGetAttrPos|__valueSize|abort|baseNameOf|derivation|derivationStrict|dirOf|fetchGit|fetchMercurial|fetchTarball|fromTOML|import|isNull|map|placeholder|removeAttrs|scopedImport|throw|toString)$")
(#is-not? local))

[
(string)
(indented_string)
(string_expression)
(indented_string_expression)
] @string

[
(path)
(hpath)
(spath)
(path_expression)
(hpath_expression)
(spath_expression)
] @string.special.path

(uri) @string.special.uri
(uri_expression) @string.special.uri

; boolean
((identifier) @constant.builtin.boolean (#match? @constant.builtin.boolean "^(true|false)$")) @constant.builtin.boolean
; null
((identifier) @constant.builtin (#eq? @constant.builtin "null")) @constant.builtin

(integer) @constant.numeric.integer
(float) @constant.numeric.float
(integer_expression) @constant.numeric.integer
(float_expression) @constant.numeric.float

(interpolation
"${" @punctuation.special
"}" @punctuation.special) @embedded

(escape_sequence) @constant.character.escape
(escape_sequence) @escape

(function
(function_expression
universal: (identifier) @variable.parameter
)

(formal
name: (identifier) @variable.parameter
"?"? @punctuation.delimiter)

(app
(select_expression
attrpath: (attrpath (identifier)) @variable.other.member)

(apply_expression
function: [
(identifier) @function
(select
(variable_expression (identifier)) @function
(select_expression
attrpath: (attrpath
attr: (attr_identifier) @function .))])

attr: (identifier) @function .))])

(unary
(unary_expression
operator: _ @operator)

(binary
(binary_expression
operator: _ @operator)

(attr_identifier) @variable.other.member
(inherit attrs: (attrs_inherited (identifier) @variable.other.member) )
(variable_expression (identifier) @variable)

(binding
attrpath: (attrpath (identifier)) @variable.other.member)

(identifier) @variable.other.member

[
";"
"."
","
"="
] @punctuation.delimiter

[
Expand Down
31 changes: 19 additions & 12 deletions runtime/queries/nix/indents.scm
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@

[
; "function",
(bind)
(assert)
(with)
; Bracket like
(let)
(if)

(attrset)
(list)
(indented_string)
(rec_attrset)
(let_attrset)
(parenthesized)
(list)

; Binding
(bind)
(inherit)
(inherit_from)
(formal)

; Binary operations
(binary)
(has_attr)
(select)
(app)
] @indent

[
"}"
"]"
] @outdent
; Conditional
(if) @indent

0 comments on commit 530fcd8

Please sign in to comment.