344 lines
5.8 KiB
C
344 lines
5.8 KiB
C
/* date = July 11th 2025 6:03 pm */
|
|
|
|
#ifndef TREE_SITTER_JAI_H
|
|
#define TREE_SITTER_JAI_H
|
|
|
|
String_Const_u8 TS_JAI_FUNCTION_QUERY = string_u8_litexpr(R"DONE(
|
|
|
|
(procedure_declaration
|
|
name: (identifier) @print1
|
|
(procedure
|
|
(named_parameters) @print2
|
|
(procedure_returns) @print
|
|
)
|
|
)
|
|
|
|
)DONE");
|
|
|
|
String_Const_u8 TS_JAI_TYPE_QUERY = string_u8_litexpr(R"DONE(
|
|
|
|
(struct_declaration
|
|
name: (identifier) @prefixStruct
|
|
)
|
|
|
|
(enum_declaration
|
|
name: (identifier) @prefixEnum
|
|
)
|
|
|
|
)DONE");
|
|
|
|
String_Const_u8 TS_JAI_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
|
|
|
|
; keywords
|
|
[
|
|
"if"
|
|
"else"
|
|
"break"
|
|
"continue"
|
|
"return"
|
|
"struct"
|
|
"enum"
|
|
"for"
|
|
"defer"
|
|
"cast"
|
|
"xx"
|
|
"ifx"
|
|
"null"
|
|
] @defcolor_keyword
|
|
|
|
; # preceeded
|
|
[
|
|
(compiler_directive)
|
|
(import)
|
|
(char_string)
|
|
] @defcolor_macro
|
|
|
|
(import (identifier) @defcolor_type)
|
|
|
|
; Identifiers
|
|
(struct_declaration
|
|
name: (identifier) @defcolor_type
|
|
)
|
|
|
|
(struct_literal
|
|
type: (identifier) @defcolor_type
|
|
)
|
|
|
|
(enum_declaration
|
|
name: (identifier) @defcolor_type
|
|
)
|
|
|
|
(enum_declaration "{" (identifier) @defcolor_type)
|
|
|
|
(variable_declaration
|
|
type: (types) @defcolor_type
|
|
)
|
|
|
|
(procedure_declaration
|
|
name: (identifier) @defcolor_function
|
|
)
|
|
|
|
(call_expression
|
|
function: (identifier) @defcolor_function
|
|
)
|
|
|
|
(procedure
|
|
result: (procedure_returns) @defcolor_type
|
|
)
|
|
|
|
; Constants & Literals
|
|
[
|
|
(string)
|
|
(string_directive)
|
|
] @defcolor_str_constant
|
|
(escape_sequence) @defcolor_special_character
|
|
(integer) @defcolor_int_constant
|
|
(float) @defcolor_float_constant
|
|
(boolean) @defcolor_bool_constant
|
|
|
|
(array_literal
|
|
type: (identifier) @defcolor_type
|
|
)
|
|
|
|
; Comments
|
|
(note) @defcolor_comment
|
|
(block_comment) @defcolor_comment
|
|
(block_comment_text) @defcolor_comment
|
|
|
|
)DONE");
|
|
|
|
// NOTE(PS): source: https://github.com/St0wy/tree-sitter-jai/blob/main/queries/highlights.scm
|
|
String_Const_u8 TS_JAI_HIGHLIGHT_QUERY_ = string_u8_litexpr(R"DONE(
|
|
|
|
[
|
|
(compiler_directive)
|
|
(import)
|
|
] @defcolor_macro
|
|
|
|
; Keywords
|
|
; TODO : complete this list
|
|
[
|
|
"struct"
|
|
"enum"
|
|
"defer"
|
|
"cast"
|
|
"xx"
|
|
"return"
|
|
] @defcolor_keyword
|
|
|
|
; Conditionals
|
|
[
|
|
"if"
|
|
"else"
|
|
"case"
|
|
"break"
|
|
] @defcolor_keyword
|
|
|
|
((if_expression
|
|
[
|
|
"then"
|
|
"ifx"
|
|
"else"
|
|
] @defcolor_keyword)
|
|
(#set! "priority" 105))
|
|
|
|
; Repeats
|
|
|
|
[
|
|
"for"
|
|
"while"
|
|
"continue"
|
|
] @defcolor_keyword
|
|
|
|
; Variables
|
|
|
|
(identifier) @defcolor_text_default
|
|
|
|
; Namespaces
|
|
|
|
(import (identifier) @defcolor_text_default)
|
|
|
|
; Parameters
|
|
|
|
(parameter (identifier) @defcolor_text_default ":" "="? (identifier)? @defcolor_str_constant)
|
|
|
|
(default_parameter (identifier) @defcolor_text_default ":=")
|
|
|
|
(call_expression argument: (identifier) @defcolor_text_default "=")
|
|
|
|
; Functions
|
|
|
|
(procedure_declaration (identifier) @defcolor_function)
|
|
|
|
(procedure_declaration (identifier) @defcolor_function (procedure (block)))
|
|
|
|
(call_expression function: (identifier) @defcolor_function)
|
|
|
|
; Types
|
|
|
|
(type (identifier) @defcolor_type)
|
|
|
|
((type (identifier) @defcolor_type)
|
|
(#any-of? @type.builtin
|
|
"bool"
|
|
"int" "s8" "s16" "s32" "s64"
|
|
"u8" "u16" "u32" "u64"
|
|
"string"))
|
|
|
|
|
|
(struct_declaration (identifier) @defcolor_type "::")
|
|
|
|
(enum_declaration (identifier) @defcolor_type "::")
|
|
|
|
;(union_declaration (identifier) @defcolor_type "::")
|
|
|
|
(const_declaration (identifier) @defcolor_type "::" [(array_type) (pointer_type)])
|
|
|
|
(struct . (identifier) @defcolor_type)
|
|
|
|
;(field_type . (identifier) @namespace "." (identifier) @defcolor_type)
|
|
|
|
;(bit_set_type (identifier) @defcolor_type ";")
|
|
|
|
;(procedure_type (parameters (parameter (identifier) @defcolor_type)))
|
|
|
|
;(polymorphic_parameters (identifier) @defcolor_type)
|
|
|
|
((identifier) @defcolor_type
|
|
(#lua-match? @defcolor_type "^[A-Z][a-zA-Z0-9]*$")
|
|
(#not-has-parent? @defcolor_type parameter procedure_declaration call_expression))
|
|
|
|
; Fields
|
|
|
|
(member_expression "." (identifier) @defcolor_text_default)
|
|
|
|
;(struct_type "{" (identifier) @defcolor_text_default)
|
|
|
|
(struct_field (identifier) @defcolor_text_default "="?)
|
|
|
|
(field (identifier) @defcolor_text_default)
|
|
|
|
; Constants
|
|
|
|
((identifier) @defcolor_text_default
|
|
(#lua-match? @defcolor_str_constnat "^_*[A-Z][A-Z0-9_]*$")
|
|
(#not-has-parent? @text_default type parameter))
|
|
|
|
(member_expression . "." (identifier) @defcolor_text_default)
|
|
|
|
(enum_declaration "{" (identifier) @defcolor_text_default)
|
|
|
|
; Literals
|
|
|
|
(number) @defcolor_int_constant
|
|
|
|
(float) @defcolor_float_constant
|
|
|
|
(string) @defcolor_str_constnat
|
|
|
|
;(character) @defcolor_str_constnat
|
|
|
|
(escape_sequence) @defcolor_str_constant
|
|
|
|
(boolean) @defcolor_bool_constant
|
|
|
|
[
|
|
(uninitialized)
|
|
(null)
|
|
] @defcolor_text_default
|
|
|
|
((identifier) @defcolor_text_default
|
|
(#any-of? @defcolor_text_default "context"))
|
|
|
|
; Operators
|
|
|
|
[
|
|
":="
|
|
"="
|
|
"+"
|
|
"-"
|
|
"*"
|
|
"/"
|
|
"%"
|
|
"%%"
|
|
">"
|
|
">="
|
|
"<"
|
|
"<="
|
|
"=="
|
|
"!="
|
|
"~="
|
|
"|"
|
|
"~"
|
|
"&"
|
|
"&~"
|
|
"<<"
|
|
">>"
|
|
"||"
|
|
"&&"
|
|
"!"
|
|
".."
|
|
"+="
|
|
"-="
|
|
"*="
|
|
"/="
|
|
"%="
|
|
"&="
|
|
"|="
|
|
"^="
|
|
"<<="
|
|
">>="
|
|
"||="
|
|
"&&="
|
|
"&~="
|
|
;"..="
|
|
;"..<"
|
|
;"?"
|
|
] @defcolor_operator
|
|
|
|
; Punctuation
|
|
|
|
[ "{" "}" ] @defcolor_text_default
|
|
|
|
[ "(" ")" ] @defcolor_text_default
|
|
|
|
[ "[" "]" ] @defcolor_text_default
|
|
|
|
[
|
|
"::"
|
|
"->"
|
|
"."
|
|
","
|
|
":"
|
|
";"
|
|
] @defcolor_text_default
|
|
|
|
; Comments
|
|
|
|
[
|
|
(comment)
|
|
(block_comment)
|
|
] @defcolor_comment
|
|
|
|
; Errors
|
|
|
|
(ERROR) @defcolor_comment_pop
|
|
)DONE");
|
|
|
|
extern "C" {
|
|
TSLanguage *tree_sitter_jai();
|
|
}
|
|
|
|
void
|
|
tree_sitter_register_jai (Application_Links* app)
|
|
{
|
|
TSLanguage* language = tree_sitter_jai();
|
|
Tree_Sitter_Language_Queries queries = {};
|
|
queries.ptr[Tree_Sitter_Language_Query_Highlights] = tree_sitter_query_new(app, language, TS_JAI_HIGHLIGHT_QUERY);
|
|
queries.ptr[Tree_Sitter_Language_Query_Functions] = tree_sitter_query_new(app, language, TS_JAI_FUNCTION_QUERY);
|
|
queries.ptr[Tree_Sitter_Language_Query_Types] = tree_sitter_query_new(app, language, TS_JAI_TYPE_QUERY);
|
|
tree_sitter_register_language(SCu8("jai"), language, queries);
|
|
}
|
|
|
|
#endif //TREE_SITTER_JAI_H
|