Skip to content

Commit

Permalink
update zig grammar and highlight rules (helix-editor#3621)
Browse files Browse the repository at this point in the history
  • Loading branch information
voroskoi authored and Shekhinah Memmel committed Dec 11, 2022
1 parent 7d2667b commit 0f1ded5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 53 deletions.
3 changes: 1 addition & 2 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,9 @@ language-server = { command = "zls" }
indent = { tab-width = 4, unit = " " }
formatter = { command = "zig" , args = ["fmt", "--stdin"] }


[[grammar]]
name = "zig"
source = { git = "https://github.com/maxxnino/tree-sitter-zig", rev = "93331b8bd8b4ebee2b575490b2758f16ad4e9f30" }
source = { git = "https://github.com/maxxnino/tree-sitter-zig", rev = "8d3224c3bd0890fe08358886ebf54fca2ed448a6" }

[[language]]
name = "prolog"
Expand Down
96 changes: 45 additions & 51 deletions runtime/queries/zig/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
[
(container_doc_comment)
(doc_comment)
(line_comment)
] @comment
] @comment.documentation

[
variable: (IDENTIFIER)
variable_type_function: (IDENTIFIER)
] @variable

parameter: (IDENTIFIER) @variable.parameter

[
field_member: (IDENTIFIER)
field_access: (IDENTIFIER)
] @variable.other.member
(line_comment)
] @comment.line

;; assume TitleCase is a type
(
Expand All @@ -25,6 +16,7 @@ parameter: (IDENTIFIER) @variable.parameter
] @type
(#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)*$")
)

;; assume camelCase is a function
(
[
Expand All @@ -44,29 +36,33 @@ parameter: (IDENTIFIER) @variable.parameter
(#match? @constant "^[A-Z][A-Z_0-9]+$")
)

[
function_call: (IDENTIFIER)
function: (IDENTIFIER)
] @function

exception: "!" @function.macro

;; _
(
(IDENTIFIER) @variable.builtin
(#eq? @variable.builtin "_")
)

;; C Pointers [*c]T
(PtrTypeStart "c" @variable.builtin)

(
(ContainerDeclType
[
(ErrorUnionExpr)
"enum"
]
)
(ContainerField (IDENTIFIER) @constant)
)
[
variable: (IDENTIFIER)
variable_type_function: (IDENTIFIER)
] @variable

parameter: (IDENTIFIER) @variable.parameter

[
field_member: (IDENTIFIER)
field_access: (IDENTIFIER)
] @variable.other.member

[
function_call: (IDENTIFIER)
function: (IDENTIFIER)
] @function

exception: "!" @keyword.control.exception

field_constant: (IDENTIFIER) @constant

Expand All @@ -89,8 +85,6 @@ field_constant: (IDENTIFIER) @constant
(FormatSequence) @string.special

[
"allowzero"
"volatile"
"anytype"
"anyframe"
(BuildinTypeExpr)
Expand Down Expand Up @@ -125,44 +119,53 @@ field_constant: (IDENTIFIER) @constant
"or"
"and"
"orelse"
] @operator
] @keyword.operator

[
"struct"
"enum"
"union"
"error"
"packed"
"opaque"
] @keyword
"export"
"extern"
"linksection"
] @keyword.storage.type

[
"const"
"var"
"threadlocal"
"allowzero"
"volatile"
"align"
] @keyword.storage.modifier

[
"try"
"error"
"catch"
] @function.macro
] @keyword.control.exception

; VarDecl
[
"threadlocal"
"fn"
] @keyword.function

[
"const"
"var"
"test"
] @keyword

[
"pub"
"usingnamespace"
] @keyword
] @keyword.control.import

[
"return"
"break"
"continue"
] @keyword.control
] @keyword.control.return

; Macro
[
"defer"
"errdefer"
Expand All @@ -171,11 +174,8 @@ field_constant: (IDENTIFIER) @constant
"await"
"suspend"
"resume"
"export"
"extern"
] @function.macro

; PrecProc
[
"comptime"
"inline"
Expand All @@ -185,11 +185,6 @@ field_constant: (IDENTIFIER) @constant
"noalias"
] @keyword.directive

[
"linksection"
"align"
] @function.builtin

[
(CompareOp)
(BitwiseOp)
Expand Down Expand Up @@ -230,5 +225,4 @@ field_constant: (IDENTIFIER) @constant
(PtrIndexPayload "|")
] @punctuation.bracket

; Error
(ERROR) @keyword
(ERROR) @keyword.control.exception

0 comments on commit 0f1ded5

Please sign in to comment.