Switched to using the default highlight and tags queries for cpp, jai, bash.

This commit is contained in:
Peter Slattery 2025-07-13 08:44:45 -07:00
parent c5a462993d
commit 336a98f701
5 changed files with 424 additions and 265 deletions

View File

@ -395,7 +395,7 @@ async_task_cancel_nowait(Application_Links* app, Async_System* async_system, Asy
// Token Highlighting // Token Highlighting
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
function void function bool
tree_sitter_highlight_node( tree_sitter_highlight_node(
Application_Links* app, Application_Links* app,
TSQuery* query, TSQuery* query,
@ -403,6 +403,7 @@ tree_sitter_highlight_node(
TSQueryCursor* query_cursor, TSQueryCursor* query_cursor,
Text_Layout_ID text_layout_id Text_Layout_ID text_layout_id
){ ){
bool highlighted_any_code = false;
ts_query_cursor_exec(query_cursor, query, top_node); ts_query_cursor_exec(query_cursor, query, top_node);
TSQueryMatch query_match; TSQueryMatch query_match;
@ -416,13 +417,33 @@ tree_sitter_highlight_node(
const char* tmp = ts_query_capture_name_for_id(query, capture.index, &length); const char* tmp = ts_query_capture_name_for_id(query, capture.index, &length);
String_Const_u8 capture_name = SCu8((char*)tmp, length); String_Const_u8 capture_name = SCu8((char*)tmp, length);
// TODO(PS): let each language provide a custom override
String_Const_u8 color_name = SCu8("defcolor_text_default");
if (string_match(capture_name, SCu8("function"))) {
color_name = SCu8("defcolor_function");
} else if (string_match(capture_name, SCu8("type"))) {
color_name = SCu8("defcolor_type");
} else if (string_match(capture_name, SCu8("constant")) || string_match(capture_name, SCu8("number"))) {
color_name = SCu8("defcolor_int_constant");
} else if (string_match(capture_name, SCu8("keyword"))) {
color_name = SCu8("defcolor_keyword");
} else if (string_match(capture_name, SCu8("string"))) {
color_name = SCu8("defcolor_str_constant");
} else if (string_match(capture_name, SCu8("comment"))) {
color_name = SCu8("defcolor_comment");
}
Range_i64 highlight_range = tree_sitter_node_to_range(node); Range_i64 highlight_range = tree_sitter_node_to_range(node);
Managed_ID color_id = managed_id_get(app, SCu8("colors"), capture_name); Managed_ID color_id = managed_id_get(app, SCu8("colors"), color_name);
if (color_id != 0) if (color_id != 0)
{ {
paint_text_color_fcolor(app, text_layout_id, highlight_range, fcolor_id(color_id)); paint_text_color_fcolor(app, text_layout_id, highlight_range, fcolor_id(color_id));
} }
highlighted_any_code = true;
} }
return highlighted_any_code;
} }
function void function void
@ -461,7 +482,11 @@ draw_tree_sitter_node_colors(Application_Links* app, Text_Layout_ID text_layout_
} }
else else
{ {
tree_sitter_highlight_node(app, query, visible_container, query_cursor, text_layout_id); bool should_ascend = false;
do {
should_ascend = !tree_sitter_highlight_node(app, query, visible_container, query_cursor, text_layout_id);
if (should_ascend) visible_container = ts_node_parent(visible_container);
} while (should_ascend && !ts_node_is_null(visible_container));
} }
ts_query_cursor_delete(query_cursor); ts_query_cursor_delete(query_cursor);
} }
@ -483,6 +508,10 @@ convert_to_single_line_in_place(String_Const_u8 str)
{ {
while (src < str.size && character_is_whitespace(str.str[src])) { src += 1; } while (src < str.size && character_is_whitespace(str.str[src])) { src += 1; }
if (src >= str.size) break; if (src >= str.size) break;
else {
result.str[dst] = ' ';
dst += 1;
}
} }
result.str[dst] = str.str[src]; result.str[dst] = str.str[src];
dst += 1; dst += 1;
@ -555,15 +584,10 @@ tree_sitter_list_all_query_results(
{ {
Tree_Sitter_Language_Definition* lang = tree_sitter_language_for_buffer(app, buffer); Tree_Sitter_Language_Definition* lang = tree_sitter_language_for_buffer(app, buffer);
if (!lang) continue; if (!lang) continue;
TSQuery* ts_query = lang->queries.ptr[query_kind]; TSQuery* ts_query = lang->queries.ptr[Tree_Sitter_Language_Query_Tags];
if (!ts_query) ts_query = lang->queries.ptr[Tree_Sitter_Language_Query_Highlights];
Tree_Sitter_Query_Cursor query = tree_sitter_query_init(app, buffer, ts_query); Tree_Sitter_Query_Cursor query = tree_sitter_query_init(app, buffer, ts_query);
i64 last_query_match_id = -1;
i64 last_query_match_printed = -1;
i64 last_query_line_number = 0;
Range_i64 last_query_range = {};
String_Const_u8 last_query_prefix = {};
TSQueryMatch query_match; TSQueryMatch query_match;
u32 capture_index; u32 capture_index;
bool reached_end = false; bool reached_end = false;
@ -571,43 +595,44 @@ tree_sitter_list_all_query_results(
{ {
TSQueryCapture capture = query_match.captures[capture_index]; TSQueryCapture capture = query_match.captures[capture_index];
if (last_query_match_id != query_match.id) Range_i64 match_range;
{ match_range.start = (i64)ts_node_start_byte(capture.node);
if (last_query_match_id >= 0) match_range.end = (i64)ts_node_end_byte(capture.node);
{
print_position(
app, &out, buffer, buffer_name, last_query_range, last_query_prefix, scratch, true
);
last_query_match_printed = last_query_match_id;
}
last_query_range.start = (i64)ts_node_start_byte(capture.node);
last_query_range.end = last_query_range.start;
last_query_prefix = {};
}
last_query_match_id = query_match.id;
last_query_range.end = Max((i64)ts_node_end_byte(capture.node), last_query_range.end);
String_Const_u8 name; String_Const_u8 name;
u32 name_length; u32 name_length;
name.str = (u8*)ts_query_capture_name_for_id(ts_query, capture.index, &name_length); name.str = (u8*)ts_query_capture_name_for_id(ts_query, capture.index, &name_length);
name.size = (u64)name_length; name.size = (u64)name_length;
String_Const_u8 prefix_identifier = SCu8("prefix"); bool matches = false;
u64 prefix_loc = string_find_first(name, prefix_identifier); switch (query_kind)
if (prefix_loc < name.size)
{ {
last_query_prefix = name; case Tree_Sitter_Language_Query_Functions:
last_query_prefix.str += prefix_loc + prefix_identifier.size; {
last_query_prefix.size -= prefix_loc + prefix_identifier.size; matches = string_match(name, SCu8("function"));
} matches |= string_match(name, SCu8("definition.function"));
}
if (last_query_match_printed != last_query_match_id) // TODO(PS): ideally, these should be provided by the language
{ matches |= string_match(name, SCu8("definition.method"));
print_position( } break;
app, &out, buffer, buffer_name, last_query_range, last_query_prefix, scratch, true
); case Tree_Sitter_Language_Query_Types:
{
matches = string_match(name, SCu8("type"));
matches |= string_match(name, SCu8("definition.type"));
// TODO(PS): ideally, these should be provided by the language
matches |= string_match(name, SCu8("definition.class"));
matches |= string_match(name, SCu8("definition.interface"));
} break;
}
if (matches)
{
print_position(
app, &out, buffer, buffer_name, match_range, {}, scratch, true
);
}
} }
tree_sitter_query_end(&query); tree_sitter_query_end(&query);

View File

@ -8,6 +8,8 @@
enum Tree_Sitter_Language_Query_Kind enum Tree_Sitter_Language_Query_Kind
{ {
Tree_Sitter_Language_Query_Highlights, Tree_Sitter_Language_Query_Highlights,
Tree_Sitter_Language_Query_Tags,
Tree_Sitter_Language_Query_Nests, Tree_Sitter_Language_Query_Nests,
Tree_Sitter_Language_Query_Functions, Tree_Sitter_Language_Query_Functions,

View File

@ -3,16 +3,65 @@
#ifndef TREE_SITTER_BASH_H #ifndef TREE_SITTER_BASH_H
#define TREE_SITTER_BASH_H #define TREE_SITTER_BASH_H
// Source: https://github.com/tree-sitter/tree-sitter-bash/blob/master/queries/highlights.scm
String_Const_u8 TS_BASH_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE( String_Const_u8 TS_BASH_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
[
(string)
(raw_string)
(heredoc_body)
(heredoc_start)
] @string
(command name: (command_name) @defcolor_function) (command_name) @function.call
(variable_assignment name: (variable_name) @defcolor_macro)
; Basic Types (variable_name) @property
(string) @defcolor_str_constant
(number) @defcolor_int_constant [
"case"
"do"
"done"
"elif"
"else"
"esac"
"export"
"fi"
"for"
"function"
"if"
"in"
"select"
"then"
"unset"
"until"
"while"
] @keyword
(comment) @comment
(function_definition name: (word) @function)
(file_descriptor) @number
[
(command_substitution)
(process_substitution)
(expansion)
] @embedded
[
"$"
"&&"
">"
">>"
"<"
"|"
] @operator
(
(command (_) @constant)
(#match? @constant "^-")
)
(comment) @defcolor_comment
)DONE"); )DONE");
extern "C" { extern "C" {

View File

@ -5,55 +5,186 @@
String_Const_u8 TS_CPP_NEST_QUERY = string_u8_litexpr("(_ \"{\" @scope_begin \"}\" @scope_end )\n"); 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( // Source: https://github.com/tree-sitter/tree-sitter-cpp/blob/master/queries/tags.scm
(function_declarator) @function_identifier String_Const_u8 TS_CPP_TAGS_QUERY_SCM = string_u8_litexpr(R"DONE(
(struct_specifier name: (type_identifier) @name body:(_)) @definition.class
(declaration type: (union_specifier name: (type_identifier) @name)) @definition.class
(function_declarator declarator: (identifier) @name) @definition.function
(function_declarator declarator: (field_identifier) @name) @definition.function
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @local.scope name: (identifier) @name)) @definition.method
(type_definition declarator: (type_identifier) @name) @definition.type
(enum_specifier name: (type_identifier) @name) @definition.type
(class_specifier name: (type_identifier) @name) @definition.class
)DONE"); )DONE");
String_Const_u8 TS_CPP_TYPE_QUERY = string_u8_litexpr(R"DONE( // Source: https://github.com/tree-sitter/tree-sitter-cpp/blob/master/queries/highlights.scm
(struct_specifier String_Const_u8 TS_CPP_HIGHLIGHT_QUERY_SCM = string_u8_litexpr(R"DONE(
name: (type_identifier) @prefixStruct (identifier) @variable
)
(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( ((identifier) @constant
(call_expression function: [ (#match? @constant "^[A-Z][A-Z\\d_]*$"))
(identifier) @defcolor_function
(field_expression field: (field_identifier) @defcolor_function)])
(function_declarator "break" @keyword
declarator: [(identifier) (field_identifier)] @defcolor_function) "case" @keyword
"const" @keyword
"continue" @keyword
"default" @keyword
"do" @keyword
"else" @keyword
"enum" @keyword
"extern" @keyword
"for" @keyword
"if" @keyword
"inline" @keyword
"return" @keyword
"sizeof" @keyword
"static" @keyword
"struct" @keyword
"switch" @keyword
"typedef" @keyword
"union" @keyword
"volatile" @keyword
"while" @keyword
(preproc_def "#define" @keyword
name: (identifier) @defcolor_macro) "#elif" @keyword
"#else" @keyword
"#endif" @keyword
"#if" @keyword
"#ifdef" @keyword
"#ifndef" @keyword
"#include" @keyword
(preproc_directive) @keyword
(preproc_function_def "--" @operator
name: (identifier) @defcolor_macro) "-" @operator
"-=" @operator
"->" @operator
"=" @operator
"!=" @operator
"*" @operator
"&" @operator
"&&" @operator
"+" @operator
"++" @operator
"+=" @operator
"<" @operator
"==" @operator
">" @operator
"||" @operator
(type_identifier) @defcolor_type "." @delimiter
";" @delimiter
(string_literal) @string
(system_lib_string) @string
(null) @constant
(number_literal) @number
(char_literal) @number
(field_identifier) @property
(statement_identifier) @label
(type_identifier) @type
(primitive_type) @type
(sized_type_specifier) @type
(call_expression (call_expression
function: (parenthesized_expression function: (identifier) @function)
(identifier) @defcolor_type)) (call_expression
function: (field_expression
field: (field_identifier) @function))
(function_declarator
declarator: (identifier) @function)
(preproc_function_def
name: (identifier) @function.special)
[(primitive_type) (type_qualifier) (storage_class_specifier) (comment) @comment
(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 ; Functions
[(preproc_directive) "#define" "#if" "#elif" "#else" "#endif" (call_expression
"#include"] @defcolor_preproc function: (qualified_identifier
name: (identifier) @function))
["{" "}" ";" ":" ","] @defcolor_text_default (template_function
name: (identifier) @function)
(comment) @defcolor_comment (template_method
name: (field_identifier) @function)
(template_function
name: (identifier) @function)
(function_declarator
declarator: (qualified_identifier
name: (identifier) @function))
(function_declarator
declarator: (field_identifier) @function)
; Types
((namespace_identifier) @type
(#match? @type "^[A-Z]"))
(auto) @type
; Constants
(this) @variable.builtin
(null "nullptr" @constant)
; Modules
(module_name
(identifier) @module)
; Keywords
[
"catch"
"class"
"co_await"
"co_return"
"co_yield"
"constexpr"
"constinit"
"consteval"
"delete"
"explicit"
"final"
"friend"
"mutable"
"namespace"
"noexcept"
"new"
"override"
"private"
"protected"
"public"
"template"
"throw"
"try"
"typename"
"using"
"concept"
"requires"
"virtual"
"import"
"export"
"module"
] @keyword
; Strings
(raw_string_literal) @string
)DONE"); )DONE");
extern "C" { extern "C" {
@ -64,13 +195,10 @@ void
tree_sitter_register_cpp(Application_Links* app) tree_sitter_register_cpp(Application_Links* app)
{ {
TSLanguage* language = tree_sitter_cpp(); TSLanguage* language = tree_sitter_cpp();
String_Const_u8 highlight_query_str = TS_CPP_HIGHLIGHT_QUERY;
Tree_Sitter_Language_Queries queries = {}; 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_Highlights] = tree_sitter_query_new(app, language, TS_CPP_HIGHLIGHT_QUERY_SCM);
queries.ptr[Tree_Sitter_Language_Query_Tags] = tree_sitter_query_new(app, language, TS_CPP_TAGS_QUERY_SCM);
queries.ptr[Tree_Sitter_Language_Query_Nests] = tree_sitter_query_new(app, language, TS_CPP_NEST_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("c"), language, queries);
tree_sitter_register_language(SCu8("cpp"), language, queries); tree_sitter_register_language(SCu8("cpp"), language, queries);
tree_sitter_register_language(SCu8("h"), language, queries); tree_sitter_register_language(SCu8("h"), language, queries);

View File

@ -3,143 +3,98 @@
#ifndef TREE_SITTER_JAI_H #ifndef TREE_SITTER_JAI_H
#define TREE_SITTER_JAI_H #define TREE_SITTER_JAI_H
String_Const_u8 TS_JAI_FUNCTION_QUERY = string_u8_litexpr(R"DONE( String_Const_u8 TS_JAI_TAGS_QUERY = string_u8_litexpr(R"DONE(
(procedure_declaration (procedure_declaration
name: (identifier) @print1 name: (identifier) @definition.function
(procedure
(named_parameters) @print2
(procedure_returns) @print
)
) )
)DONE");
String_Const_u8 TS_JAI_TYPE_QUERY = string_u8_litexpr(R"DONE(
(struct_declaration (struct_declaration
name: (identifier) @prefixStruct name: (identifier) @definition.type
) )
(enum_declaration (enum_declaration
name: (identifier) @prefixEnum name: (identifier) @definition.type
) )
)DONE"); )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 // 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( String_Const_u8 TS_JAI_HIGHLIGHT_QUERY = string_u8_litexpr(R"DONE(
; Includes
[ [
(compiler_directive)
(import) (import)
] @defcolor_macro (load)
] @include
; Keywords ; Keywords
; TODO : complete this list
[ [
"struct" ; from modules/Jai_Lexer
"enum" "if"
"defer"
"cast"
"xx" "xx"
"return"
] @defcolor_keyword
; Conditionals "ifx"
"for"
"then"
"else"
"null"
"case"
"enum"
"true"
"cast"
"while"
"break"
"using"
"defer"
"false"
"union"
"return"
"struct"
"inline"
"remove"
; "size_of"
"type_of"
; "code_of"
; "context"
"continue"
"operator"
; "type_info"
"no_inline"
"interface"
"enum_flags"
; "is_constant"
"push_context"
; "initializer_of"
] @keyword
[
"return"
] @keyword.return
[ [
"if" "if"
"else" "else"
"case" "case"
"break" "break"
] @defcolor_keyword ] @keyword.conditional
((if_expression ((if_expression
[ [
"then" "then"
"ifx" "ifx"
"else" "else"
] @defcolor_keyword) ] @keyword.conditional.ternary)
(#set! "priority" 105)) (#set! "priority" 105))
; Repeats ; Repeats
@ -148,132 +103,123 @@ String_Const_u8 TS_JAI_HIGHLIGHT_QUERY_ = string_u8_litexpr(R"DONE(
"for" "for"
"while" "while"
"continue" "continue"
] @defcolor_keyword ] @keyword.repeat
; Variables ; Variables
(identifier) @defcolor_text_default ; (identifier) @variable
name: (identifier) @variable
argument: (identifier) @variable
named_argument: (identifier) @variable
(member_expression (identifier) @variable)
(parenthesized_expression (identifier) @variable)
((identifier) @variable.builtin
(#any-of? @variable.builtin "context"))
; Namespaces ; Namespaces
(import (identifier) @defcolor_text_default) (import (identifier) @namespace)
; Parameters ; Parameters
(parameter (identifier) @defcolor_text_default ":" "="? (identifier)? @defcolor_str_constant) (parameter (identifier) @parameter ":" "="? (identifier)? @constant)
(default_parameter (identifier) @defcolor_text_default ":=") ; (call_expression argument: (identifier) @parameter "=")
(call_expression argument: (identifier) @defcolor_text_default "=")
; Functions ; Functions
(procedure_declaration (identifier) @defcolor_function) ; (procedure_declaration (identifier) @function (procedure (block)))
(procedure_declaration (identifier) @function (block))
(procedure_declaration (identifier) @defcolor_function (procedure (block))) (call_expression function: (identifier) @function.call)
(call_expression function: (identifier) @defcolor_function)
; Types ; Types
(type (identifier) @defcolor_type) type: (types) @type
type: (identifier) @type
((types) @type)
((type (identifier) @defcolor_type) modifier: (identifier) @keyword
keyword: (identifier) @keyword
((types (identifier) @type.builtin)
(#any-of? @type.builtin (#any-of? @type.builtin
"bool" "bool" "int" "string"
"int" "s8" "s16" "s32" "s64" "s8" "s16" "s32" "s64"
"u8" "u16" "u32" "u64" "u8" "u16" "u32" "u64"
"string")) "Type" "Any"))
(struct_declaration (identifier) @type ":" ":")
(struct_declaration (identifier) @defcolor_type "::") (enum_declaration (identifier) @type ":" ":")
(enum_declaration (identifier) @defcolor_type "::") ; (const_declaration (identifier) @type ":" ":" [(array_type) (pointer_type)])
;(union_declaration (identifier) @defcolor_type "::") ; ; I don't like this
; ((identifier) @type
(const_declaration (identifier) @defcolor_type "::" [(array_type) (pointer_type)]) ; (#lua-match? @type "^[A-Z][a-zA-Z0-9]*$")
; (#not-has-parent? @type parameter procedure_declaration call_expression))
(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 ; Fields
(member_expression "." (identifier) @defcolor_text_default) (member_expression "." (identifier) @field)
;(struct_type "{" (identifier) @defcolor_text_default) (assignment_statement (identifier) @field "="?)
(update_statement (identifier) @field)
(struct_field (identifier) @defcolor_text_default "="?)
(field (identifier) @defcolor_text_default)
; Constants ; Constants
((identifier) @defcolor_text_default ((identifier) @constant
(#lua-match? @defcolor_str_constnat "^_*[A-Z][A-Z0-9_]*$") (#lua-match? @constant "^_*[A-Z][A-Z0-9_]*$")
(#not-has-parent? @text_default type parameter)) (#not-has-parent? @constant type parameter))
(member_expression . "." (identifier) @defcolor_text_default) (member_expression . "." (identifier) @constant)
(enum_declaration "{" (identifier) @defcolor_text_default) (enum_declaration "{" (identifier) @constant)
; Literals ; Literals
(number) @defcolor_int_constant (integer) @number
(float) @number
(float) @defcolor_float_constant (string) @string
(string) @defcolor_str_constnat ;(character) @character
;(character) @defcolor_str_constnat (string (escape_sequence) @string.escape)
(escape_sequence) @defcolor_str_constant (boolean) @boolean
(boolean) @defcolor_bool_constant
[ [
(uninitialized) (uninitialized)
(null) (null)
] @defcolor_text_default ] @constant.builtin
((identifier) @defcolor_text_default
(#any-of? @defcolor_text_default "context"))
; Operators ; Operators
[ [
":=" ":"
"=" "="
"+" "+"
"-" "-"
"*" "*"
"/" "/"
"%" "%"
"%%"
">" ">"
">=" ">="
"<" "<"
"<=" "<="
"==" "=="
"!=" "!="
"~="
"|" "|"
"~" "~"
"&" "&"
"&~" "&~"
"<<" "<<"
">>" ">>"
"<<<"
">>>"
"||" "||"
"&&" "&&"
"!" "!"
@ -288,41 +234,51 @@ String_Const_u8 TS_JAI_HIGHLIGHT_QUERY_ = string_u8_litexpr(R"DONE(
"^=" "^="
"<<=" "<<="
">>=" ">>="
"<<<="
">>>="
"||=" "||="
"&&=" "&&="
"&~=" ] @operator
;"..="
;"..<"
;"?"
] @defcolor_operator
; Punctuation ; Punctuation
[ "{" "}" ] @defcolor_text_default [ "{" "}" ] @punctuation.bracket
[ "(" ")" ] @defcolor_text_default [ "(" ")" ] @punctuation.bracket
[ "[" "]" ] @defcolor_text_default [ "[" "]" ] @punctuation.bracket
[ [
"::" "`"
"->" "->"
"." "."
"," ","
":" ":"
";" ";"
] @defcolor_text_default ] @punctuation.delimiter
; Comments ; Comments
[ [
(comment)
(block_comment) (block_comment)
] @defcolor_comment (comment)
] @comment @spell
; Errors ; Errors
(ERROR) @defcolor_comment_pop (ERROR) @error
(block_comment) @comment
directive: ("#") @keyword ; #if
type: ("type_of") @type
(compiler_directive) @keyword
(heredoc_start) @none
(heredoc_end) @none
(heredoc_body) @string
(note) @string
)DONE"); )DONE");
extern "C" { extern "C" {
@ -335,8 +291,7 @@ tree_sitter_register_jai (Application_Links* app)
TSLanguage* language = tree_sitter_jai(); TSLanguage* language = tree_sitter_jai();
Tree_Sitter_Language_Queries queries = {}; 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_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_Tags] = tree_sitter_query_new(app, language, TS_JAI_TAGS_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_language(SCu8("jai"), language, queries);
} }