312 lines
5.0 KiB
C
312 lines
5.0 KiB
C
|
/* date = July 13th 2025 11:38 am */
|
||
|
|
||
|
#ifndef TREE_SITTER_TS_H
|
||
|
#define TREE_SITTER_TS_H
|
||
|
|
||
|
String_Const_u8 TS_TS_TAGS_QUERY = string_u8_litexpr(R"DONE(
|
||
|
|
||
|
(function_declaration
|
||
|
name: (identifier) @name) @definition.function
|
||
|
|
||
|
(function_signature
|
||
|
name: (identifier) @name) @definition.function
|
||
|
|
||
|
(variable_declarator
|
||
|
name: (identifier) @name
|
||
|
value: (arrow_function)) @definition.function
|
||
|
|
||
|
(method_signature
|
||
|
name: (property_identifier) @name) @definition.method
|
||
|
|
||
|
(abstract_method_signature
|
||
|
name: (property_identifier) @name) @definition.method
|
||
|
|
||
|
(abstract_class_declaration
|
||
|
name: (type_identifier) @name) @definition.class
|
||
|
|
||
|
(module
|
||
|
name: (identifier) @name) @definition.module
|
||
|
|
||
|
(interface_declaration
|
||
|
name: (type_identifier) @name) @definition.type
|
||
|
|
||
|
(type_alias_declaration
|
||
|
name: (type_identifier) @name) @definition.type
|
||
|
|
||
|
(type_annotation
|
||
|
(type_identifier) @name) @reference.type
|
||
|
|
||
|
(new_expression
|
||
|
constructor: (identifier) @name) @reference.class
|
||
|
|
||
|
(_ "{" @scope_begin "}" @scope_end )
|
||
|
(_ "(" @scope_begin ")" @scope_end )
|
||
|
(_ "[" @scope_begin "]" @scope_end )
|
||
|
|
||
|
)DONE");
|
||
|
|
||
|
String_Const_u8 TS_TS_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
|
||
|
;;;;;;;;;;;;;;;;; JAVASCRIPT ;;;;;;;;;;;;;;;;;
|
||
|
; Variables
|
||
|
;----------
|
||
|
|
||
|
(identifier) @variable
|
||
|
|
||
|
; Properties
|
||
|
;-----------
|
||
|
|
||
|
(property_identifier) @property
|
||
|
|
||
|
; Function and method definitions
|
||
|
;--------------------------------
|
||
|
|
||
|
(function_expression
|
||
|
name: (identifier) @function)
|
||
|
(function_declaration
|
||
|
name: (identifier) @function)
|
||
|
(method_definition
|
||
|
name: (property_identifier) @function.method)
|
||
|
|
||
|
(pair
|
||
|
key: (property_identifier) @function.method
|
||
|
value: [(function_expression) (arrow_function)])
|
||
|
|
||
|
(assignment_expression
|
||
|
left: (member_expression
|
||
|
property: (property_identifier) @function.method)
|
||
|
right: [(function_expression) (arrow_function)])
|
||
|
|
||
|
(variable_declarator
|
||
|
name: (identifier) @function
|
||
|
value: [(function_expression) (arrow_function)])
|
||
|
|
||
|
(assignment_expression
|
||
|
left: (identifier) @function
|
||
|
right: [(function_expression) (arrow_function)])
|
||
|
|
||
|
; Function and method calls
|
||
|
;--------------------------
|
||
|
|
||
|
(call_expression
|
||
|
function: (identifier) @function)
|
||
|
|
||
|
(call_expression
|
||
|
function: (member_expression
|
||
|
property: (property_identifier) @function.method))
|
||
|
|
||
|
; Special identifiers
|
||
|
;--------------------
|
||
|
|
||
|
((identifier) @constructor
|
||
|
(#match? @constructor "^[A-Z]"))
|
||
|
|
||
|
([
|
||
|
(identifier)
|
||
|
(shorthand_property_identifier)
|
||
|
(shorthand_property_identifier_pattern)
|
||
|
] @constant
|
||
|
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
|
||
|
|
||
|
((identifier) @variable.builtin
|
||
|
(#match? @variable.builtin "^(arguments|module|console|window|document)$")
|
||
|
(#is-not? local))
|
||
|
|
||
|
((identifier) @function.builtin
|
||
|
(#eq? @function.builtin "require")
|
||
|
(#is-not? local))
|
||
|
|
||
|
; Literals
|
||
|
;---------
|
||
|
|
||
|
(this) @variable.builtin
|
||
|
(super) @variable.builtin
|
||
|
|
||
|
[
|
||
|
(true)
|
||
|
(false)
|
||
|
(null)
|
||
|
(undefined)
|
||
|
] @constant.builtin
|
||
|
|
||
|
(comment) @comment
|
||
|
|
||
|
[
|
||
|
(string)
|
||
|
(template_string)
|
||
|
] @string
|
||
|
|
||
|
(regex) @string.special
|
||
|
(number) @number
|
||
|
|
||
|
; Tokens
|
||
|
;-------
|
||
|
|
||
|
[
|
||
|
";"
|
||
|
(optional_chain)
|
||
|
"."
|
||
|
","
|
||
|
] @punctuation.delimiter
|
||
|
|
||
|
[
|
||
|
"-"
|
||
|
"--"
|
||
|
"-="
|
||
|
"+"
|
||
|
"++"
|
||
|
"+="
|
||
|
"*"
|
||
|
"*="
|
||
|
"**"
|
||
|
"**="
|
||
|
"/"
|
||
|
"/="
|
||
|
"%"
|
||
|
"%="
|
||
|
"<"
|
||
|
"<="
|
||
|
"<<"
|
||
|
"<<="
|
||
|
"="
|
||
|
"=="
|
||
|
"==="
|
||
|
"!"
|
||
|
"!="
|
||
|
"!=="
|
||
|
"=>"
|
||
|
">"
|
||
|
">="
|
||
|
">>"
|
||
|
">>="
|
||
|
">>>"
|
||
|
">>>="
|
||
|
"~"
|
||
|
"^"
|
||
|
"&"
|
||
|
"|"
|
||
|
"^="
|
||
|
"&="
|
||
|
"|="
|
||
|
"&&"
|
||
|
"||"
|
||
|
"??"
|
||
|
"&&="
|
||
|
"||="
|
||
|
"??="
|
||
|
] @operator
|
||
|
|
||
|
[
|
||
|
"("
|
||
|
")"
|
||
|
"["
|
||
|
"]"
|
||
|
"{"
|
||
|
"}"
|
||
|
] @punctuation.bracket
|
||
|
|
||
|
(template_substitution
|
||
|
"${" @punctuation.special
|
||
|
"}" @punctuation.special) @embedded
|
||
|
|
||
|
[
|
||
|
"as"
|
||
|
"async"
|
||
|
"await"
|
||
|
"break"
|
||
|
"case"
|
||
|
"catch"
|
||
|
"class"
|
||
|
"const"
|
||
|
"continue"
|
||
|
"debugger"
|
||
|
"default"
|
||
|
"delete"
|
||
|
"do"
|
||
|
"else"
|
||
|
"export"
|
||
|
"extends"
|
||
|
"finally"
|
||
|
"for"
|
||
|
"from"
|
||
|
"function"
|
||
|
"get"
|
||
|
"if"
|
||
|
"import"
|
||
|
"in"
|
||
|
"instanceof"
|
||
|
"let"
|
||
|
"new"
|
||
|
"of"
|
||
|
"return"
|
||
|
"set"
|
||
|
"static"
|
||
|
"switch"
|
||
|
"target"
|
||
|
"throw"
|
||
|
"try"
|
||
|
"typeof"
|
||
|
"var"
|
||
|
"void"
|
||
|
"while"
|
||
|
"with"
|
||
|
"yield"
|
||
|
] @keyword
|
||
|
|
||
|
;;;;;;;;;;;;;;;;; TYPESCRIPT ;;;;;;;;;;;;;;;;;
|
||
|
|
||
|
; Types
|
||
|
|
||
|
(type_identifier) @type
|
||
|
(predefined_type) @type.builtin
|
||
|
|
||
|
((identifier) @type
|
||
|
(#match? @type "^[A-Z]"))
|
||
|
|
||
|
(type_arguments
|
||
|
"<" @punctuation.bracket
|
||
|
">" @punctuation.bracket)
|
||
|
|
||
|
; Variables
|
||
|
|
||
|
(required_parameter (identifier) @variable.parameter)
|
||
|
(optional_parameter (identifier) @variable.parameter)
|
||
|
|
||
|
; Keywords
|
||
|
|
||
|
[ "abstract"
|
||
|
"declare"
|
||
|
"enum"
|
||
|
"export"
|
||
|
"implements"
|
||
|
"interface"
|
||
|
"keyof"
|
||
|
"namespace"
|
||
|
"private"
|
||
|
"protected"
|
||
|
"public"
|
||
|
"type"
|
||
|
"readonly"
|
||
|
"override"
|
||
|
"satisfies"
|
||
|
] @keyword
|
||
|
)DONE");
|
||
|
|
||
|
extern "C" {
|
||
|
TSLanguage* tree_sitter_typescript();
|
||
|
}
|
||
|
|
||
|
void
|
||
|
tree_sitter_register_ts (Application_Links* app)
|
||
|
{
|
||
|
TSLanguage* language = tree_sitter_typescript();
|
||
|
Tree_Sitter_Language_Queries queries = {};
|
||
|
queries.ptr[Tree_Sitter_Language_Query_Highlights] = tree_sitter_query_new(app, language, TS_TS_HIGHLIGHT_QUERY);
|
||
|
queries.ptr[Tree_Sitter_Language_Query_Tags] = tree_sitter_query_new(app, language, TS_TS_TAGS_QUERY);
|
||
|
Tree_Sitter_Language_Flags flags = (
|
||
|
Tree_Sitter_Language_Can_Receive_Virtual_Indent
|
||
|
);
|
||
|
tree_sitter_register_language(SCu8("ts"), language, queries, flags);
|
||
|
}
|
||
|
|
||
|
#endif //TREE_SITTER_TS_H
|