mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
Update new query and parser for zig
This commit is contained in:
parent
1e19898703
commit
9b265c9c4c
6 changed files with 225 additions and 228 deletions
|
|
@ -633,11 +633,12 @@ list.bibtex = {
|
||||||
|
|
||||||
list.zig = {
|
list.zig = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = "https://github.com/Himujjal/tree-sitter-zig",
|
url = "https://github.com/maxxnino/tree-sitter-zig",
|
||||||
files = { "src/parser.c" },
|
files = { "src/parser.c" },
|
||||||
|
branch = "main",
|
||||||
},
|
},
|
||||||
filetype = "zig",
|
filetype = "zig",
|
||||||
maintainers = { "@Himujjal" },
|
maintainers = { "@maxxnino" },
|
||||||
}
|
}
|
||||||
|
|
||||||
list.fortran = {
|
list.fortran = {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
[
|
[
|
||||||
(block)
|
(Block)
|
||||||
(comptime_block)
|
(ContainerDecl)
|
||||||
(defer_block)
|
(SwitchExpr)
|
||||||
(suspend_block)
|
(AsmExpr)
|
||||||
(resume_block)
|
|
||||||
(if_expression)
|
|
||||||
(switch_block)
|
|
||||||
(for_expression)
|
|
||||||
(test_expression)
|
|
||||||
(struct_expression)
|
|
||||||
(anonymous_struct_enum)
|
|
||||||
(anonymous_array_expr)
|
|
||||||
(union_expression)
|
|
||||||
(enum_expression)
|
|
||||||
] @fold
|
] @fold
|
||||||
|
|
|
||||||
|
|
@ -1,147 +1,158 @@
|
||||||
|
[
|
||||||
|
(container_doc_comment)
|
||||||
|
(doc_comment)
|
||||||
|
(line_comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
; Zig
|
(IDENTIFIER) @variable
|
||||||
|
|
||||||
; Variables
|
;field in top level decl, and in struct, union...
|
||||||
; --------------
|
(ContainerField
|
||||||
(identifier) @variable
|
(IDENTIFIER) @field
|
||||||
|
(SuffixExpr (IDENTIFIER) @type)?
|
||||||
(parameter (identifier) @variable)
|
|
||||||
|
|
||||||
; ((identifier) @constant
|
|
||||||
; (#vim-match? @constant "^[A-Z][A-Z\\d_]+$'"))
|
|
||||||
|
|
||||||
; function definition
|
|
||||||
(function_signature
|
|
||||||
name: (identifier) @function)
|
|
||||||
|
|
||||||
(function_declaration
|
|
||||||
name: (identifier) @function
|
|
||||||
return: (identifier) @type)
|
|
||||||
|
|
||||||
; Function calls
|
|
||||||
(call_expression
|
|
||||||
function: (identifier) @function)
|
|
||||||
|
|
||||||
(build_in_call_expr
|
|
||||||
function: (identifier) @function.builtin
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(build_in_call_expr
|
; INFO: field become a function if type is a function?
|
||||||
function: ((identifier) @include
|
; const u = union { this_is_function: fn () void };
|
||||||
(#any-of? @include "@import" "@cImport"))
|
(ContainerField
|
||||||
|
(IDENTIFIER) @function
|
||||||
|
(SuffixExpr (FnProto))
|
||||||
)
|
)
|
||||||
|
|
||||||
(struct_construction
|
;enum and tag union field is constant
|
||||||
(type_identifier) @constructor
|
(
|
||||||
|
[
|
||||||
|
; union(Tag){}
|
||||||
|
(ContainerDeclType (SuffixExpr (IDENTIFIER) @type))
|
||||||
|
|
||||||
|
; enum{}
|
||||||
|
(ContainerDeclType "enum")
|
||||||
|
]
|
||||||
|
(ContainerField (IDENTIFIER) @constant)?
|
||||||
)
|
)
|
||||||
|
|
||||||
;; other identifiers
|
; INFO: .IDENTIFIER is a field?
|
||||||
(type_identifier) @type
|
(SuffixExpr
|
||||||
(custom_number_type) @type.builtin
|
"."
|
||||||
(primitive_type) @type.builtin
|
(IDENTIFIER) @field
|
||||||
(field_identifier) @field
|
)
|
||||||
(enum_identifier) @constant
|
|
||||||
(union_identifier) @field
|
|
||||||
(error_identifier) @field
|
|
||||||
|
|
||||||
(assignment_statement
|
; error.OutOfMemory;
|
||||||
name: (identifier) @type
|
(SuffixExpr
|
||||||
expression: [
|
"error"
|
||||||
(enum_expression)
|
"."
|
||||||
(union_expression)
|
(IDENTIFIER) @constant
|
||||||
(error_expression)
|
)
|
||||||
(struct_expression)
|
|
||||||
|
(VarDecl
|
||||||
|
(IDENTIFIER) @type
|
||||||
|
[
|
||||||
|
; const IDENTIFIER = struct/enum/union...
|
||||||
|
(SuffixExpr (ContainerDecl))
|
||||||
|
|
||||||
|
; const A = u8;
|
||||||
|
(SuffixExpr (BuildinTypeExpr))
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
(line_comment) @comment
|
; const fn_no_comma = fn (i32, i32) void;
|
||||||
(doc_comment) @comment
|
(VarDecl
|
||||||
|
(IDENTIFIER) @function
|
||||||
|
(SuffixExpr (FnProto))
|
||||||
|
)
|
||||||
|
|
||||||
(char_literal) @character
|
; var x: IDENTIFIER
|
||||||
(integer_literal) @number
|
type: (SuffixExpr (IDENTIFIER) @type)
|
||||||
(float_literal) @number
|
|
||||||
|
|
||||||
(boolean_literal) @boolean
|
; IDENTIFIER{}
|
||||||
(undefined_literal) @constant.builtin
|
constructor: (SuffixExpr (IDENTIFIER) @constructor)
|
||||||
(unreachable_expression) @constant.builtin
|
|
||||||
(null_literal) @constant.builtin
|
|
||||||
|
|
||||||
; (ERROR) @error
|
;{.IDENTIFIER = 1}
|
||||||
|
(FieldInit (IDENTIFIER) @field)
|
||||||
|
|
||||||
(string_literal) @string
|
; var.field
|
||||||
(multiline_string_literal) @string
|
(SuffixOp (IDENTIFIER) @field)
|
||||||
|
|
||||||
(escape_sequence) @string.escape
|
; var.func().func().field
|
||||||
(char_literal (escape_sequence) @character)
|
(
|
||||||
|
(SuffixOp
|
||||||
|
(IDENTIFIER) @function
|
||||||
|
)
|
||||||
|
.
|
||||||
|
(FnCallArguments)
|
||||||
|
)
|
||||||
|
; func()
|
||||||
|
(
|
||||||
|
(
|
||||||
|
(IDENTIFIER) @function
|
||||||
|
)
|
||||||
|
.
|
||||||
|
(FnCallArguments)
|
||||||
|
)
|
||||||
|
|
||||||
(label_identifier) @label
|
; functionn decl
|
||||||
|
(FnProto
|
||||||
|
(IDENTIFIER) @function
|
||||||
|
(SuffixExpr (IDENTIFIER) @type)?
|
||||||
|
("!")? @exception
|
||||||
|
)
|
||||||
|
|
||||||
(call_modifier) @keyword ; async
|
|
||||||
|
|
||||||
(binary_operator) @keyword.operator
|
(ParamDecl
|
||||||
|
(ParamType (SuffixExpr (IDENTIFIER) @parameter))
|
||||||
|
)
|
||||||
|
|
||||||
|
(ParamDecl
|
||||||
|
(IDENTIFIER) @parameter
|
||||||
|
":"
|
||||||
|
[
|
||||||
|
(ParamType (SuffixExpr (IDENTIFIER) @type))
|
||||||
|
(ParamType)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
(BUILTINIDENTIFIER) @function.builtin
|
||||||
|
|
||||||
|
((BUILTINIDENTIFIER) @include
|
||||||
|
(#any-of? @include "@import" "@cImport"))
|
||||||
|
|
||||||
|
|
||||||
|
(INTEGER) @number
|
||||||
|
|
||||||
|
(FLOAT) @float
|
||||||
|
|
||||||
|
[
|
||||||
|
(STRINGLITERAL)
|
||||||
|
(STRINGLITERALSINGLE)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
(CHAR_LITERAL) @character
|
||||||
|
|
||||||
[
|
[
|
||||||
"align"
|
|
||||||
"allowzero"
|
"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"
|
"volatile"
|
||||||
"while"
|
"anytype"
|
||||||
] @keyword
|
"anyframe"
|
||||||
|
(BuildinTypeExpr)
|
||||||
|
] @type.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(BreakLabel)
|
||||||
|
(BlockLabel)
|
||||||
|
] @label
|
||||||
|
|
||||||
[
|
[
|
||||||
"true"
|
"true"
|
||||||
"false"
|
"false"
|
||||||
] @boolean
|
] @boolean
|
||||||
|
|
||||||
"return" @keyword.return
|
[
|
||||||
|
"undefined"
|
||||||
"fn" @keyword.function
|
"unreachable"
|
||||||
|
"null"
|
||||||
|
] @constant.builtin
|
||||||
|
|
||||||
[
|
[
|
||||||
(else_switch)
|
|
||||||
"continue"
|
|
||||||
"else"
|
"else"
|
||||||
"if"
|
"if"
|
||||||
"switch"
|
"switch"
|
||||||
|
|
@ -152,71 +163,97 @@
|
||||||
"while"
|
"while"
|
||||||
] @repeat
|
] @repeat
|
||||||
|
|
||||||
(assignment_modifier) @attribute
|
[
|
||||||
|
"or"
|
||||||
|
"and"
|
||||||
|
(BitwiseOp "orelse")
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
[
|
[
|
||||||
".{"
|
"struct"
|
||||||
"("
|
"enum"
|
||||||
")"
|
"union"
|
||||||
"["
|
"error"
|
||||||
"]"
|
"packed"
|
||||||
"{"
|
"opaque"
|
||||||
"}"
|
] @keyword
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"&"
|
"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
|
] @operator
|
||||||
|
|
||||||
[
|
[
|
||||||
";"
|
";"
|
||||||
"."
|
"."
|
||||||
","
|
","
|
||||||
|
":"
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,9 @@
|
||||||
[
|
[
|
||||||
(block)
|
; BUG: why function block not indent
|
||||||
(comptime_block)
|
(Block)
|
||||||
(defer_block)
|
(ContainerDecl)
|
||||||
(suspend_block)
|
(SwitchExpr)
|
||||||
(resume_block)
|
(InitList)
|
||||||
(if_expression)
|
|
||||||
(while_expression)
|
|
||||||
(for_expression)
|
|
||||||
(test_expression)
|
|
||||||
(struct_expression)
|
|
||||||
(struct_construction)
|
|
||||||
(anonymous_struct_enum)
|
|
||||||
(anonymous_array_expr)
|
|
||||||
(enum_expression)
|
|
||||||
(union_expression)
|
|
||||||
] @indent
|
] @indent
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
@ -27,5 +17,7 @@
|
||||||
|
|
||||||
[
|
[
|
||||||
(line_comment)
|
(line_comment)
|
||||||
(multiline_string_literal)
|
(container_doc_comment)
|
||||||
|
(doc_comment)
|
||||||
|
(STRINGLITERAL)
|
||||||
] @ignore
|
] @ignore
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
(line_comment) @comment
|
[
|
||||||
|
(container_doc_comment)
|
||||||
|
(doc_comment)
|
||||||
|
(line_comment)
|
||||||
|
] @comment
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue