306 lines
4.6 KiB
C
306 lines
4.6 KiB
C
/* date = July 11th 2025 6:03 pm */
|
|
|
|
#ifndef TREE_SITTER_JAI_H
|
|
#define TREE_SITTER_JAI_H
|
|
|
|
String_Const_u8 TS_JAI_TAGS_QUERY = string_u8_litexpr(R"DONE(
|
|
|
|
(procedure_declaration
|
|
name: (identifier) @definition.function
|
|
)
|
|
|
|
(struct_declaration
|
|
name: (identifier) @definition.type
|
|
)
|
|
|
|
(enum_declaration
|
|
name: (identifier) @definition.type
|
|
)
|
|
|
|
("{" @scope_begin "}" @scope_end )
|
|
("(" @scope_begin ")" @scope_end )
|
|
("[" @scope_begin "]" @scope_end )
|
|
|
|
)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(
|
|
; Includes
|
|
|
|
[
|
|
(import)
|
|
(load)
|
|
] @include
|
|
|
|
; Keywords
|
|
[
|
|
; from modules/Jai_Lexer
|
|
"if"
|
|
"xx"
|
|
|
|
"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"
|
|
"else"
|
|
"case"
|
|
"break"
|
|
] @keyword.conditional
|
|
|
|
((if_expression
|
|
[
|
|
"then"
|
|
"ifx"
|
|
"else"
|
|
] @keyword.conditional.ternary)
|
|
(#set! "priority" 105))
|
|
|
|
; Repeats
|
|
|
|
[
|
|
"for"
|
|
"while"
|
|
"continue"
|
|
] @keyword.repeat
|
|
|
|
; Variables
|
|
|
|
; (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
|
|
|
|
(import (identifier) @namespace)
|
|
|
|
; Parameters
|
|
|
|
(parameter (identifier) @parameter ":" "="? (identifier)? @constant)
|
|
|
|
; (call_expression argument: (identifier) @parameter "=")
|
|
|
|
; Functions
|
|
|
|
; (procedure_declaration (identifier) @function (procedure (block)))
|
|
(procedure_declaration (identifier) @function (block))
|
|
|
|
(call_expression function: (identifier) @function.call)
|
|
|
|
; Types
|
|
|
|
type: (types) @type
|
|
type: (identifier) @type
|
|
((types) @type)
|
|
|
|
modifier: (identifier) @keyword
|
|
keyword: (identifier) @keyword
|
|
|
|
((types (identifier) @type.builtin)
|
|
(#any-of? @type.builtin
|
|
"bool" "int" "string"
|
|
"s8" "s16" "s32" "s64"
|
|
"u8" "u16" "u32" "u64"
|
|
"Type" "Any"))
|
|
|
|
(struct_declaration (identifier) @type ":" ":")
|
|
|
|
(enum_declaration (identifier) @type ":" ":")
|
|
|
|
; (const_declaration (identifier) @type ":" ":" [(array_type) (pointer_type)])
|
|
|
|
; ; I don't like this
|
|
; ((identifier) @type
|
|
; (#lua-match? @type "^[A-Z][a-zA-Z0-9]*$")
|
|
; (#not-has-parent? @type parameter procedure_declaration call_expression))
|
|
|
|
; Fields
|
|
|
|
(member_expression "." (identifier) @field)
|
|
|
|
(assignment_statement (identifier) @field "="?)
|
|
(update_statement (identifier) @field)
|
|
|
|
; Constants
|
|
|
|
((identifier) @constant
|
|
(#lua-match? @constant "^_*[A-Z][A-Z0-9_]*$")
|
|
(#not-has-parent? @constant type parameter))
|
|
|
|
(member_expression . "." (identifier) @constant)
|
|
|
|
(enum_declaration "{" (identifier) @constant)
|
|
|
|
; Literals
|
|
|
|
(integer) @number
|
|
(float) @number
|
|
|
|
(string) @string
|
|
|
|
;(character) @character
|
|
|
|
(string (escape_sequence) @string.escape)
|
|
|
|
(boolean) @boolean
|
|
|
|
[
|
|
(uninitialized)
|
|
(null)
|
|
] @constant.builtin
|
|
|
|
; Operators
|
|
|
|
[
|
|
":"
|
|
"="
|
|
"+"
|
|
"-"
|
|
"*"
|
|
"/"
|
|
"%"
|
|
">"
|
|
">="
|
|
"<"
|
|
"<="
|
|
"=="
|
|
"!="
|
|
"|"
|
|
"~"
|
|
"&"
|
|
"&~"
|
|
"<<"
|
|
">>"
|
|
"<<<"
|
|
">>>"
|
|
"||"
|
|
"&&"
|
|
"!"
|
|
".."
|
|
"+="
|
|
"-="
|
|
"*="
|
|
"/="
|
|
"%="
|
|
"&="
|
|
"|="
|
|
"^="
|
|
"<<="
|
|
">>="
|
|
"<<<="
|
|
">>>="
|
|
"||="
|
|
"&&="
|
|
] @operator
|
|
|
|
; Punctuation
|
|
|
|
[ "{" "}" ] @punctuation.bracket
|
|
|
|
[ "(" ")" ] @punctuation.bracket
|
|
|
|
[ "[" "]" ] @punctuation.bracket
|
|
|
|
[
|
|
"`"
|
|
"->"
|
|
"."
|
|
","
|
|
":"
|
|
";"
|
|
] @punctuation.delimiter
|
|
|
|
; Comments
|
|
|
|
[
|
|
(block_comment)
|
|
(comment)
|
|
] @comment @spell
|
|
|
|
; Errors
|
|
|
|
(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");
|
|
|
|
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_Tags] = tree_sitter_query_new(app, language, TS_JAI_TAGS_QUERY);
|
|
Tree_Sitter_Language_Flags flags = (
|
|
Tree_Sitter_Language_Can_Receive_Virtual_Indent
|
|
);
|
|
tree_sitter_register_language(SCu8("jai"), language, queries, flags);
|
|
}
|
|
|
|
#endif //TREE_SITTER_JAI_H
|