mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
feat(nu): add parser and queries (#7267)
This commit is contained in:
parent
509d38fee8
commit
604aa5a7c8
12 changed files with 449 additions and 0 deletions
|
|
@ -500,6 +500,9 @@
|
|||
"nqc": {
|
||||
"revision": "14e6da1627aaef21d2b2aa0c37d04269766dcc1d"
|
||||
},
|
||||
"nu": {
|
||||
"revision": "082a7c7df7db460da6b280c9f902bf2b19a2f423"
|
||||
},
|
||||
"objc": {
|
||||
"revision": "62e61b6f5c0289c376d61a8c91faf6435cde9012"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1469,6 +1469,14 @@ list.nqc = {
|
|||
maintainers = { "@amaanq" },
|
||||
}
|
||||
|
||||
list.nu = {
|
||||
install_info = {
|
||||
url = "https://github.com/nushell/tree-sitter-nu",
|
||||
files = { "src/parser.c" },
|
||||
},
|
||||
maintainers = { "@abhisheksingh0x558" },
|
||||
}
|
||||
|
||||
list.objc = {
|
||||
install_info = {
|
||||
url = "https://github.com/amaanq/tree-sitter-objc",
|
||||
|
|
|
|||
356
queries/nu/highlights.scm
Normal file
356
queries/nu/highlights.scm
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
; ---
|
||||
; keywords
|
||||
[
|
||||
"let"
|
||||
"let-env"
|
||||
"mut"
|
||||
"const"
|
||||
"hide-env"
|
||||
"source"
|
||||
"source-env"
|
||||
"overlay"
|
||||
"register"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"if"
|
||||
"else"
|
||||
"match"
|
||||
] @keyword.conditional
|
||||
|
||||
[
|
||||
"loop"
|
||||
"while"
|
||||
"break"
|
||||
"continue"
|
||||
] @keyword.repeat
|
||||
|
||||
[
|
||||
"def"
|
||||
"do"
|
||||
] @keyword.function
|
||||
|
||||
"return" @keyword.return
|
||||
|
||||
[
|
||||
"try"
|
||||
"catch"
|
||||
"error"
|
||||
] @keyword.exception
|
||||
|
||||
"module" @keyword.import
|
||||
|
||||
[
|
||||
"alias"
|
||||
"export-env"
|
||||
"export"
|
||||
"extern"
|
||||
] @keyword.modifier
|
||||
|
||||
(hide_mod
|
||||
"hide" @keyword)
|
||||
|
||||
(decl_use
|
||||
module: (unquoted) @module)
|
||||
|
||||
(ctrl_for
|
||||
"for" @keyword
|
||||
"in" @keyword)
|
||||
|
||||
(overlay_list
|
||||
"list" @keyword.import)
|
||||
|
||||
(overlay_hide
|
||||
"hide" @keyword.import)
|
||||
|
||||
(overlay_new
|
||||
"new" @keyword.import)
|
||||
|
||||
(overlay_use
|
||||
"use" @keyword.import
|
||||
"as" @keyword)
|
||||
|
||||
(ctrl_error
|
||||
"make" @keyword.import)
|
||||
|
||||
; ---
|
||||
; literals
|
||||
(val_number) @number
|
||||
|
||||
(val_duration
|
||||
unit: _ @variable.parameter)
|
||||
|
||||
(val_filesize
|
||||
unit: _ @variable.parameter)
|
||||
|
||||
(val_binary
|
||||
[
|
||||
"0b"
|
||||
"0o"
|
||||
"0x"
|
||||
] @number
|
||||
digit: [
|
||||
"," @punctuation.delimiter
|
||||
(hex_digit) @number
|
||||
]) @number
|
||||
|
||||
(val_bool) @constant.builtin
|
||||
|
||||
(val_nothing) @constant.builtin
|
||||
|
||||
(val_string) @string
|
||||
|
||||
arg_str: (val_string) @variable.parameter
|
||||
|
||||
file_path: (val_string) @variable.parameter
|
||||
|
||||
(val_date) @number
|
||||
|
||||
(inter_escape_sequence) @string.escape
|
||||
|
||||
(escape_sequence) @string.escape
|
||||
|
||||
(val_interpolated
|
||||
[
|
||||
"$\""
|
||||
"$'"
|
||||
"\""
|
||||
"'"
|
||||
] @string)
|
||||
|
||||
(unescaped_interpolated_content) @string
|
||||
|
||||
(escaped_interpolated_content) @string
|
||||
|
||||
(expr_interpolated
|
||||
[
|
||||
"("
|
||||
")"
|
||||
] @variable.parameter)
|
||||
|
||||
; ---
|
||||
; operators
|
||||
[
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"//"
|
||||
"++"
|
||||
"**"
|
||||
"=="
|
||||
"!="
|
||||
"<"
|
||||
"<="
|
||||
">"
|
||||
">="
|
||||
"=~"
|
||||
"!~"
|
||||
"="
|
||||
"+="
|
||||
"-="
|
||||
"*="
|
||||
"/="
|
||||
"++="
|
||||
"-"
|
||||
".."
|
||||
"..="
|
||||
"..<"
|
||||
"=>"
|
||||
"="
|
||||
"|"
|
||||
"o>"
|
||||
"out>"
|
||||
"e>"
|
||||
"err>"
|
||||
"e+o>"
|
||||
"err+out>"
|
||||
"o+e>"
|
||||
"out+err>"
|
||||
] @operator
|
||||
|
||||
[
|
||||
"mod"
|
||||
"and"
|
||||
"or"
|
||||
"xor"
|
||||
"bit-or"
|
||||
"bit-xor"
|
||||
"bit-and"
|
||||
"bit-shl"
|
||||
"bit-shr"
|
||||
"in"
|
||||
"not-in"
|
||||
"starts-with"
|
||||
"ends-with"
|
||||
"not"
|
||||
] @keyword.operator
|
||||
|
||||
; ---
|
||||
; punctuation
|
||||
[
|
||||
","
|
||||
";"
|
||||
":"
|
||||
] @punctuation.delimiter
|
||||
|
||||
(param_long_flag
|
||||
"--" @punctuation.delimiter)
|
||||
|
||||
(long_flag
|
||||
"--" @punctuation.delimiter)
|
||||
|
||||
(long_flag_equals_value
|
||||
"--" @punctuation.delimiter)
|
||||
|
||||
(short_flag
|
||||
"-" @punctuation.delimiter)
|
||||
|
||||
(long_flag_equals_value
|
||||
"=" @punctuation.delimiter)
|
||||
|
||||
(param_short_flag
|
||||
"-" @punctuation.delimiter)
|
||||
|
||||
(param_rest
|
||||
"..." @punctuation.delimiter)
|
||||
|
||||
(param_value
|
||||
"=" @punctuation.delimiter)
|
||||
|
||||
(param_cmd
|
||||
"@" @punctuation.delimiter)
|
||||
|
||||
(param_opt
|
||||
"?" @punctuation.delimiter)
|
||||
|
||||
(returns
|
||||
"->" @punctuation.delimiter)
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"{"
|
||||
"}"
|
||||
"["
|
||||
"]"
|
||||
] @punctuation.bracket
|
||||
|
||||
(parameter_pipes
|
||||
"|" @punctuation.bracket)
|
||||
|
||||
key: (identifier) @property
|
||||
|
||||
; ---
|
||||
; identifiers
|
||||
(param_rest
|
||||
name: (_) @variable.parameter)
|
||||
|
||||
(param_opt
|
||||
name: (_) @variable.parameter)
|
||||
|
||||
(parameter
|
||||
param_name: (_) @variable.parameter)
|
||||
|
||||
(param_cmd
|
||||
(cmd_identifier) @string)
|
||||
|
||||
(param_long_flag
|
||||
(long_flag_identifier) @attribute)
|
||||
|
||||
(param_short_flag
|
||||
(param_short_flag_identifier) @attribute)
|
||||
|
||||
(short_flag
|
||||
(short_flag_identifier) @attribute)
|
||||
|
||||
(long_flag_identifier) @attribute
|
||||
|
||||
(scope_pattern
|
||||
(wild_card) @function)
|
||||
|
||||
(cmd_identifier) @function
|
||||
|
||||
; generated with Nu 0.93.0
|
||||
; > help commands
|
||||
; | filter { $in.command_type == builtin and $in.category != core }
|
||||
; | each {$'"($in.name | split row " " | $in.0)"'}
|
||||
; | uniq
|
||||
; | str join ' '
|
||||
(command
|
||||
head: [
|
||||
(cmd_identifier) @function.builtin
|
||||
(#any-of? @function.builtin
|
||||
"all" "ansi" "any" "append" "ast" "bits" "bytes" "cal" "cd" "char" "clear" "collect" "columns"
|
||||
"compact" "complete" "config" "cp" "date" "debug" "decode" "default" "detect" "dfr" "drop"
|
||||
"du" "each" "encode" "enumerate" "every" "exec" "exit" "explain" "explore" "export-env" "fill"
|
||||
"filter" "find" "first" "flatten" "fmt" "format" "from" "generate" "get" "glob" "grid" "group"
|
||||
"group-by" "hash" "headers" "histogram" "history" "http" "input" "insert" "inspect"
|
||||
"interleave" "into" "is-empty" "is-not-empty" "is-terminal" "items" "join" "keybindings"
|
||||
"kill" "last" "length" "let-env" "lines" "load-env" "ls" "math" "merge" "metadata" "mkdir"
|
||||
"mktemp" "move" "mv" "nu-check" "nu-highlight" "open" "panic" "par-each" "parse" "path"
|
||||
"plugin" "port" "prepend" "print" "ps" "query" "random" "range" "reduce" "reject" "rename"
|
||||
"reverse" "rm" "roll" "rotate" "run-external" "save" "schema" "select" "seq" "shuffle" "skip"
|
||||
"sleep" "sort" "sort-by" "split" "split-by" "start" "stor" "str" "sys" "table" "take" "tee"
|
||||
"term" "timeit" "to" "touch" "transpose" "tutor" "ulimit" "uname" "uniq" "uniq-by" "update"
|
||||
"upsert" "url" "values" "view" "watch" "where" "which" "whoami" "window" "with-env" "wrap"
|
||||
"zip")
|
||||
])
|
||||
|
||||
(command
|
||||
"^" @punctuation.delimiter
|
||||
head: (_) @function)
|
||||
|
||||
"where" @function.builtin
|
||||
|
||||
(path
|
||||
[
|
||||
"."
|
||||
"?"
|
||||
] @punctuation.delimiter) @variable.parameter
|
||||
|
||||
(stmt_let
|
||||
(identifier) @variable)
|
||||
|
||||
(val_variable
|
||||
"$" @punctuation.special
|
||||
[
|
||||
(identifier) @variable
|
||||
"in" @variable.parameter.builtin
|
||||
"nu" @module
|
||||
"env" @constant
|
||||
]) @none
|
||||
|
||||
; ---
|
||||
; types
|
||||
(flat_type) @type
|
||||
|
||||
(list_type
|
||||
"list" @type.builtin
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
] @punctuation.bracket)
|
||||
|
||||
(collection_type
|
||||
[
|
||||
"record"
|
||||
"table"
|
||||
] @type.builtin
|
||||
"<" @punctuation.bracket
|
||||
key: (_) @variable.parameter
|
||||
[
|
||||
","
|
||||
":"
|
||||
] @punctuation.delimiter
|
||||
">" @punctuation.bracket)
|
||||
|
||||
(shebang) @keyword.directive
|
||||
|
||||
(comment) @comment @spell
|
||||
|
||||
((comment) @comment.documentation @spell
|
||||
(decl_def))
|
||||
|
||||
((parameter)
|
||||
(comment) @comment.documentation @spell)
|
||||
26
queries/nu/indents.scm
Normal file
26
queries/nu/indents.scm
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
; Forked from https://github.com/nushell/tree-sitter-nu
|
||||
; Copyright (c) 2019 - 2022 The Nushell Project Developers
|
||||
; Licensed under the MIT license.
|
||||
[
|
||||
(expr_parenthesized)
|
||||
(parameter_bracks)
|
||||
(val_record)
|
||||
(val_list)
|
||||
(val_closure)
|
||||
(val_table)
|
||||
(block)
|
||||
] @indent.begin
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @indent.end
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @indent.branch
|
||||
|
||||
(comment) @indent.auto
|
||||
5
queries/nu/injections.scm
Normal file
5
queries/nu/injections.scm
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
; Forked from https://github.com/nushell/tree-sitter-nu
|
||||
; Copyright (c) 2019 - 2022 The Nushell Project Developers
|
||||
; Licensed under the MIT license.
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
6
tests/indent/nu/closure.nu
Normal file
6
tests/indent/nu/closure.nu
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
do { |x, y|
|
||||
print ($x + $y);
|
||||
print ($x - $y);
|
||||
print ($x * $y);
|
||||
print ($x / $y);
|
||||
}
|
||||
3
tests/indent/nu/for.nu
Normal file
3
tests/indent/nu/for.nu
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for x in 1..3 {
|
||||
print ($x * $x)
|
||||
}
|
||||
5
tests/indent/nu/if_else.nu
Normal file
5
tests/indent/nu/if_else.nu
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
if true {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
7
tests/indent/nu/list.nu
Normal file
7
tests/indent/nu/list.nu
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
let my_list = [
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
qux
|
||||
quux
|
||||
]
|
||||
4
tests/indent/nu/record.nu
Normal file
4
tests/indent/nu/record.nu
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let my_record = {
|
||||
foo: "bar"
|
||||
bar: 1
|
||||
}
|
||||
9
tests/indent/nu/table.nu
Normal file
9
tests/indent/nu/table.nu
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let my_table = [
|
||||
[a b];
|
||||
[1 2]
|
||||
[3 4]
|
||||
[5 6]
|
||||
[7 8]
|
||||
[9 10]
|
||||
[11 12]
|
||||
]
|
||||
17
tests/indent/nu_spec.lua
Normal file
17
tests/indent/nu_spec.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local Runner = require("tests.indent.common").Runner
|
||||
--local XFAIL = require("tests.indent.common").XFAIL
|
||||
|
||||
local run = Runner:new(it, "tests/indent/nu", {
|
||||
tabstop = 2,
|
||||
shiftwidth = 2,
|
||||
softtabstop = -1,
|
||||
expandtab = true,
|
||||
})
|
||||
|
||||
describe("indent Nu:", function()
|
||||
describe("whole file:", function()
|
||||
run:whole_file(".", {
|
||||
expected_failures = {},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue