diff --git a/bex/queries/community/kotlin_highlights.scm b/bex/queries/community/kotlin_highlights.scm new file mode 100644 index 0000000..93eeb33 --- /dev/null +++ b/bex/queries/community/kotlin_highlights.scm @@ -0,0 +1,378 @@ +;; Based on the nvim-treesitter highlighting, which is under the Apache license. +;; See https://github.com/nvim-treesitter/nvim-treesitter/blob/f8ab59861eed4a1c168505e3433462ed800f2bae/queries/kotlin/highlights.scm +;; +;; The only difference in this file is that queries using #lua-match? +;; have been removed. + +;;; Identifiers + +(simple_identifier) @variable + +; `it` keyword inside lambdas +; FIXME: This will highlight the keyword outside of lambdas since tree-sitter +; does not allow us to check for arbitrary nestation +((simple_identifier) @variable.builtin +(#eq? @variable.builtin "it")) + +; `field` keyword inside property getter/setter +; FIXME: This will highlight the keyword outside of getters and setters +; since tree-sitter does not allow us to check for arbitrary nestation +((simple_identifier) @variable.builtin +(#eq? @variable.builtin "field")) + +; `this` this keyword inside classes +(this_expression) @variable.builtin + +; `super` keyword inside classes +(super_expression) @variable.builtin + +(class_parameter + (simple_identifier) @property) + +(class_body + (property_declaration + (variable_declaration + (simple_identifier) @property))) + +; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties +(_ + (navigation_suffix + (simple_identifier) @property)) + +(enum_entry + (simple_identifier) @constant) + +(type_identifier) @type + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "Byte" + "Short" + "Int" + "Long" + "UByte" + "UShort" + "UInt" + "ULong" + "Float" + "Double" + "Boolean" + "Char" + "String" + "Array" + "ByteArray" + "ShortArray" + "IntArray" + "LongArray" + "UByteArray" + "UShortArray" + "UIntArray" + "ULongArray" + "FloatArray" + "DoubleArray" + "BooleanArray" + "CharArray" + "Map" + "Set" + "List" + "EmptyMap" + "EmptySet" + "EmptyList" + "MutableMap" + "MutableSet" + "MutableList" +)) + +(package_header + . (identifier)) @namespace + +(import_header + "import" @include) + + +; TODO: Seperate labeled returns/breaks/continue/super/this +; Must be implemented in the parser first +(label) @label + +;;; Function definitions + +(function_declaration + . (simple_identifier) @function) + +(getter + ("get") @function.builtin) +(setter + ("set") @function.builtin) + +(primary_constructor) @constructor +(secondary_constructor + ("constructor") @constructor) + +(constructor_invocation + (user_type + (type_identifier) @constructor)) + +(anonymous_initializer + ("init") @constructor) + +(parameter + (simple_identifier) @parameter) + +(parameter_with_optional_type + (simple_identifier) @parameter) + +; lambda parameters +(lambda_literal + (lambda_parameters + (variable_declaration + (simple_identifier) @parameter))) + +;;; Function calls + +; function() +(call_expression + . (simple_identifier) @function) + +; object.function() or object.property.function() +(call_expression + (navigation_expression + (navigation_suffix + (simple_identifier) @function) . )) + +(call_expression + . (simple_identifier) @function.builtin + (#any-of? @function.builtin + "arrayOf" + "arrayOfNulls" + "byteArrayOf" + "shortArrayOf" + "intArrayOf" + "longArrayOf" + "ubyteArrayOf" + "ushortArrayOf" + "uintArrayOf" + "ulongArrayOf" + "floatArrayOf" + "doubleArrayOf" + "booleanArrayOf" + "charArrayOf" + "emptyArray" + "mapOf" + "setOf" + "listOf" + "emptyMap" + "emptySet" + "emptyList" + "mutableMapOf" + "mutableSetOf" + "mutableListOf" + "print" + "println" + "error" + "TODO" + "run" + "runCatching" + "repeat" + "lazy" + "lazyOf" + "enumValues" + "enumValueOf" + "assert" + "check" + "checkNotNull" + "require" + "requireNotNull" + "with" + "synchronized" +)) + +;;; Literals + +[ + (line_comment) + (multiline_comment) + (shebang_line) +] @comment + +(real_literal) @float +[ + (integer_literal) + (long_literal) + (hex_literal) + (bin_literal) + (unsigned_literal) +] @number + +[ + (null_literal) ; should be highlighted the same as booleans + (boolean_literal) +] @boolean + +(character_literal) @character + +(string_literal) @string + +(character_escape_seq) @string.escape + +; There are 3 ways to define a regex +; - "[abc]?".toRegex() +(call_expression + (navigation_expression + ((string_literal) @string.regex) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "toRegex"))))) + +; - Regex("[abc]?") +(call_expression + ((simple_identifier) @_function + (#eq? @_function "Regex")) + (call_suffix + (value_arguments + (value_argument + (string_literal) @string.regex)))) + +; - Regex.fromLiteral("[abc]?") +(call_expression + (navigation_expression + ((simple_identifier) @_class + (#eq? @_class "Regex")) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "fromLiteral")))) + (call_suffix + (value_arguments + (value_argument + (string_literal) @string.regex)))) + +;;; Keywords + +(type_alias "typealias" @keyword) +[ + (class_modifier) + (member_modifier) + (function_modifier) + (property_modifier) + (platform_modifier) + (variance_modifier) + (parameter_modifier) + (visibility_modifier) + (reification_modifier) + (inheritance_modifier) +]@keyword + +[ + "val" + "var" + "enum" + "class" + "object" + "interface" +; "typeof" ; NOTE: It is reserved for future use +] @keyword + +("fun") @keyword.function + +(jump_expression) @keyword.return + +[ + "if" + "else" + "when" +] @conditional + +[ + "for" + "do" + "while" +] @repeat + +[ + "try" + "catch" + "throw" + "finally" +] @exception + + +(annotation + "@" @attribute (use_site_target)? @attribute) +(annotation + (user_type + (type_identifier) @attribute)) +(annotation + (constructor_invocation + (user_type + (type_identifier) @attribute))) + +(file_annotation + "@" @attribute "file" @attribute ":" @attribute) +(file_annotation + (user_type + (type_identifier) @attribute)) +(file_annotation + (constructor_invocation + (user_type + (type_identifier) @attribute))) + +;;; Operators & Punctuation + +[ + "!" + "!=" + "!==" + "=" + "==" + "===" + ">" + ">=" + "<" + "<=" + "||" + "&&" + "+" + "++" + "+=" + "-" + "--" + "-=" + "*" + "*=" + "/" + "/=" + "%" + "%=" + "?." + "?:" + "!!" + "is" + "in" + "as" + "as?" + ".." + "..<" + "->" +] @operator + +[ + "(" ")" + "[" "]" + "{" "}" +] @punctuation.bracket + +[ + "." + "," + ";" + ":" + "::" +] @punctuation.delimiter + +; NOTE: `interpolated_identifier`s can be highlighted in any way +(string_literal + (interpolation_identifier_start) @punctuation.special + (interpolated_identifier) @none) +(string_literal + (interpolation_expression_start) @punctuation.special + (interpolated_expression) @none + (interpolation_expression_end) @punctuation.special) diff --git a/bex/queries/community/kotlin_tags.scm b/bex/queries/community/kotlin_tags.scm new file mode 100644 index 0000000..fa12bf6 --- /dev/null +++ b/bex/queries/community/kotlin_tags.scm @@ -0,0 +1,43 @@ +; Classes +(class_declaration + (type_identifier) @name) @definition.class + +; Objects +(object_declaration + (type_identifier) @name) @definition.class + +; Functions (top-level and member) +(function_declaration + (simple_identifier) @name) @definition.function + +; Properties +(property_declaration + (variable_declaration + (simple_identifier) @name)) @definition.constant + +; Enum entries +(enum_entry + (simple_identifier) @name) @definition.constant + +; Type aliases +(type_alias + (type_identifier) @name) @definition.type + +; Companion objects (only named ones) +(companion_object + (type_identifier) @name) @definition.class + +; Function calls +(call_expression + (simple_identifier) @name) @reference.call + +; Method calls via navigation +(call_expression + (navigation_expression + (navigation_suffix + (simple_identifier) @name))) @reference.call + +; Constructor invocations (class references) +(constructor_invocation + (user_type + (type_identifier) @name)) @reference.class diff --git a/bex/queries/community/typescript_highlights.scm b/bex/queries/community/typescript_highlights.scm new file mode 100644 index 0000000..c758b51 --- /dev/null +++ b/bex/queries/community/typescript_highlights.scm @@ -0,0 +1,35 @@ +; 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 diff --git a/bex/queries/community/typescript_tags.scm b/bex/queries/community/typescript_tags.scm new file mode 100644 index 0000000..ccae934 --- /dev/null +++ b/bex/queries/community/typescript_tags.scm @@ -0,0 +1,23 @@ +(function_signature + name: (identifier) @name) @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.interface + +(type_annotation + (type_identifier) @name) @reference.type + +(new_expression + constructor: (identifier) @name) @reference.class diff --git a/bex/queries/universal.scm b/bex/queries/universal.scm new file mode 100644 index 0000000..447c640 --- /dev/null +++ b/bex/queries/universal.scm @@ -0,0 +1,132 @@ +; UNIVERSAL DERVISH QUERY +; +; One query to extract behavioral tokens from any TreeSitter-supported language. +; TreeSitter silently ignores non-existent node types at query time, +; so we can reference nodes from all languages safely. +; +; Captures: +; @qualified-call — obj.method() → "obj.method" +; @simple-call — bare method() → "method" +; @annotation — @Annotation → "@Annotation" +; @constructor — new Type() / Type() → "Type" + +;; === JAVA === + +; obj.method() +(method_invocation + object: (identifier) @object + name: (identifier) @method) @qualified-call + +; method() (no explicit object) +(method_invocation + name: (identifier) @method + !object) @simple-call + +; @Annotation +(annotation + name: (identifier) @name) @annotation + +; @Annotation (no args) +(marker_annotation + name: (identifier) @name) @annotation + +; new Type() +(object_creation_expression + type: (type_identifier) @name) @constructor + +;; === KOTLIN === + +; obj.method() +(navigation_expression + (identifier) @object + (identifier) @method) @qualified-call + +; method() bare call (Kotlin top-level function) +(call_expression + function: (identifier) @method) @simple-call + +; @Annotation (simple) +(annotation + (user_type) @name) @annotation + +; @Annotation(args) +(annotation + (constructor_invocation + (user_type) @name)) @annotation + +;; === PYTHON === + +; obj.method() +(call + function: (attribute + object: (identifier) @object + attribute: (identifier) @method)) @qualified-call + +; method() bare call +(call + function: (identifier) @method) @simple-call + +; @decorator +(decorator + (identifier) @name) @annotation + +; @decorator(args) +(decorator + (attribute + attribute: (identifier) @name)) @annotation + +;; === GO === + +; obj.method() +(call_expression + function: (selector_expression + operand: (identifier) @object + field: (field_identifier) @method)) @qualified-call + +; method() bare call +(call_expression + function: (identifier) @method) @simple-call + +;; === RUST === + +; obj::method() +(call_expression + function: (scoped_identifier + path: (identifier) @object + name: (identifier) @method)) @qualified-call + +; obj.method() +(call_expression + function: (field_expression + value: (identifier) @object + field: (field_identifier) @method)) @qualified-call + +; method() bare call +(call_expression + function: (identifier) @method) @simple-call + +;; === TYPE-SCRIPT / JAVASCRIPT === + +; obj.method() +(call_expression + function: (member_expression + object: (identifier) @object + property: (property_identifier) @method)) @qualified-call + +; method() bare call +(call_expression + function: (identifier) @method) @simple-call + +; new Type() +(new_expression + constructor: (identifier) @name) @constructor + +;; === C / C++ === + +(call_expression + function: (field_expression + argument: (identifier) @object + field: (field_identifier) @method)) @qualified-call + +(call_expression + function: (identifier) @method) @simple-call