This commit is contained in:
Le_Foucheur committed 2024-09-15 22:10:50 +02:00
1 parent bd49911eca
commit e3de01bde8
3742 files changed
+64316

No files matched your search

@@ -0,0 +1,38 @@
; Opening elements
; ----------------
(jsx_opening_element (identifier) @tag)
; Closing elements
; ----------------
(jsx_closing_element (identifier) @tag)
; Self-closing elements
; ---------------------
(jsx_self_closing_element (identifier) @tag)
; Attributes
; ----------
(jsx_attribute (property_identifier) @attribute.jsx)
; Punctuation
; -----------
; Handle attribute delimiter (<Component color="red"/>)
(jsx_attribute "=" @operator)
; <Component>
(jsx_opening_element ["<" ">"] @punctuation.bracket)
; </Component>
(jsx_closing_element ["</" ">"] @punctuation.bracket)
; <Component />
(jsx_self_closing_element ["<" "/>"] @punctuation.bracket)
; Brackets inside jsx ({children})
(jsx_expression ["{" "}"] @punctuation.embedded.jsx)
@@ -0,0 +1,148 @@
"sizeof" @keyword
[
"enum"
"struct"
"typedef"
"union"
] @keyword.storage.type
[
"extern"
"register"
(type_qualifier)
(storage_class_specifier)
] @keyword.storage.modifier
[
"goto"
"break"
"continue"
] @keyword.control
[
"do"
"for"
"while"
] @keyword.control.repeat
[
"if"
"else"
"switch"
"case"
"default"
] @keyword.control.conditional
"return" @keyword.control.return
[
"defined"
"#define"
"#elif"
"#else"
"#endif"
"#if"
"#ifdef"
"#ifndef"
"#include"
] @keyword
(preproc_directive) @keyword.directive
[
"+"
"-"
"*"
"/"
"++"
"--"
"%"
"=="
"!="
">"
"<"
">="
"<="
"&&"
"||"
"!"
"&"
"|"
"^"
"~"
"<<"
">>"
"="
"+="
"-="
"*="
"/="
"%="
"<<="
">>="
"&="
"^="
"|="
"?"
] @operator
(conditional_expression ":" @operator)
"..." @punctuation
["," "." ":" ";" "->" "::"] @punctuation.delimiter
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[(true) (false)] @constant.builtin.boolean
(enumerator name: (identifier) @type.enum.variant)
(string_literal) @string
(system_lib_string) @string
(null) @constant
(number_literal) @constant.numeric
(char_literal) @constant.character
(escape_sequence) @constant.character.escape
(call_expression
function: (identifier) @function)
(call_expression
function: (field_expression
field: (field_identifier) @function))
(call_expression (argument_list (identifier) @variable))
(function_declarator
declarator: [(identifier) (field_identifier)] @function)
(parameter_declaration
declarator: (identifier) @variable.parameter)
(parameter_declaration
(pointer_declarator
declarator: (identifier) @variable.parameter))
(preproc_function_def
name: (identifier) @function.special)
(attribute
name: (identifier) @attribute)
(field_identifier) @variable.other.member
(statement_identifier) @label
(type_identifier) @type
(primitive_type) @type.builtin
(sized_type_specifier) @type.builtin
((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
(identifier) @variable
(comment) @comment
; -----
; custom string
; -----
(string_literal [
"\""
"'"
] @string.delimiter)
@@ -0,0 +1,159 @@
; Modules
;--------
[(module_name) (module_type_name)] @namespace
; Types
;------
(
(type_constructor) @type.builtin
(#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$")
)
[(class_name) (class_type_name) (type_constructor)] @type
[(constructor_name) (tag)] @constructor
; Functions
;----------
(let_binding
pattern: (value_name) @function
(parameter))
(let_binding
pattern: (value_name) @function
body: [(fun_expression) (function_expression)])
(value_specification (value_name) @function)
(external (value_name) @function)
(method_name) @function.method
; Application
;------------
(
(value_name) @function.builtin
(#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$")
)
(infix_expression
left: (value_path (value_name) @function)
operator: (concat_operator) @operator
(#eq? @operator "@@"))
(infix_expression
operator: (rel_operator) @operator
right: (value_path (value_name) @function)
(#eq? @operator "|>"))
(application_expression
function: (value_path (value_name) @function))
; Variables
;----------
[(value_name) (type_variable)] @variable
(value_pattern) @variable.parameter
; Properties
;-----------
[(label_name) (field_name) (instance_variable_name)] @variable.other.member
; Constants
;----------
(boolean) @constant.builtin.boolean
[(number) (signed_number)] @constant.numeric
[(string) (character)] @string
(quoted_string "{" @string "}" @string) @string
(escape_sequence) @constant.character.escape
(conversion_specification) @string.special
; Operators
;----------
(match_expression (match_operator) @keyword)
(value_definition [(let_operator) (let_and_operator)] @keyword)
[
(prefix_operator)
(sign_operator)
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
(hash_operator)
(indexing_operator)
(let_operator)
(let_and_operator)
(match_operator)
] @operator
["*" "#" "::" "<-"] @operator
; Keywords
;---------
[
"and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else"
"end" "exception" "external" "for" "fun" "function" "functor" "if" "in"
"include" "inherit" "initializer" "lazy" "let" "match" "method" "module"
"mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct"
"then" "to" "try" "type" "val" "virtual" "when" "while" "with"
] @keyword
; Punctuation
;------------
(attribute ["[@" "]"] @punctuation.special)
(item_attribute ["[@@" "]"] @punctuation.special)
(floating_attribute ["[@@@" "]"] @punctuation.special)
(extension ["[%" "]"] @punctuation.special)
(item_extension ["[%%" "]"] @punctuation.special)
(quoted_extension ["{%" "}"] @punctuation.special)
(quoted_item_extension ["{%%" "}"] @punctuation.special)
"%" @punctuation.special
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
(object_type ["<" ">"] @punctuation.bracket)
[
"," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&"
"->" ";;" ":>" "+=" ":=" ".."
] @punctuation.delimiter
; Attributes
;-----------
(attribute_id) @tag
; Comments
;---------
[(comment) (line_number_directive) (directive) (shebang)] @comment
; -----
; custom string
; -----
(string [
"\""
"'"
] @string.delimiter)
@@ -0,0 +1,429 @@
; -------
; Tree-Sitter doesn't allow overrides in regards to captures,
; though it is possible to affect the child node of a captured
; node. Thus, the approach here is to flip the order so that
; overrides are unnecessary.
; -------
; -------
; Types
; -------
(type_parameters
(type_identifier) @type.parameter)
(constrained_type_parameter
left: (type_identifier) @type.parameter)
(optional_type_parameter
name: (type_identifier) @type.parameter)
; ---
; Primitives
; ---
(escape_sequence) @constant.character.escape
(primitive_type) @type.builtin
(boolean_literal) @constant.builtin.boolean
(integer_literal) @constant.numeric.integer
(float_literal) @constant.numeric.float
(char_literal) @constant.character
[
(string_literal)
(raw_string_literal)
(string_content)
] @string
[
(line_comment)
(block_comment)
] @comment
; ---
; Extraneous
; ---
(self) @variable.builtin.self
(enum_variant (identifier) @type.enum.variant)
(field_initializer
(field_identifier) @variable.other.member)
(shorthand_field_initializer
(identifier) @variable.other.member)
(shorthand_field_identifier) @variable.other.member
(lifetime
"'" @string.delimiter
(identifier) @type)
(label
"'" @label
(identifier) @label)
; ---
; Punctuation
; ---
[
";"
","
] @punctuation.delimiter
[
"::"
"."
":"
] @punctuation.delimiter.rust
[
"("
")"
"["
"]"
"{"
"}"
"#"
] @punctuation.bracket
(type_arguments
[
"<"
">"
] @punctuation.bracket)
(type_parameters
[
"<"
">"
] @punctuation.bracket)
(closure_parameters
"|" @punctuation.bracket)
; ---
; Variables
; ---
(let_declaration
pattern: [
((identifier) @variable)
((tuple_pattern
(identifier) @variable))
])
; It needs to be anonymous to not conflict with `call_expression` further below.
(_
value: (field_expression
value: (identifier)? @variable
field: (field_identifier) @variable.other.member))
(parameter
pattern: (identifier) @variable.parameter)
(closure_parameters
(identifier) @variable.parameter)
; -------
; Keywords
; -------
(for_expression
"for" @keyword.control.repeat)
((identifier) @keyword.control
(#match? @keyword.control "^yield$"))
"in" @keyword.control
[
"match"
"if"
"else"
"try"
] @keyword.control.conditional
[
"while"
"loop"
] @keyword.control.repeat
[
"break"
"continue"
"return"
"await"
] @keyword.control.return
"use" @keyword.control.import
(mod_item "mod" @keyword.control.import !body)
(use_as_clause "as" @keyword.control.import)
(type_cast_expression "as" @keyword.operator)
[
(crate)
(super)
"as"
"pub"
"mod"
"extern"
"impl"
"where"
"trait"
"for"
"default"
"async"
] @keyword
[
"struct"
"enum"
"union"
"type"
] @keyword.storage.type
"let" @keyword.storage
"fn" @keyword.function
"unsafe" @keyword.special
"macro_rules!" @function.macro
(mutable_specifier) @keyword.storage.modifier.mut
(reference_type "&" @keyword.storage.modifier.ref)
(self_parameter "&" @keyword.storage.modifier.ref)
[
"static"
"const"
"ref"
"move"
"dyn"
] @keyword.storage.modifier
; TODO: variable.mut to highlight mutable identifiers via locals.scm
; -------
; Constructors
; -------
; TODO: this is largely guesswork, remove it once we get actual info from locals.scm or r-a
(struct_expression
name: (type_identifier) @constructor)
(tuple_struct_pattern
type: [
(identifier) @constructor
(scoped_identifier
name: (identifier) @constructor)
])
(struct_pattern
type: [
((type_identifier) @constructor)
(scoped_type_identifier
name: (type_identifier) @constructor)
])
(match_pattern
((identifier) @constructor) (#match? @constructor "^[A-Z]"))
(or_pattern
((identifier) @constructor)
((identifier) @constructor)
(#match? @constructor "^[A-Z]"))
; -------
; Guess Other Types
; -------
((identifier) @constant
(#match? @constant "^[A-Z][A-Z\\d_]*$"))
; ---
; PascalCase identifiers in call_expressions (e.g. `Ok()`)
; are assumed to be enum constructors.
; ---
(call_expression
function: [
((identifier) @constructor
(#match? @constructor "^[A-Z]"))
(scoped_identifier
name: ((identifier) @constructor
(#match? @constructor "^[A-Z]")))
])
; ---
; PascalCase identifiers under a path which is also PascalCase
; are assumed to be constructors if they have methods or fields.
; ---
(field_expression
value: (scoped_identifier
path: [
(identifier) @type
(scoped_identifier
name: (identifier) @type)
]
name: (identifier) @constructor
(#match? @type "^[A-Z]")
(#match? @constructor "^[A-Z]")))
; ---
; Other PascalCase identifiers are assumed to be structs.
; ---
((identifier) @type
(#match? @type "^[A-Z]"))
; -------
; Functions
; -------
(call_expression
function: [
((identifier) @function)
(scoped_identifier
name: (identifier) @function)
(field_expression
field: (field_identifier) @function)
])
(generic_function
function: [
((identifier) @function)
(scoped_identifier
name: (identifier) @function)
(field_expression
field: (field_identifier) @function.method)
])
(function_item
name: (identifier) @function)
(function_signature_item
name: (identifier) @function)
; ---
; Macros
; ---
(attribute
(identifier) @special
arguments: (token_tree (identifier) @type)
(#eq? @special "derive")
)
(attribute
(identifier) @function.macro)
(attribute
[
(identifier) @function.macro
(scoped_identifier
name: (identifier) @function.macro)
]
(token_tree (identifier) @function.macro)?)
(inner_attribute_item) @attribute
(macro_definition
name: (identifier) @function.macro)
(macro_invocation
macro: [
((identifier) @function.macro)
(scoped_identifier
name: (identifier) @function.macro)
]
"!" @function.macro)
(metavariable) @variable.parameter
(fragment_specifier) @type
; -------
; Operators
; -------
[
"*"
"'"
"->"
"=>"
"<="
"="
"=="
"!"
"!="
"%"
"%="
"&"
"&="
"&&"
"|"
"|="
"||"
"^"
"^="
"*"
"*="
"-"
"-="
"+"
"+="
"/"
"/="
">"
"<"
">="
">>"
"<<"
">>="
"<<="
"@"
".."
"..="
"'"
] @operator
; -------
; Paths
; -------
(use_declaration
argument: (identifier) @namespace)
(use_wildcard
(identifier) @namespace)
(extern_crate_declaration
name: (identifier) @namespace
alias: (identifier)? @namespace)
(mod_item
name: (identifier) @namespace)
(scoped_use_list
path: (identifier)? @namespace)
(use_list
(identifier) @namespace)
(use_as_clause
path: (identifier)? @namespace
alias: (identifier) @namespace)
; ---
; Remaining Paths
; ---
(scoped_identifier
path: (identifier)? @namespace
name: (identifier) @namespace)
(scoped_type_identifier
path: (identifier) @namespace)
; -------
; Remaining Identifiers
; -------
"?" @special
(type_identifier) @type
(identifier) @variable
(field_identifier) @variable.other.member
; -----
; custom string
; -----
(string_literal [
"\""
"'"
] @string.delimiter)
(lifetime
"'" @string.delimiter)
(lifetime
(identifier) @type)
@@ -0,0 +1,127 @@
[
"@at-root"
"@debug"
"@error"
"@extend"
"@forward"
"@mixin"
"@use"
"@warn"
"@media"
"="
] @keyword
"@function" @keyword.function
"@return" @keyword.return
"@include" @keyword.import
[
"@while"
"@each"
"@for"
"from"
"through"
"in"
] @keyword.repeat
(js_comment) @comment @spell
(comment) @comment
(function_name) @function
[
">="
"<="
] @operator
(mixin_statement
name: (identifier) @function)
(mixin_statement
(parameters
(parameter) @variable.parameter))
(function_statement
name: (identifier) @function)
(function_statement
(parameters
(parameter) @variable.parameter))
((plain_value) @variable.scss
(#match? @variable.scss "^--.+"))
((property_name) @variable.scss
(#match? @variable.scss "^--.+"))
((property_name) @variable.scss
(#match? @variable.scss "^$.+"))
(plain_value) @type
(string_value) @string
(selectors
(pseudo_element_selector
(tag_name) @attribute.jsx))
(selectors
(pseudo_class_selector
(class_name) @attribute.jsx))
(nesting_selector) @keyword
(tag_name) @tag
(keyword_query) @function
(identifier) @variable.scss.ident
(variable) @variable.scss
(argument) @variable.parameter
(arguments
(variable) @variable.parameter)
(integer_value) @constant.numeric.integer
(integer_value
(unit) @keyword)
(class_name) @classname
(id_name) @idname
(attribute_name) @attribute.jsx
(class_selector
"." @punctuation.italic)
(id_selector
"#" @punctuation.italic)
(pseudo_class_selector
":" @punctuation.italic)
"::" @punctuation.italic
[
"["
"]"
] @punctuation.bracket
[
"{"
"}"
":"
";"
"#{"
","
"("
")"
] @punctuation
(include_statement
(identifier) @function)
@@ -0,0 +1,2 @@
; ([(comment) (single_line_comment)] @injection.content
; (#set! injection.language "comment"))