aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaxxnino <idonthaveemail@dontknow.com>2021-08-08 18:54:24 +0900
committerStephan Seitz <stephan.lauf@yahoo.de>2021-08-11 08:16:16 +0200
commit53160520e2ee5f8e255ed181294e5452b04140f0 (patch)
tree473b296928eee77c70f9fd67a28961f67022aec2
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar.gz
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar.bz2
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar.lz
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar.xz
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.tar.zst
nvim-treesitter-53160520e2ee5f8e255ed181294e5452b04140f0.zip
Update new query and parser for zig
-rw-r--r--lua/nvim-treesitter/parsers.lua5
-rw-r--r--queries/zig/folds.scm18
-rw-r--r--queries/zig/highlights.scm365
-rw-r--r--queries/zig/indents.scm24
-rw-r--r--queries/zig/injections.scm6
-rw-r--r--queries/zig/locals.scm27
6 files changed, 221 insertions, 224 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index afe02f708..eef3262bb 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -633,11 +633,12 @@ list.bibtex = {
list.zig = {
install_info = {
- url = "https://github.com/Himujjal/tree-sitter-zig",
+ url = "https://github.com/maxxnino/tree-sitter-zig",
files = { "src/parser.c" },
+ branch = "main",
},
filetype = "zig",
- maintainers = { "@Himujjal" },
+ maintainers = { "@maxxnino" },
}
list.fortran = {
diff --git a/queries/zig/folds.scm b/queries/zig/folds.scm
index 0001b0e1a..70c1f7439 100644
--- a/queries/zig/folds.scm
+++ b/queries/zig/folds.scm
@@ -1,16 +1,6 @@
[
- (block)
- (comptime_block)
- (defer_block)
- (suspend_block)
- (resume_block)
- (if_expression)
- (switch_block)
- (for_expression)
- (test_expression)
- (struct_expression)
- (anonymous_struct_enum)
- (anonymous_array_expr)
- (union_expression)
- (enum_expression)
+ (Block)
+ (ContainerDecl)
+ (SwitchExpr)
+ (AsmExpr)
] @fold
diff --git a/queries/zig/highlights.scm b/queries/zig/highlights.scm
index 6f0c0a84d..06daf0f99 100644
--- a/queries/zig/highlights.scm
+++ b/queries/zig/highlights.scm
@@ -1,147 +1,158 @@
+[
+ (container_doc_comment)
+ (doc_comment)
+ (line_comment)
+] @comment
-; Zig
-
-; Variables
-; --------------
-(identifier) @variable
+(IDENTIFIER) @variable
-(parameter (identifier) @variable)
+;field in top level decl, and in struct, union...
+(ContainerField
+ (IDENTIFIER) @field
+ (SuffixExpr (IDENTIFIER) @type)?
+)
-; ((identifier) @constant
-; (#vim-match? @constant "^[A-Z][A-Z\\d_]+$'"))
+; INFO: field become a function if type is a function?
+; const u = union { this_is_function: fn () void };
+(ContainerField
+ (IDENTIFIER) @function
+ (SuffixExpr (FnProto))
+)
-; function definition
-(function_signature
- name: (identifier) @function)
+;enum and tag union field is constant
+(
+ [
+ ; union(Tag){}
+ (ContainerDeclType (SuffixExpr (IDENTIFIER) @type))
-(function_declaration
- name: (identifier) @function
- return: (identifier) @type)
+ ; enum{}
+ (ContainerDeclType "enum")
+ ]
+ (ContainerField (IDENTIFIER) @constant)?
+)
-; Function calls
-(call_expression
- function: (identifier) @function)
+; INFO: .IDENTIFIER is a field?
+(SuffixExpr
+ "."
+ (IDENTIFIER) @field
+)
-(build_in_call_expr
- function: (identifier) @function.builtin
+; error.OutOfMemory;
+(SuffixExpr
+ "error"
+ "."
+ (IDENTIFIER) @constant
)
-(build_in_call_expr
- function: ((identifier) @include
- (#any-of? @include "@import" "@cImport"))
+(VarDecl
+ (IDENTIFIER) @type
+ [
+ ; const IDENTIFIER = struct/enum/union...
+ (SuffixExpr (ContainerDecl))
+
+ ; const A = u8;
+ (SuffixExpr (BuildinTypeExpr))
+ ]
)
-(struct_construction
- (type_identifier) @constructor
+; const fn_no_comma = fn (i32, i32) void;
+(VarDecl
+ (IDENTIFIER) @function
+ (SuffixExpr (FnProto))
)
-;; other identifiers
-(type_identifier) @type
-(custom_number_type) @type.builtin
-(primitive_type) @type.builtin
-(field_identifier) @field
-(enum_identifier) @constant
-(union_identifier) @field
-(error_identifier) @field
+; var x: IDENTIFIER
+type: (SuffixExpr (IDENTIFIER) @type)
-(assignment_statement
- name: (identifier) @type
- expression: [
- (enum_expression)
- (union_expression)
- (error_expression)
- (struct_expression)
- ]
+; IDENTIFIER{}
+constructor: (SuffixExpr (IDENTIFIER) @constructor)
+
+;{.IDENTIFIER = 1}
+(FieldInit (IDENTIFIER) @field)
+
+; var.field
+(SuffixOp (IDENTIFIER) @field)
+
+; var.func().func().field
+(
+ (SuffixOp
+ (IDENTIFIER) @function
+ )
+ .
+ (FnCallArguments)
+)
+; func()
+(
+ (
+ (IDENTIFIER) @function
+ )
+ .
+ (FnCallArguments)
)
-(line_comment) @comment
-(doc_comment) @comment
+; functionn decl
+(FnProto
+ (IDENTIFIER) @function
+ (SuffixExpr (IDENTIFIER) @type)?
+ ("!")? @exception
+)
-(char_literal) @character
-(integer_literal) @number
-(float_literal) @number
-(boolean_literal) @boolean
-(undefined_literal) @constant.builtin
-(unreachable_expression) @constant.builtin
-(null_literal) @constant.builtin
+(ParamDecl
+ (ParamType (SuffixExpr (IDENTIFIER) @parameter))
+)
-; (ERROR) @error
+(ParamDecl
+ (IDENTIFIER) @parameter
+ ":"
+ [
+ (ParamType (SuffixExpr (IDENTIFIER) @type))
+ (ParamType)
+ ]
+)
-(string_literal) @string
-(multiline_string_literal) @string
+(BUILTINIDENTIFIER) @function.builtin
-(escape_sequence) @string.escape
-(char_literal (escape_sequence) @character)
+((BUILTINIDENTIFIER) @include
+ (#any-of? @include "@import" "@cImport"))
-(label_identifier) @label
-(call_modifier) @keyword ; async
+(INTEGER) @number
-(binary_operator) @keyword.operator
+(FLOAT) @float
+
+[
+ (STRINGLITERAL)
+ (STRINGLITERALSINGLE)
+] @string
+
+(CHAR_LITERAL) @character
[
- "align"
"allowzero"
- ; "and"
- ; "anyframe"
- ; "anytype"
- ;"asm"
- "await"
- "break"
- ; "callconv"
- ; "catch"
- "comptime"
- "const"
- "continue"
- "defer"
- "else"
- "enum"
- "errdefer"
- "error"
- "export"
- "extern"
- "for"
- "if"
- "inline"
- ; "noalias"
- ; "nosuspend"
- ; "noinline"
- "null"
- ; "opaque"
- ; "or"
- ; "orelse"
- ; "packed"
- "pub"
- "resume"
- ; "linksection"
- "struct"
- "suspend"
- "switch"
- "test"
- ; "threadlocal"
- "try"
- ; "undefined"
- "union"
- ;"unreachable"
- "usingnamespace"
- "var"
"volatile"
- "while"
-] @keyword
+ "anytype"
+ "anyframe"
+ (BuildinTypeExpr)
+] @type.builtin
+
+[
+ (BreakLabel)
+ (BlockLabel)
+] @label
[
"true"
"false"
] @boolean
-"return" @keyword.return
-
-"fn" @keyword.function
+[
+ "undefined"
+ "unreachable"
+ "null"
+] @constant.builtin
[
- (else_switch)
- "continue"
"else"
"if"
"switch"
@@ -152,71 +163,97 @@
"while"
] @repeat
-(assignment_modifier) @attribute
+[
+ "or"
+ "and"
+ (BitwiseOp "orelse")
+] @keyword.operator
[
- ".{"
- "("
- ")"
- "["
- "]"
- "{"
- "}"
-] @punctuation.bracket
+ "struct"
+ "enum"
+ "union"
+ "error"
+ "packed"
+ "opaque"
+] @keyword
[
- "&"
- "&="
- "*"
- "*="
- ;"*%"
- "*%="
- ;"^"
- "^="
- ":"
- ","
- "."
- ".."
- "..."
- ".*"
- ".?"
- "="
- ;"=="
- "=>"
- "!"
- ;"!="
- ;"<"
- ;"<<"
- "<<="
- ; "<="
- "-"
- "-="
- "-%"
- "-%="
- ;"->"
- ;"%"
- "%="
- "|"
- ;"||"
- "|="
- ;"+"
- ;"++"
- "+="
- ;"+%"
- "+%="
- "?"
- ;">"
- ;">>"
- ">>="
- ;">="
- ;"/"
- "/="
- "~"
+ "try"
+ "error"
+ "catch"
+] @exception
+
+; VarDecl
+[
+ "const"
+ "var"
+ "comptime"
+ "threadlocal"
+ "fn"
+] @keyword.function
+
+[
+ "test"
+ "pub"
+ "usingnamespace"
+] @keyword
+
+[
+ "return"
+ "break"
+ "continue"
+] @keyword.return
+
+; Macro
+[
+ "defer"
+ "errdefer"
+ "async"
+ "nosuspend"
+ "await"
+ "suspend"
+ "resume"
+ "export"
+ "extern"
+] @function.macro
+
+; PrecProc
+[
+ (BitwiseOp "orelse")
+ "inline"
+ "noinline"
+ "asm"
+ "callconv"
+ "noalias"
+] @attribute
+
+[
+ "linksection"
+ "align"
+] @function.builtin
+
+[
+ (CompareOp)
+ (BitwiseOp)
+ (BitShiftOp)
+ (AdditionOp)
+ (MultiplyOp)
+ (PrefixOp)
] @operator
[
";"
"."
","
+ ":"
] @punctuation.delimiter
+[
+ "["
+ "]"
+ "("
+ ")"
+ "{"
+ "}"
+] @punctuation.bracket
diff --git a/queries/zig/indents.scm b/queries/zig/indents.scm
index aba56f4a5..97710195d 100644
--- a/queries/zig/indents.scm
+++ b/queries/zig/indents.scm
@@ -1,19 +1,9 @@
[
- (block)
- (comptime_block)
- (defer_block)
- (suspend_block)
- (resume_block)
- (if_expression)
- (while_expression)
- (for_expression)
- (test_expression)
- (struct_expression)
- (struct_construction)
- (anonymous_struct_enum)
- (anonymous_array_expr)
- (enum_expression)
- (union_expression)
+ ; BUG: why function block not indent
+ (Block)
+ (ContainerDecl)
+ (SwitchExpr)
+ (InitList)
] @indent
[
@@ -27,5 +17,7 @@
[
(line_comment)
- (multiline_string_literal)
+ (container_doc_comment)
+ (doc_comment)
+ (STRINGLITERAL)
] @ignore
diff --git a/queries/zig/injections.scm b/queries/zig/injections.scm
index a7dbad4a5..e3ff406d3 100644
--- a/queries/zig/injections.scm
+++ b/queries/zig/injections.scm
@@ -1 +1,5 @@
-(line_comment) @comment
+[
+ (container_doc_comment)
+ (doc_comment)
+ (line_comment)
+] @comment
diff --git a/queries/zig/locals.scm b/queries/zig/locals.scm
index 54bb4d2e3..e69de29bb 100644
--- a/queries/zig/locals.scm
+++ b/queries/zig/locals.scm
@@ -1,27 +0,0 @@
-
-(function_declaration
- name: (identifier) @definition.function
-)
-
-((type_identifier) @reference
- (set! reference.kind "type"))
-
-(assignment_statement
- name: (identifier) @definition.var
-)
-
-(identifier) @reference
-
-; Scopes
-[
- (block)
- (comptime_block)
- (defer_block)
- (suspend_block)
- (resume_block)
- (if_expression)
- (while_expression)
- (for_expression)
- (test_expression)
- (anonymous_array_expr)
-] @scope