Pull language registration into individual per-language files
This commit is contained in:
parent
60e850b2ff
commit
c5a462993d
|
@ -3,390 +3,9 @@
|
|||
// TEMP until I implement more generic language stuff
|
||||
/////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// C
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// C++
|
||||
|
||||
TSQuery* tree_sitter_cpp_index_query;
|
||||
String_Const_u8 TS_CPP_INDEX_QUERY = string_u8_litexpr("(_ \"{\" @Start \"}\" @End ) @ScopeNest\n");
|
||||
|
||||
String_Const_u8 TS_CPP_FUNCTION_QUERY = string_u8_litexpr(R"DONE(
|
||||
(function_declarator) @function_identifier
|
||||
)DONE");
|
||||
|
||||
String_Const_u8 TS_CPP_TYPE_QUERY = string_u8_litexpr(R"DONE(
|
||||
(struct_specifier
|
||||
name: (type_identifier) @prefixStruct
|
||||
)
|
||||
(enum_specifier
|
||||
name: (type_identifier) @prefixEnum
|
||||
)
|
||||
(class_specifier
|
||||
name: (type_identifier) @prefixClass
|
||||
)
|
||||
)DONE");
|
||||
|
||||
String_Const_u8 TS_CPP_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
|
||||
(call_expression function: [
|
||||
(identifier) @defcolor_function
|
||||
(field_expression field: (field_identifier) @defcolor_function)])
|
||||
|
||||
(function_declarator
|
||||
declarator: [(identifier) (field_identifier)] @defcolor_function)
|
||||
|
||||
(preproc_def
|
||||
name: (identifier) @defcolor_macro)
|
||||
|
||||
(preproc_function_def
|
||||
name: (identifier) @defcolor_macro)
|
||||
|
||||
(type_identifier) @defcolor_type
|
||||
|
||||
(call_expression
|
||||
function: (parenthesized_expression
|
||||
(identifier) @defcolor_type))
|
||||
|
||||
[(primitive_type) (type_qualifier) (storage_class_specifier)
|
||||
(break_statement) (continue_statement) "union" "return" "do"
|
||||
"while" "for" "if" "class" "struct" "enum" "sizeof"
|
||||
"else" "switch" "case"] @defcolor_keyword
|
||||
|
||||
[(number_literal) (string_literal) (raw_string_literal)] @defcolor_str_constant
|
||||
|
||||
[(preproc_directive) "#define" "#if" "#elif" "#else" "#endif"
|
||||
"#include"] @defcolor_preproc
|
||||
|
||||
["{" "}" ";" ":" ","] @defcolor_text_default
|
||||
|
||||
(comment) @defcolor_comment
|
||||
)DONE");
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Jai
|
||||
|
||||
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");
|
||||
#include "languages/tree_sitter_cpp.h"
|
||||
#include "languages/tree_sitter_jai.h"
|
||||
#include "languages/tree_sitter_bash.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Language Management
|
||||
|
@ -490,32 +109,9 @@ tree_sitter_init(Application_Links* app)
|
|||
|
||||
tree_sitter_languages.arena = make_arena_system(KB(16));
|
||||
|
||||
u32 error_offset;
|
||||
TSQueryError query_error;
|
||||
|
||||
{ // Register CPP
|
||||
TSLanguage* language = tree_sitter_cpp();
|
||||
String_Const_u8 highlight_query_str = TS_CPP_HIGHLIGHT_QUERY;
|
||||
|
||||
Tree_Sitter_Language_Queries queries = {};
|
||||
queries.ptr[Tree_Sitter_Language_Query_Highlights] = tree_sitter_query_new(app, language, TS_CPP_HIGHLIGHT_QUERY);
|
||||
queries.ptr[Tree_Sitter_Language_Query_Functions] = tree_sitter_query_new(app, language, TS_CPP_FUNCTION_QUERY);
|
||||
queries.ptr[Tree_Sitter_Language_Query_Types] = tree_sitter_query_new(app, language, TS_CPP_TYPE_QUERY);
|
||||
tree_sitter_register_language(SCu8("c"), language, queries);
|
||||
tree_sitter_register_language(SCu8("cpp"), language, queries);
|
||||
tree_sitter_register_language(SCu8("h"), language, queries);
|
||||
tree_sitter_register_language(SCu8("hpp"), language, queries);
|
||||
tree_sitter_register_language(SCu8("cc"), language, queries);
|
||||
}
|
||||
|
||||
{ // Register Jai
|
||||
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);
|
||||
}
|
||||
tree_sitter_register_cpp(app);
|
||||
tree_sitter_register_jai(app);
|
||||
tree_sitter_register_bash(app);
|
||||
}
|
||||
|
||||
function void
|
||||
|
@ -555,6 +151,67 @@ tree_sitter_buffer_get_tree_copy(Buffer_Tree_Sitter_Data* tree_data)
|
|||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Queries
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Tree_Sitter_Query_Cursor
|
||||
{
|
||||
Buffer_ID buffer_id;
|
||||
TSQuery* query;
|
||||
TSQueryCursor* query_cursor;
|
||||
TSTree* tree;
|
||||
TSNode first_node;
|
||||
bool ok;
|
||||
};
|
||||
|
||||
function Tree_Sitter_Query_Cursor
|
||||
tree_sitter_query_init(Application_Links* app, Buffer_ID buffer_id, TSQuery* query)
|
||||
{
|
||||
Tree_Sitter_Query_Cursor result = {};
|
||||
result.buffer_id = buffer_id;
|
||||
result.query = query;
|
||||
result.ok = false;
|
||||
|
||||
Managed_Scope buffer_scope = buffer_get_managed_scope(app, buffer_id);
|
||||
Buffer_Tree_Sitter_Data* tree_data = scope_attachment(app, buffer_scope, buffer_tree_sitter_data_id, Buffer_Tree_Sitter_Data);
|
||||
result.tree = tree_sitter_buffer_get_tree_copy(tree_data);
|
||||
if (result.tree) result.first_node = ts_tree_root_node(result.tree);
|
||||
|
||||
result.ok = (
|
||||
result.query != 0 &&
|
||||
result.tree != 0
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
function bool
|
||||
tree_sitter_query_continue(Tree_Sitter_Query_Cursor* cursor, TSQueryMatch* match, u32* capture_index)
|
||||
{
|
||||
if (cursor->ok)
|
||||
{
|
||||
if (!cursor->query_cursor)
|
||||
{
|
||||
cursor->query_cursor = ts_query_cursor_new();
|
||||
ts_query_cursor_exec(cursor->query_cursor, cursor->query, cursor->first_node);
|
||||
}
|
||||
|
||||
cursor->ok = ts_query_cursor_next_capture(cursor->query_cursor, match, capture_index);
|
||||
}
|
||||
return cursor->ok;
|
||||
}
|
||||
|
||||
function void
|
||||
tree_sitter_query_end(Tree_Sitter_Query_Cursor* cursor)
|
||||
{
|
||||
if (cursor->query_cursor) ts_query_cursor_delete(cursor->query_cursor);
|
||||
ts_tree_delete(cursor->tree);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Tree Parsing
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
function void
|
||||
tree_sitter_parse_async__inner(Async_Context* actx, Buffer_ID buffer_id)
|
||||
{
|
||||
|
@ -566,6 +223,12 @@ tree_sitter_parse_async__inner(Async_Context* actx, Buffer_ID buffer_id)
|
|||
ts_parser_set_timeout_micros(parser, 5000);
|
||||
|
||||
acquire_global_frame_mutex(app);
|
||||
Scratch_Block scratch(app);
|
||||
String_Const_u8 buffer_name = push_buffer_unique_name(app, scratch, buffer_id);
|
||||
print_message(app, SCu8("Parsing "));
|
||||
print_message(app, buffer_name);
|
||||
print_message(app, SCu8("\n"));
|
||||
|
||||
Tree_Sitter_Language_Definition* lang = tree_sitter_language_for_buffer(app, buffer_id);
|
||||
String_Const_u8 src = push_whole_buffer(app, &arena, buffer_id);
|
||||
Managed_Scope scope = buffer_get_managed_scope(app, buffer_id);
|
||||
|
@ -606,8 +269,6 @@ tree_sitter_parse_async__inner(Async_Context* actx, Buffer_ID buffer_id)
|
|||
tree_data->tree = new_tree;
|
||||
system_mutex_acquire(tree_data->tree_mutex);
|
||||
|
||||
print_message(app, SCu8("Finished Parse\n"));
|
||||
|
||||
// TODO(PS): Just put the code index update call here
|
||||
// NOTE(jack): This feels kinda hacky, this is here to trigger
|
||||
// the code index update tick. The buffer is also makred by the
|
||||
|
@ -807,63 +468,6 @@ draw_tree_sitter_node_colors(Application_Links* app, Text_Layout_ID text_layout_
|
|||
ts_tree_delete(tree);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Queries
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Tree_Sitter_Query_Cursor
|
||||
{
|
||||
Buffer_ID buffer_id;
|
||||
TSQuery* query;
|
||||
TSQueryCursor* query_cursor;
|
||||
TSTree* tree;
|
||||
TSNode first_node;
|
||||
bool ok;
|
||||
};
|
||||
|
||||
function Tree_Sitter_Query_Cursor
|
||||
tree_sitter_query_init(Application_Links* app, Buffer_ID buffer_id, TSQuery* query)
|
||||
{
|
||||
Tree_Sitter_Query_Cursor result = {};
|
||||
result.buffer_id = buffer_id;
|
||||
result.query = query;
|
||||
result.ok = false;
|
||||
|
||||
Managed_Scope buffer_scope = buffer_get_managed_scope(app, buffer_id);
|
||||
Buffer_Tree_Sitter_Data* tree_data = scope_attachment(app, buffer_scope, buffer_tree_sitter_data_id, Buffer_Tree_Sitter_Data);
|
||||
result.tree = tree_sitter_buffer_get_tree_copy(tree_data);
|
||||
result.first_node = ts_tree_root_node(result.tree);
|
||||
|
||||
result.ok = (
|
||||
result.query != 0 &&
|
||||
result.tree != 0
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
function bool
|
||||
tree_sitter_query_continue(Tree_Sitter_Query_Cursor* cursor, TSQueryMatch* match, u32* capture_index)
|
||||
{
|
||||
if (cursor->ok)
|
||||
{
|
||||
if (!cursor->query_cursor)
|
||||
{
|
||||
cursor->query_cursor = ts_query_cursor_new();
|
||||
ts_query_cursor_exec(cursor->query_cursor, cursor->query, cursor->first_node);
|
||||
}
|
||||
|
||||
cursor->ok = ts_query_cursor_next_capture(cursor->query_cursor, match, capture_index);
|
||||
}
|
||||
return cursor->ok;
|
||||
}
|
||||
|
||||
function void
|
||||
tree_sitter_query_end(Tree_Sitter_Query_Cursor* cursor)
|
||||
{
|
||||
if (cursor->query_cursor) ts_query_cursor_delete(cursor->query_cursor);
|
||||
ts_tree_delete(cursor->tree);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Lists
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
enum Tree_Sitter_Language_Query_Kind
|
||||
{
|
||||
Tree_Sitter_Language_Query_Highlights,
|
||||
Tree_Sitter_Language_Query_Nests,
|
||||
|
||||
Tree_Sitter_Language_Query_Functions,
|
||||
Tree_Sitter_Language_Query_Types,
|
||||
|
||||
|
@ -38,10 +40,6 @@ struct Tree_Sitter_Languages
|
|||
|
||||
global Tree_Sitter_Languages tree_sitter_languages;
|
||||
|
||||
extern "C" {
|
||||
TSLanguage *tree_sitter_cpp();
|
||||
TSLanguage *tree_sitter_jai();
|
||||
}
|
||||
|
||||
CUSTOM_ID(attachment, buffer_tree_sitter_data_id);
|
||||
CUSTOM_ID(attachment, buffer_tree_sitter_parse_task_id);
|
||||
|
@ -69,6 +67,9 @@ struct Tree_Sitter_Code_Index_Nest_List
|
|||
Tree_Sitter_Code_Index_Nest_Node* last;
|
||||
};
|
||||
|
||||
function TSQuery* tree_sitter_query_new(Application_Links* app, TSLanguage* language, String_Const_u8 query_string);
|
||||
function void tree_sitter_register_language(String_Const_u8 ext, TSLanguage* language, Tree_Sitter_Language_Queries queries);
|
||||
|
||||
b8 use_tree_sitter_code_indexing = true;
|
||||
b8 use_tree_sitter_token_coloring = true;
|
||||
function void tree_sitter_code_index_update_tick(Application_Links *app);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/* date = July 11th 2025 6:02 pm */
|
||||
|
||||
#ifndef TREE_SITTER_BASH_H
|
||||
#define TREE_SITTER_BASH_H
|
||||
|
||||
String_Const_u8 TS_BASH_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
|
||||
|
||||
(command name: (command_name) @defcolor_function)
|
||||
(variable_assignment name: (variable_name) @defcolor_macro)
|
||||
|
||||
; Basic Types
|
||||
(string) @defcolor_str_constant
|
||||
(number) @defcolor_int_constant
|
||||
|
||||
(comment) @defcolor_comment
|
||||
)DONE");
|
||||
|
||||
extern "C" {
|
||||
TSLanguage* tree_sitter_bash();
|
||||
}
|
||||
|
||||
void
|
||||
tree_sitter_register_bash(Application_Links* app)
|
||||
{
|
||||
TSLanguage* language = tree_sitter_bash();
|
||||
Tree_Sitter_Language_Queries queries = {};
|
||||
queries.ptr[Tree_Sitter_Language_Query_Highlights] = tree_sitter_query_new(app, language, TS_BASH_HIGHLIGHT_QUERY);
|
||||
tree_sitter_register_language(SCu8("sh"), language, queries);
|
||||
}
|
||||
|
||||
#endif //TREE_SITTER_BASH_H
|
|
@ -0,0 +1,81 @@
|
|||
/* date = July 11th 2025 6:04 pm */
|
||||
|
||||
#ifndef TREE_SITTER_CPP_H
|
||||
#define TREE_SITTER_CPP_H
|
||||
|
||||
String_Const_u8 TS_CPP_NEST_QUERY = string_u8_litexpr("(_ \"{\" @scope_begin \"}\" @scope_end )\n");
|
||||
|
||||
String_Const_u8 TS_CPP_FUNCTION_QUERY = string_u8_litexpr(R"DONE(
|
||||
(function_declarator) @function_identifier
|
||||
)DONE");
|
||||
|
||||
String_Const_u8 TS_CPP_TYPE_QUERY = string_u8_litexpr(R"DONE(
|
||||
(struct_specifier
|
||||
name: (type_identifier) @prefixStruct
|
||||
)
|
||||
(enum_specifier
|
||||
name: (type_identifier) @prefixEnum
|
||||
)
|
||||
(class_specifier
|
||||
name: (type_identifier) @prefixClass
|
||||
)
|
||||
)DONE");
|
||||
|
||||
String_Const_u8 TS_CPP_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
|
||||
(call_expression function: [
|
||||
(identifier) @defcolor_function
|
||||
(field_expression field: (field_identifier) @defcolor_function)])
|
||||
|
||||
(function_declarator
|
||||
declarator: [(identifier) (field_identifier)] @defcolor_function)
|
||||
|
||||
(preproc_def
|
||||
name: (identifier) @defcolor_macro)
|
||||
|
||||
(preproc_function_def
|
||||
name: (identifier) @defcolor_macro)
|
||||
|
||||
(type_identifier) @defcolor_type
|
||||
|
||||
(call_expression
|
||||
function: (parenthesized_expression
|
||||
(identifier) @defcolor_type))
|
||||
|
||||
[(primitive_type) (type_qualifier) (storage_class_specifier)
|
||||
(break_statement) (continue_statement) "union" "return" "do"
|
||||
"while" "for" "if" "class" "struct" "enum" "sizeof"
|
||||
"else" "switch" "case"] @defcolor_keyword
|
||||
|
||||
[(number_literal) (string_literal) (raw_string_literal)] @defcolor_str_constant
|
||||
|
||||
[(preproc_directive) "#define" "#if" "#elif" "#else" "#endif"
|
||||
"#include"] @defcolor_preproc
|
||||
|
||||
["{" "}" ";" ":" ","] @defcolor_text_default
|
||||
|
||||
(comment) @defcolor_comment
|
||||
)DONE");
|
||||
|
||||
extern "C" {
|
||||
TSLanguage *tree_sitter_cpp();
|
||||
}
|
||||
|
||||
void
|
||||
tree_sitter_register_cpp(Application_Links* app)
|
||||
{
|
||||
TSLanguage* language = tree_sitter_cpp();
|
||||
String_Const_u8 highlight_query_str = TS_CPP_HIGHLIGHT_QUERY;
|
||||
|
||||
Tree_Sitter_Language_Queries queries = {};
|
||||
queries.ptr[Tree_Sitter_Language_Query_Highlights] = tree_sitter_query_new(app, language, TS_CPP_HIGHLIGHT_QUERY);
|
||||
queries.ptr[Tree_Sitter_Language_Query_Nests] = tree_sitter_query_new(app, language, TS_CPP_NEST_QUERY);
|
||||
queries.ptr[Tree_Sitter_Language_Query_Functions] = tree_sitter_query_new(app, language, TS_CPP_FUNCTION_QUERY);
|
||||
queries.ptr[Tree_Sitter_Language_Query_Types] = tree_sitter_query_new(app, language, TS_CPP_TYPE_QUERY);
|
||||
tree_sitter_register_language(SCu8("c"), language, queries);
|
||||
tree_sitter_register_language(SCu8("cpp"), language, queries);
|
||||
tree_sitter_register_language(SCu8("h"), language, queries);
|
||||
tree_sitter_register_language(SCu8("hpp"), language, queries);
|
||||
tree_sitter_register_language(SCu8("cc"), language, queries);
|
||||
}
|
||||
|
||||
#endif //TREE_SITTER_CPP_H
|
|
@ -0,0 +1,343 @@
|
|||
/* 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
|
|
@ -12,6 +12,7 @@ patterns = {
|
|||
};
|
||||
blacklist_patterns = {
|
||||
".*",
|
||||
"non-source",
|
||||
};
|
||||
load_paths_base = {
|
||||
{ ".", .relative = true, .recursive = true, },
|
||||
|
|
Loading…
Reference in New Issue