Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul Hare syntax highlight queries #11208

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 127 additions & 80 deletions runtime/queries/hare/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(type) @type
(type "const" @type)
(nullable_type) @type

[
"else"
"if"
"case"
"match"
"switch"
] @keyword.control.conditional
Expand All @@ -13,83 +12,44 @@
"use"
] @keyword.control.import

[
"continue"
"for"
"break"
] @keyword.control.repeat

"return" @keyword.control.return

[
"abort"
"assert"
] @keyword.control.exception

"fn" @keyword.function

[
"alloc"
"append"
"as"
"bool"
"case"
"const"
"nullable"
] @keyword.storage.modifier

[
"def"
"defer"
"delete"
"enum"
"free"
"is"
"len"
"let"
"match"
"nullable"
"offset"
"static"
"struct"
"type"
"union"
"yield"
"_"
] @keyword

"static" @keyword.storage.modifier

[
"."
"!"
"~"
"?"
"*"
"/"
"%"
"+"
"-"
"<<"
">>"
"::"
"<"
"<="
">"
">="
"=="
"!="
"&"
"|"
"^"
"&&"
"||"
"="
"+="
"-="
"*="
"/="
"%="
"&="
"|="
"<<="
">>="
"^="
"%="
"&&="
"&="
"*="
"+="
"-="
"."
".."
"/="
"::"
"<<="
"="
"=>"
">>="
"?"
"^="
"^^="
"|="
"||="
] @operator

[
Expand All @@ -107,36 +67,123 @@
";"
] @punctuation.delimiter

"..." @special
"..." @special

(comment) @comment

[
"false"
"null"
"true"
] @constant.builtin
(literal "void") @constant.builtin
((literal) @constant.builtin
(#match? @constant.builtin "^(null|void)$"))

((literal) @constant.builtin.boolean
(#match? @constant.builtin.boolean "^(false|true)$"))

(string_literal) @string
(escape_sequence) @constant.character.escape
(rune_literal) @string
(integer_literal) @constant.numeric.integer
(floating_literal) @constant.numeric.float
(rune_literal) @constant.character
(escape_sequence) @constant.character.escape
(string_literal) @string

(call_expression
(postfix_expression) @function)
(postfix_expression
(nested_expression
(identifier) @function)))

(allocation_expression
_ @function.builtin
(#match? @function.builtin "^(alloc|free)$"))

(align_expression "align" @function.builtin)
(size_expression "size" @function.builtin)
(length_expression "len" @function.builtin)
(offset_expression "offset" @function.builtin)

(append_expression
_ @function.builtin
(#match? @function.builtin "^(append|delete|insert)$"))

(assertion_expression
_ @keyword.control.exception
(#match? @keyword.control.exception "^(abort|assert)$"))

(unary_expression
_ @operator
(#match? @operator "^[+-~!*&]$"))

(multiplicative_expression
_ @operator
(#match? @operator "^[*/%]$"))

(additive_expression
_ @operator
(#match? @operator "^[+-]$"))

(shift_expression
_ @operator
(#match? @operator "^(<<|>>)$"))

(and_expression "&" @operator)
(exclusive_or_expression "^" @operator)
(inclusive_or_expression "|" @operator)

(comparison_expression
_ @operator
(#match? @operator "^(<|>|<=|>=)$"))

(equality_expression
_ @operator
(#match? @operator "^(==|!=)$"))

(logical_and_expression "&&" @operator)
(logical_xor_expression "^^" @operator)
(logical_or_expression "||" @operator)

(if_expression
_ @keyword.control.conditional
(#match? @keyword.control.conditional "^(else|if)$"))

(for_loop "for" @keyword.control.repeat)

(iterable_binding
_ @keyword.storage.type
(#match? @keyword.storage.type "^(const|let)$"))

(switch_expression "switch" @keyword.control.conditional)
(switch_case "case" @keyword.control.conditional)
(match_expression "match" @keyword.control.conditional)
(match_case "case" @keyword.control.conditional)
(match_case "let" @keyword.storage.type)

(control_expression
_ @keyword.control.repeat
(#match? @keyword.control.repeat "^(break|continue)$"))

(control_expression
_ @keyword.control.return
(#match? @keyword.control.repeat "^(return|yield)$"))

(cast_expression
_ @keyword.operator
(#match? @keyword.operator "^(as|is)$"))

(variadic_expression
_ @function.builtin
(#match? @function.builtin "$va(arg|end|start)$"))

(function_declaration
name: (identifier) @function)

(parameter (name) @variable.parameter)
(parameter
(name) @variable.parameter)

(field_access_expression
selector: (name) @variable.other.member)

(identifier) @variable

(struct_union_field
(name) @variable)

(decl_attr) @special
(fndec_attrs) @special

(identifier) @variable
(struct_union_field (name)) @variable
(ERROR) @error
Loading