diff --git a/bex/queries/community/kotlin_tags.scm b/bex/queries/community/kotlin_tags.scm deleted file mode 100644 index fa12bf6..0000000 --- a/bex/queries/community/kotlin_tags.scm +++ /dev/null @@ -1,43 +0,0 @@ -; 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 deleted file mode 100644 index c758b51..0000000 --- a/bex/queries/community/typescript_highlights.scm +++ /dev/null @@ -1,35 +0,0 @@ -; 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 deleted file mode 100644 index ccae934..0000000 --- a/bex/queries/community/typescript_tags.scm +++ /dev/null @@ -1,23 +0,0 @@ -(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 deleted file mode 100644 index 447c640..0000000 --- a/bex/queries/universal.scm +++ /dev/null @@ -1,132 +0,0 @@ -; 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 diff --git a/bex/tag-preprocessor/__init__.py b/bex/tag-preprocessor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bex/tag-preprocessor/code.py b/bex/tag-preprocessor/code.py new file mode 100644 index 0000000..d192957 --- /dev/null +++ b/bex/tag-preprocessor/code.py @@ -0,0 +1,188 @@ +"""Universal tree-sitter tag preprocessor. + +Usage: + python -m bex.tag-preprocessor.code + +Emits an ordered sequence of behavioral tokens using community highlights.scm +queries from nvim-treesitter. One code path for all languages. +""" + +import importlib +import os +import re +import sys +from pathlib import Path + +from tree_sitter import Language, Parser, Query, QueryCursor + +QUERIES_DIR = Path(__file__).parent / "queries" + +# (query_name, module_name, func_name) +EXTENSION_MAP = { + ".py": ("python", "tree_sitter_python", "language"), + ".js": ("javascript", "tree_sitter_javascript", "language"), + ".mjs": ("javascript", "tree_sitter_javascript", "language"), + ".cjs": ("javascript", "tree_sitter_javascript", "language"), + ".ts": ("typescript", "tree_sitter_typescript", "language_typescript"), + ".tsx": ("typescript", "tree_sitter_typescript", "language_tsx"), + ".rb": ("ruby", "tree_sitter_ruby", "language"), + ".go": ("go", "tree_sitter_go", "language"), + ".rs": ("rust", "tree_sitter_rust", "language"), + ".java": ("java", "tree_sitter_java", "language"), + ".kt": ("kotlin", "tree_sitter_kotlin", "language"), + ".kts": ("kotlin", "tree_sitter_kotlin", "language"), + ".c": ("c", "tree_sitter_c", "language"), + ".h": ("c", "tree_sitter_c", "language"), + ".cpp": ("cpp", "tree_sitter_cpp", "language"), + ".cc": ("cpp", "tree_sitter_cpp", "language"), + ".cxx": ("cpp", "tree_sitter_cpp", "language"), + ".hpp": ("cpp", "tree_sitter_cpp", "language"), +} + +BEHAVIORAL_PREFIXES = ( + "definition.", + "reference.", + "keyword.", + "function", + "attribute", + "constructor", + "label", + "type.definition", + "module", +) + +_grammar_cache = {} +_query_cache = {} + + +def _load_grammar(ext): + entry = EXTENSION_MAP.get(ext) + if entry is None: + raise ValueError(f"Unsupported extension: {ext}") + query_name, module_name, func_name = entry + + cache_key = f"{module_name}.{func_name}" + if cache_key in _grammar_cache: + return _grammar_cache[cache_key], query_name + + mod = importlib.import_module(module_name) + lang = Language(getattr(mod, func_name)()) + _grammar_cache[cache_key] = lang + return lang, query_name + + +INHERIT_RE = re.compile(r"^;\s*inherits:\s*(.+)$", re.MULTILINE) + + +def _resolve_inherits(src, query_name, seen=None): + if seen is None: + seen = set() + if query_name in seen: + return "" + seen.add(query_name) + + qpath = QUERIES_DIR / f"{query_name}.scm" + if not qpath.exists(): + return "" + + content = qpath.read_text() + m = INHERIT_RE.search(content) + if m: + parents = m.group(1) + parent_parts = [] + for parent in parents.split(","): + parent = parent.strip().strip("()") + if parent: + parent_parts.append(_resolve_inherits(parent, parent, seen)) + parent_src = "\n".join(p for p in parent_parts if p) + body = INHERIT_RE.sub("", content) + return parent_src + "\n" + body if parent_src else body + return content + + +def _load_query(query_name): + if query_name in _query_cache: + return _query_cache[query_name] + + src = _resolve_inherits(query_name, query_name) + if not src: + raise FileNotFoundError(f"Query file not found: {query_name}") + + _query_cache[query_name] = src + return src + + +def preprocess(file_path: str, code: str): + ext = os.path.splitext(file_path)[1].lower() + lang, query_name = _load_grammar(ext) + query_src = _load_query(query_name) + + parser = Parser(lang) + tree = parser.parse(code.encode()) + + try: + query = Query(lang, query_src) + except Exception as e: + print(f"Query error for {query_name}: {e}", file=sys.stderr) + return + + cursor = QueryCursor(query) + captures = cursor.captures(tree.root_node) + + items = [] + for capname, nodes in captures.items(): + if not capname.startswith(BEHAVIORAL_PREFIXES): + continue + for node in nodes: + items.append((node.start_byte, capname, node, code[node.start_byte:node.end_byte].strip())) + + items.sort(key=lambda x: x[0]) + + return [(capname, text, code[:start].count("\n") + 1) for start, capname, _, text in items] + + +def main(): + if len(sys.argv) < 2: + print("Usage: python -m bex.tag-preprocessor.code ", file=sys.stderr) + sys.exit(1) + + file_path = sys.argv[1] + + if not os.path.exists(file_path): + print(f"File not found: {file_path}", file=sys.stderr) + sys.exit(1) + + try: + with open(file_path) as f: + code = f.read() + except Exception as e: + print(f"Error reading {file_path}: {e}", file=sys.stderr) + sys.exit(1) + + try: + seq = preprocess(file_path, code) + except ValueError as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1) + except FileNotFoundError as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1) + except Exception as e: + print(f"Error preprocessing {file_path}: {e}", file=sys.stderr) + sys.exit(1) + + if not seq: + print("(no behavioral tokens)") + return + + print(f"{'CAPTURE':35s} {'TEXT':50s} LINE") + print("-" * 88) + for capname, text, line in seq: + print(f"{capname:35s} '{text[:48]:48s}' L{line}") + + print(f"\nSequence ({len(seq)} tokens):") + print(" -> ".join(c for c, _, _ in seq)) + + +if __name__ == "__main__": + main() diff --git a/bex/tag-preprocessor/nvim-reference/c.scm b/bex/tag-preprocessor/nvim-reference/c.scm new file mode 100644 index 0000000..ea65075 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/c.scm @@ -0,0 +1,341 @@ +; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +((identifier) @variable + (#set! priority 95)) + +(preproc_def + (preproc_arg) @variable) + +[ + "default" + "goto" + "asm" + "__asm__" +] @keyword + +[ + "enum" + "struct" + "union" + "typedef" +] @keyword.type + +[ + "sizeof" + "offsetof" +] @keyword.operator + +(alignof_expression + . + _ @keyword.operator) + +"return" @keyword.return + +[ + "while" + "for" + "do" + "continue" + "break" +] @keyword.repeat + +[ + "if" + "else" + "case" + "switch" +] @keyword.conditional + +[ + "#if" + "#ifdef" + "#ifndef" + "#else" + "#elif" + "#endif" + "#elifdef" + "#elifndef" + (preproc_directive) +] @keyword.directive + +"#define" @keyword.directive.define + +"#include" @keyword.import + +[ + ";" + ":" + "," + "." + "::" +] @punctuation.delimiter + +"..." @punctuation.special + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "-" + "*" + "/" + "+" + "%" + "~" + "|" + "&" + "^" + "<<" + ">>" + "->" + "<" + "<=" + ">=" + ">" + "==" + "!=" + "!" + "&&" + "||" + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" + "--" + "++" +] @operator + +; Make sure the comma operator is given a highlight group after the comma +; punctuator so the operator is highlighted properly. +(comma_expression + "," @operator) + +[ + (true) + (false) +] @boolean + +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(string_literal) @string + +(system_lib_string) @string + +(escape_sequence) @string.escape + +(null) @constant.builtin + +(number_literal) @number + +(char_literal) @character + +(preproc_defined) @function.macro + +((field_expression + (field_identifier) @property) @_parent + (#not-has-parent? @_parent template_method function_declarator call_expression)) + +(field_designator) @property + +((field_identifier) @property + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) + +(statement_identifier) @label + +(declaration + type: (type_identifier) @_type + declarator: (identifier) @label + (#eq? @_type "__label__")) + +[ + (type_identifier) + (type_descriptor) +] @type + +(storage_class_specifier) @keyword.modifier + +[ + (type_qualifier) + (gnu_asm_qualifier) + "__extension__" +] @keyword.modifier + +(linkage_specification + "extern" @keyword.modifier) + +(type_definition + declarator: (type_identifier) @type.definition) + +(primitive_type) @type.builtin + +(sized_type_specifier + _ @type.builtin + type: _?) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(preproc_def + (preproc_arg) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(enumerator + name: (identifier) @constant) + +(case_statement + value: (identifier) @constant) + +((identifier) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(preproc_def + (preproc_arg) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(attribute_specifier + (argument_list + (identifier) @variable.builtin)) + +(attribute_specifier + (argument_list + (call_expression + function: (identifier) @variable.builtin))) + +((call_expression + function: (identifier) @function.builtin) + (#lua-match? @function.builtin "^__builtin_")) + +((call_expression + function: (identifier) @function.builtin) + (#has-ancestor? @function.builtin attribute_specifier)) + +; Preproc def / undef +(preproc_def + name: (_) @constant.macro) + +(preproc_call + directive: (preproc_directive) @_u + argument: (_) @constant.macro + (#eq? @_u "#undef")) + +(preproc_ifdef + name: (identifier) @constant.macro) + +(preproc_elifdef + name: (identifier) @constant.macro) + +(preproc_defined + (identifier) @constant.macro) + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +(function_declarator + declarator: (identifier) @function) + +(function_declarator + declarator: (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) + +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +; Parameters +(parameter_declaration + declarator: (identifier) @variable.parameter) + +(parameter_declaration + declarator: (array_declarator) @variable.parameter) + +(parameter_declaration + declarator: (pointer_declarator) @variable.parameter) + +; K&R functions +; To enable support for K&R functions, +; add the following lines to your own query config and uncomment them. +; They are commented out as they'll conflict with C++ +; Note that you'll need to have `; extends` at the top of your query file. +; +; (parameter_list (identifier) @variable.parameter) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (identifier) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (array_declarator) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (pointer_declarator) @variable.parameter)) +(preproc_params + (identifier) @variable.parameter) + +[ + "__attribute__" + "__declspec" + "__based" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + (ms_pointer_modifier) + (attribute_declaration) +] @attribute diff --git a/bex/tag-preprocessor/nvim-reference/cpp.scm b/bex/tag-preprocessor/nvim-reference/cpp.scm new file mode 100644 index 0000000..85ff2dc --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/cpp.scm @@ -0,0 +1,268 @@ +; inherits: c + +((identifier) @variable.member + (#lua-match? @variable.member "^m_.*$")) + +(parameter_declaration + declarator: (reference_declarator) @variable.parameter) + +; function(Foo ...foo) +(variadic_parameter_declaration + declarator: (variadic_declarator + (_) @variable.parameter)) + +; int foo = 0 +(optional_parameter_declaration + declarator: (_) @variable.parameter) + +;(field_expression) @variable.parameter ;; How to highlight this? +((field_expression + (field_identifier) @function.method) @_parent + (#has-parent? @_parent template_method function_declarator)) + +(field_declaration + (field_identifier) @variable.member) + +(field_initializer + (field_identifier) @property) + +(function_declarator + declarator: (field_identifier) @function.method) + +(concept_definition + name: (identifier) @type.definition) + +(alias_declaration + name: (type_identifier) @type.definition) + +(auto) @type.builtin + +(namespace_identifier) @module + +((namespace_identifier) @type + (#lua-match? @type "^[%u]")) + +(case_statement + value: (qualified_identifier + (identifier) @constant)) + +(using_declaration + . + "using" + . + "namespace" + . + [ + (qualified_identifier) + (identifier) + ] @module) + +(destructor_name + (identifier) @function.method) + +; functions +(function_declarator + (qualified_identifier + (identifier) @function)) + +(function_declarator + (qualified_identifier + (qualified_identifier + (identifier) @function))) + +(function_declarator + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function)))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function)))) @_parent + (#has-ancestor? @_parent function_declarator)) + +(function_declarator + (template_function + (identifier) @function)) + +(operator_name) @function + +"operator" @function + +"static_assert" @function.builtin + +(call_expression + (qualified_identifier + (identifier) @function.call)) + +(call_expression + (qualified_identifier + (qualified_identifier + (identifier) @function.call))) + +(call_expression + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function.call)))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function.call)))) @_parent + (#has-ancestor? @_parent call_expression)) + +(call_expression + (template_function + (identifier) @function.call)) + +(call_expression + (qualified_identifier + (template_function + (identifier) @function.call))) + +(call_expression + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call)))) + +(call_expression + (qualified_identifier + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call))))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call))))) @_parent + (#has-ancestor? @_parent call_expression)) + +; methods +(function_declarator + (template_method + (field_identifier) @function.method)) + +(call_expression + (field_expression + (field_identifier) @function.method.call)) + +; constructors +((function_declarator + (qualified_identifier + (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (qualified_identifier + name: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (field_expression + field: (field_identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +; constructing a type in an initializer list: Constructor (): **SuperType (1)** +((field_initializer + (field_identifier) @constructor + (argument_list)) + (#lua-match? @constructor "^%u")) + +; Constants +(this) @variable.builtin + +(null + "nullptr" @constant.builtin) + +(true) @boolean + +(false) @boolean + +; Literals +(raw_string_literal) @string + +; Keywords +[ + "try" + "catch" + "noexcept" + "throw" +] @keyword.exception + +[ + "decltype" + "explicit" + "friend" + "override" + "using" + "requires" + "constexpr" +] @keyword + +[ + "class" + "namespace" + "template" + "typename" + "concept" +] @keyword.type + +[ + "co_await" + "co_yield" + "co_return" +] @keyword.coroutine + +[ + "public" + "private" + "protected" + "final" + "virtual" +] @keyword.modifier + +[ + "new" + "delete" + "xor" + "bitand" + "bitor" + "compl" + "not" + "xor_eq" + "and_eq" + "or_eq" + "not_eq" + "and" + "or" +] @keyword.operator + +"<=>" @operator + +"::" @punctuation.delimiter + +(template_argument_list + [ + "<" + ">" + ] @punctuation.bracket) + +(template_parameter_list + [ + "<" + ">" + ] @punctuation.bracket) + +(literal_suffix) @operator diff --git a/bex/tag-preprocessor/nvim-reference/go.scm b/bex/tag-preprocessor/nvim-reference/go.scm new file mode 100644 index 0000000..7675cb7 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/go.scm @@ -0,0 +1,254 @@ +; Forked from tree-sitter-go +; Copyright (c) 2014 Max Brunsfeld (The MIT License) +; +; Identifiers +(type_identifier) @type + +(type_spec + name: (type_identifier) @type.definition) + +(field_identifier) @property + +(identifier) @variable + +(package_identifier) @module + +(parameter_declaration + (identifier) @variable.parameter) + +(variadic_parameter_declaration + (identifier) @variable.parameter) + +(label_name) @label + +(const_spec + name: (identifier) @constant) + +; Function calls +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (selector_expression + field: (field_identifier) @function.method.call)) + +; Function definitions +(function_declaration + name: (identifier) @function) + +(method_declaration + name: (field_identifier) @function.method) + +(method_elem + name: (field_identifier) @function.method) + +; Constructors +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[nN]ew.+$")) + +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[mM]ake.+$")) + +; Operators +[ + "--" + "-" + "-=" + ":=" + "!" + "!=" + "..." + "*" + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "&^" + "&^=" + "%" + "%=" + "^" + "^=" + "+" + "++" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" +] @operator + +; Keywords +[ + "break" + "const" + "continue" + "default" + "defer" + "goto" + "range" + "select" + "var" + "fallthrough" +] @keyword + +[ + "type" + "struct" + "interface" +] @keyword.type + +"func" @keyword.function + +"return" @keyword.return + +"go" @keyword.coroutine + +"for" @keyword.repeat + +[ + "import" + "package" +] @keyword.import + +[ + "else" + "case" + "switch" + "if" +] @keyword.conditional + +; Builtin types +[ + "chan" + "map" +] @type.builtin + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "any" "bool" "byte" "comparable" "complex128" "complex64" "error" "float32" "float64" "int" + "int16" "int32" "int64" "int8" "rune" "string" "uint" "uint16" "uint32" "uint64" "uint8" + "uintptr")) + +; Builtin functions +((identifier) @function.builtin + (#any-of? @function.builtin + "append" "cap" "clear" "close" "complex" "copy" "delete" "imag" "len" "make" "max" "min" "new" + "panic" "print" "println" "real" "recover")) + +; Delimiters +"." @punctuation.delimiter + +"," @punctuation.delimiter + +":" @punctuation.delimiter + +";" @punctuation.delimiter + +"(" @punctuation.bracket + +")" @punctuation.bracket + +"{" @punctuation.bracket + +"}" @punctuation.bracket + +"[" @punctuation.bracket + +"]" @punctuation.bracket + +; Literals +(interpreted_string_literal) @string + +(raw_string_literal) @string + +(rune_literal) @string + +(escape_sequence) @string.escape + +(int_literal) @number + +(float_literal) @number.float + +(imaginary_literal) @number + +[ + (true) + (false) +] @boolean + +[ + (nil) + (iota) +] @constant.builtin + +(keyed_element + . + (literal_element + (identifier) @variable.member)) + +(field_declaration + name: (field_identifier) @variable.member) + +; Comments +(comment) @comment @spell + +; Doc Comments +(source_file + . + (comment)+ @comment.documentation) + +(source_file + (comment)+ @comment.documentation + . + (const_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (function_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (type_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (var_declaration)) + +; Spell +((interpreted_string_literal) @spell + (#not-has-parent? @spell import_spec)) + +; Regex +(call_expression + (selector_expression) @_function + (#any-of? @_function + "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" + "regexp.MustCompile" "regexp.MustCompilePOSIX") + (argument_list + . + [ + (raw_string_literal + (raw_string_literal_content) @string.regexp) + (interpreted_string_literal + (interpreted_string_literal_content) @string.regexp) + ])) diff --git a/bex/tag-preprocessor/nvim-reference/java.scm b/bex/tag-preprocessor/nvim-reference/java.scm new file mode 100644 index 0000000..df9ca14 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/java.scm @@ -0,0 +1,330 @@ +; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com) +; Variables +(identifier) @variable + +(underscore_pattern) @character.special + +; Methods +(method_declaration + name: (identifier) @function.method) + +(method_invocation + name: (identifier) @function.method.call) + +(super) @function.builtin + +; Parameters +(formal_parameter + name: (identifier) @variable.parameter) + +(spread_parameter + (variable_declarator + name: (identifier) @variable.parameter)) ; int... foo + +; Lambda parameter +(inferred_parameters + (identifier) @variable.parameter) ; (x,y) -> ... + +(lambda_expression + parameters: (identifier) @variable.parameter) ; x -> ... + +; Operators +[ + "+" + ":" + "++" + "-" + "--" + "&" + "&&" + "|" + "||" + "!" + "!=" + "==" + "*" + "/" + "%" + "<" + "<=" + ">" + ">=" + "=" + "-=" + "+=" + "*=" + "/=" + "%=" + "->" + "^" + "^=" + "&=" + "|=" + "~" + ">>" + ">>>" + "<<" + "::" +] @operator + +; Types +(interface_declaration + name: (identifier) @type) + +(annotation_type_declaration + name: (identifier) @type) + +(class_declaration + name: (identifier) @type) + +(record_declaration + name: (identifier) @type) + +(enum_declaration + name: (identifier) @type) + +(constructor_declaration + name: (identifier) @type) + +(compact_constructor_declaration + name: (identifier) @type) + +(type_identifier) @type + +((type_identifier) @type.builtin + (#eq? @type.builtin "var")) + +((method_invocation + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((method_reference + . + (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((field_access + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +(scoped_identifier + (identifier) @type + (#lua-match? @type "^[A-Z]")) + +; Fields +(field_declaration + declarator: (variable_declarator + name: (identifier) @variable.member)) + +(field_access + field: (identifier) @variable.member) + +[ + (boolean_type) + (integral_type) + (floating_point_type) + (void_type) +] @type.builtin + +; Variables +((identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z%d_]+$")) + +(this) @variable.builtin + +; Annotations +(annotation + "@" @attribute + name: (identifier) @attribute) + +(marker_annotation + "@" @attribute + name: (identifier) @attribute) + +; Literals +(string_literal) @string + +(escape_sequence) @string.escape + +(character_literal) @character + +[ + (hex_integer_literal) + (decimal_integer_literal) + (octal_integer_literal) + (binary_integer_literal) +] @number + +[ + (decimal_floating_point_literal) + (hex_floating_point_literal) +] @number.float + +[ + (true) + (false) +] @boolean + +(null_literal) @constant.builtin + +; Keywords +[ + "assert" + "default" + "extends" + "implements" + "instanceof" + "@interface" + "permits" + "to" + "with" +] @keyword + +[ + "record" + "class" + "enum" + "interface" +] @keyword.type + +(synchronized_statement + "synchronized" @keyword) + +[ + "abstract" + "final" + "native" + "non-sealed" + "open" + "private" + "protected" + "public" + "sealed" + "static" + "strictfp" + "transitive" +] @keyword.modifier + +(modifiers + "synchronized" @keyword.modifier) + +[ + "transient" + "volatile" +] @keyword.modifier + +[ + "return" + "yield" +] @keyword.return + +"new" @keyword.operator + +; Conditionals +[ + "if" + "else" + "switch" + "case" + "when" +] @keyword.conditional + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +; Loops +[ + "for" + "while" + "do" + "continue" + "break" +] @keyword.repeat + +; Includes +[ + "exports" + "import" + "module" + "opens" + "package" + "provides" + "requires" + "uses" +] @keyword.import + +(import_declaration + (asterisk + "*" @character.special)) + +; Punctuation +[ + ";" + "." + "..." + "," +] @punctuation.delimiter + +[ + "{" + "}" +] @punctuation.bracket + +[ + "[" + "]" +] @punctuation.bracket + +[ + "(" + ")" +] @punctuation.bracket + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(string_interpolation + [ + "\\{" + "}" + ] @punctuation.special) + +; Exceptions +[ + "throw" + "throws" + "finally" + "try" + "catch" +] @keyword.exception + +; Labels +(labeled_statement + (identifier) @label) + +; Comments +[ + (line_comment) + (block_comment) +] @comment @spell + +((block_comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +((line_comment) @comment.documentation + (#lua-match? @comment.documentation "^///[^/]")) + +((line_comment) @comment.documentation + (#lua-match? @comment.documentation "^///$")) diff --git a/bex/tag-preprocessor/nvim-reference/javascript.scm b/bex/tag-preprocessor/nvim-reference/javascript.scm new file mode 100644 index 0000000..257a731 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/javascript.scm @@ -0,0 +1,56 @@ +; inherits: ecma,jsx + +; Parameters +(formal_parameters + (identifier) @variable.parameter) + +(formal_parameters + (rest_pattern + (identifier) @variable.parameter)) + +; ({ a }) => null +(formal_parameters + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a = b }) => null +(formal_parameters + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a: b }) => null +(formal_parameters + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ a ]) => null +(formal_parameters + (array_pattern + (identifier) @variable.parameter)) + +; ({ a } = { a }) => null +(formal_parameters + (assignment_pattern + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a = b } = { a }) => null +(formal_parameters + (assignment_pattern + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter)))) + +; a => null +(arrow_function + parameter: (identifier) @variable.parameter) + +; optional parameters +(formal_parameters + (assignment_pattern + left: (identifier) @variable.parameter)) + +; punctuation +(optional_chain) @punctuation.delimiter diff --git a/bex/tag-preprocessor/nvim-reference/kotlin.scm b/bex/tag-preprocessor/nvim-reference/kotlin.scm new file mode 100644 index 0000000..8eda6ef --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/kotlin.scm @@ -0,0 +1,398 @@ +; 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" + "super" + "this@" + "super@" +] @variable.builtin + +; NOTE: for consistency with "super@" +(super_expression + "@" @variable.builtin) + +(class_parameter + (simple_identifier) @variable.member) + +; NOTE: temporary fix for treesitter bug that causes delay in file opening +;(class_body +; (property_declaration +; (variable_declaration +; (simple_identifier) @variable.member))) +; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties +(_ + (navigation_suffix + (simple_identifier) @variable.member)) + +; SCREAMING CASE identifiers are assumed to be constants +((simple_identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]*$")) + +(_ + (navigation_suffix + (simple_identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]*$"))) + +(enum_entry + (simple_identifier) @constant) + +(type_identifier) @type + +; '?' operator, replacement for Java @Nullable +(nullable_type) @punctuation.special + +(type_alias + (type_identifier) @type.definition) + +((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 + "package" @keyword + . + (identifier + (simple_identifier) @module)) + +(import_header + "import" @keyword.import) + +(wildcard_import) @character.special + +; The last `simple_identifier` in a `import_header` will always either be a function +; or a type. Classes can appear anywhere in the import path, unlike functions +(import_header + (identifier + (simple_identifier) @type @_import) + (import_alias + (type_identifier) @type.definition)? + (#lua-match? @_import "^[A-Z]")) + +(import_header + (identifier + (simple_identifier) @function @_import .) + (import_alias + (type_identifier) @function)? + (#lua-match? @_import "^[a-z]")) + +(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) @variable.parameter) + +(parameter_with_optional_type + (simple_identifier) @variable.parameter) + +; lambda parameters +(lambda_literal + (lambda_parameters + (variable_declaration + (simple_identifier) @variable.parameter))) + +; Function calls +; function() +(call_expression + . + (simple_identifier) @function.call) + +; ::function +(callable_reference + . + (simple_identifier) @function.call) + +; object.function() or object.property.function() +(call_expression + (navigation_expression + (navigation_suffix + (simple_identifier) @function.call) .)) + +(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" "suspend" "synchronized")) + +; Literals +[ + (line_comment) + (multiline_comment) +] @comment @spell + +((multiline_comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +(shebang_line) @keyword.directive + +(real_literal) @number.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 + +; NOTE: Escapes not allowed in multi-line strings +(character_literal + (character_escape_seq) @string.escape) + +; There are 3 ways to define a regex +; - "[abc]?".toRegex() +(call_expression + (navigation_expression + (string_literal) @string.regexp + (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.regexp)))) + +; - 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.regexp)))) + +; Keywords +(type_alias + "typealias" @keyword) + +(companion_object + "companion" @keyword) + +[ + (class_modifier) + (member_modifier) + (function_modifier) + (property_modifier) + (platform_modifier) + (variance_modifier) + (parameter_modifier) + (visibility_modifier) + (reification_modifier) + (inheritance_modifier) +] @keyword.modifier + +[ + "val" + "var" + ; "typeof" ; NOTE: It is reserved for future use +] @keyword + +[ + "enum" + "class" + "object" + "interface" +] @keyword.type + +[ + "return" + "return@" +] @keyword.return + +"suspend" @keyword.coroutine + +"fun" @keyword.function + +[ + "if" + "else" + "when" +] @keyword.conditional + +[ + "for" + "do" + "while" + "continue" + "continue@" + "break" + "break@" +] @keyword.repeat + +[ + "try" + "catch" + "throw" + "finally" +] @keyword.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" + "!is" + "in" + "!in" + "as" + "as?" + ".." + "->" +] @operator + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "." + "," + ";" + ":" + "::" +] @punctuation.delimiter + +(super_expression + [ + "<" + ">" + ] @punctuation.delimiter) + +(type_arguments + [ + "<" + ">" + ] @punctuation.delimiter) + +(type_parameters + [ + "<" + ">" + ] @punctuation.delimiter) + +; NOTE: `interpolated_identifier`s can be highlighted in any way +(string_literal + "$" @punctuation.special + (interpolated_identifier) @none @variable) + +(string_literal + "${" @punctuation.special + (interpolated_expression) @none + "}" @punctuation.special) diff --git a/bex/tag-preprocessor/nvim-reference/python.scm b/bex/tag-preprocessor/nvim-reference/python.scm new file mode 100644 index 0000000..00250de --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/python.scm @@ -0,0 +1,443 @@ +; From tree-sitter-python licensed under MIT License +; Copyright (c) 2016 Max Brunsfeld +; Variables +(identifier) @variable + +; Reset highlighting in f-string interpolations +(interpolation) @none + +; Identifier naming conventions +((identifier) @type + (#lua-match? @type "^[A-Z].*[a-z]")) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +((identifier) @constant.builtin + (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + ; https://docs.python.org/3/library/constants.html + "NotImplemented" "Ellipsis" "quit" "exit" "copyright" "credits" "license")) + +"_" @character.special ; match wildcard + +((assignment + left: (identifier) @type.definition + (type + (identifier) @_annotation)) + (#eq? @_annotation "TypeAlias")) + +((assignment + left: (identifier) @type.definition + right: (call + function: (identifier) @_func)) + (#any-of? @_func "TypeVar" "NewType")) + +; Function definitions +(function_definition + name: (identifier) @function) + +(type + (identifier) @type) + +(type + (subscript + (identifier) @type)) ; type subscript: Tuple[int] + +((call + function: (identifier) @_isinstance + arguments: (argument_list + (_) + (identifier) @type)) + (#eq? @_isinstance "isinstance")) + +; Literals +(none) @constant.builtin + +[ + (true) + (false) +] @boolean + +(integer) @number + +(float) @number.float + +(comment) @comment @spell + +((module + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#!/")) + +(string) @string + +[ + (escape_sequence) + (escape_interpolation) +] @string.escape + +; doc-strings +(expression_statement + (string + (string_content) @spell) @string.documentation) + +; Tokens +[ + "-" + "-=" + ":=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "@" + "@=" + "|" + "|=" + "~" + "->" +] @operator + +; Keywords +[ + "and" + "in" + "is" + "not" + "or" + "is not" + "not in" + "del" +] @keyword.operator + +[ + "def" + "lambda" +] @keyword.function + +[ + "assert" + "exec" + "global" + "nonlocal" + "pass" + "print" + "with" + "as" +] @keyword + +[ + "type" + "class" +] @keyword.type + +[ + "async" + "await" +] @keyword.coroutine + +[ + "return" + "yield" +] @keyword.return + +(yield + "from" @keyword.return) + +(future_import_statement + "from" @keyword.import + "__future__" @module.builtin) + +(import_from_statement + "from" @keyword.import) + +"import" @keyword.import + +(aliased_import + "as" @keyword.import) + +(wildcard_import + "*" @character.special) + +(import_statement + name: (dotted_name + (identifier) @module)) + +(import_statement + name: (aliased_import + name: (dotted_name + (identifier) @module) + alias: (identifier) @module)) + +(import_from_statement + module_name: (dotted_name + (identifier) @module)) + +(import_from_statement + module_name: (relative_import + (dotted_name + (identifier) @module))) + +[ + "if" + "elif" + "else" + "match" + "case" +] @keyword.conditional + +[ + "for" + "while" + "break" + "continue" +] @keyword.repeat + +[ + "try" + "except" + "except*" + "raise" + "finally" +] @keyword.exception + +(raise_statement + "from" @keyword.exception) + +(try_statement + (else_clause + "else" @keyword.exception)) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) + +(type_conversion) @function.macro + +[ + "," + "." + ":" + ";" + (ellipsis) +] @punctuation.delimiter + +((identifier) @type.builtin + (#any-of? @type.builtin + ; https://docs.python.org/3/library/exceptions.html + "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" + "AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" + "ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError" + "NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError" + "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError" + "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" + "UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" + "IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError" + "BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError" + "FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError" + "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" + "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" + "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning" + ; https://docs.python.org/3/library/stdtypes.html + "bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" + "set" "frozenset" "dict" "type" "object")) + +; Normal parameters +(parameters + (identifier) @variable.parameter) + +; Lambda parameters +(lambda_parameters + (identifier) @variable.parameter) + +(lambda_parameters + (tuple_pattern + (identifier) @variable.parameter)) + +; Default parameters +(keyword_argument + name: (identifier) @variable.parameter) + +; Naming parameters on call-site +(default_parameter + name: (identifier) @variable.parameter) + +(typed_parameter + (identifier) @variable.parameter) + +(typed_default_parameter + name: (identifier) @variable.parameter) + +; Variadic parameters *args, **kwargs +(parameters + (list_splat_pattern ; *args + (identifier) @variable.parameter)) + +(parameters + (dictionary_splat_pattern ; **kwargs + (identifier) @variable.parameter)) + +; Typed variadic parameters +(parameters + (typed_parameter + (list_splat_pattern ; *args: type + (identifier) @variable.parameter))) + +(parameters + (typed_parameter + (dictionary_splat_pattern ; *kwargs: type + (identifier) @variable.parameter))) + +; Lambda parameters +(lambda_parameters + (list_splat_pattern + (identifier) @variable.parameter)) + +(lambda_parameters + (dictionary_splat_pattern + (identifier) @variable.parameter)) + +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +((identifier) @variable.builtin + (#eq? @variable.builtin "cls")) + +; After @type.builtin bacause builtins (such as `type`) are valid as attribute name +((attribute + attribute: (identifier) @variable.member) + (#lua-match? @variable.member "^[%l_].*$")) + +; Class definitions +(class_definition + name: (identifier) @type) + +(class_definition + body: (block + (function_definition + name: (identifier) @function.method))) + +(class_definition + superclasses: (argument_list + (identifier) @type)) + +((class_definition + body: (block + (expression_statement + (assignment + left: (identifier) @variable.member)))) + (#lua-match? @variable.member "^[%l_].*$")) + +((class_definition + body: (block + (expression_statement + (assignment + left: (_ + (identifier) @variable.member))))) + (#lua-match? @variable.member "^[%l_].*$")) + +((class_definition + (block + (function_definition + name: (identifier) @constructor))) + (#any-of? @constructor "__new__" "__init__")) + +; Function calls +(call + function: (identifier) @function.call) + +(call + function: (attribute + attribute: (identifier) @function.method.call)) + +((call + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +((call + function: (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +; Builtin functions +((call + function: (identifier) @function.builtin) + (#any-of? @function.builtin + "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" + "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" + "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" + "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" + "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" + "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" + "vars" "zip" "__import__")) + +; Regex from the `re` module +(call + function: (attribute + object: (identifier) @_re) + arguments: (argument_list + . + (string + (string_content) @string.regexp)) + (#eq? @_re "re")) + +; Decorators +((decorator + "@" @attribute) + (#set! priority 101)) + +(decorator + (identifier) @attribute) + +(decorator + (attribute + attribute: (identifier) @attribute)) + +(decorator + (call + (identifier) @attribute)) + +(decorator + (call + (attribute + attribute: (identifier) @attribute))) + +((decorator + (identifier) @attribute.builtin) + (#any-of? @attribute.builtin "classmethod" "property" "staticmethod")) diff --git a/bex/tag-preprocessor/nvim-reference/ruby.scm b/bex/tag-preprocessor/nvim-reference/ruby.scm new file mode 100644 index 0000000..8de0251 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/ruby.scm @@ -0,0 +1,309 @@ +; Variables +[ + (identifier) + (global_variable) +] @variable + +; Keywords +[ + "alias" + "begin" + "do" + "end" + "ensure" + "module" + "rescue" + "then" +] @keyword + +"class" @keyword.type + +[ + "return" + "yield" +] @keyword.return + +[ + "and" + "or" + "in" + "not" +] @keyword.operator + +[ + "def" + "undef" +] @keyword.function + +(method + "end" @keyword.function) + +[ + "case" + "else" + "elsif" + "if" + "unless" + "when" + "then" +] @keyword.conditional + +(if + "end" @keyword.conditional) + +[ + "for" + "until" + "while" + "break" + "redo" + "retry" + "next" +] @keyword.repeat + +(constant) @constant + +((identifier) @keyword.modifier + (#any-of? @keyword.modifier "private" "protected" "public")) + +[ + "rescue" + "ensure" +] @keyword.exception + +; Function calls +"defined?" @function + +(call + receiver: (constant)? @type + method: [ + (identifier) + (constant) + ] @function.call) + +(program + (call + (identifier) @keyword.import) + (#any-of? @keyword.import "require" "require_relative" "load")) + +; Function definitions +(alias + (identifier) @function) + +(setter + (identifier) @function) + +(method + name: [ + (identifier) @function + (constant) @type + ]) + +(singleton_method + name: [ + (identifier) @function + (constant) @type + ]) + +(class + name: (constant) @type) + +(module + name: (constant) @type) + +(superclass + (constant) @type) + +; Identifiers +[ + (class_variable) + (instance_variable) +] @variable.member + +((identifier) @constant.builtin + (#any-of? @constant.builtin + "__callee__" "__dir__" "__id__" "__method__" "__send__" "__ENCODING__" "__FILE__" "__LINE__")) + +((identifier) @function.builtin + (#any-of? @function.builtin "attr_reader" "attr_writer" "attr_accessor" "module_function")) + +((call + !receiver + method: (identifier) @function.builtin) + (#any-of? @function.builtin "include" "extend" "prepend" "refine" "using")) + +((identifier) @keyword.exception + (#any-of? @keyword.exception "raise" "fail" "catch" "throw")) + +((constant) @type + (#not-lua-match? @type "^[A-Z0-9_]+$")) + +[ + (self) + (super) +] @variable.builtin + +(method_parameters + (identifier) @variable.parameter) + +(lambda_parameters + (identifier) @variable.parameter) + +(block_parameters + (identifier) @variable.parameter) + +(splat_parameter + (identifier) @variable.parameter) + +(hash_splat_parameter + (identifier) @variable.parameter) + +(optional_parameter + (identifier) @variable.parameter) + +(destructured_parameter + (identifier) @variable.parameter) + +(block_parameter + (identifier) @variable.parameter) + +(keyword_parameter + (identifier) @variable.parameter) + +; TODO: Re-enable this once it is supported +; ((identifier) @function +; (#is-not? local)) +; Literals +[ + (string_content) + (heredoc_content) + "\"" + "`" +] @string + +[ + (heredoc_beginning) + (heredoc_end) +] @label + +[ + (bare_symbol) + (simple_symbol) + (delimited_symbol) + (hash_key_symbol) +] @string.special.symbol + +(regex + (string_content) @string.regexp) + +(escape_sequence) @string.escape + +(integer) @number + +(float) @number.float + +[ + (true) + (false) +] @boolean + +(nil) @constant.builtin + +(comment) @comment @spell + +((program + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#!/")) + +(program + (comment)+ @comment.documentation + (class)) + +(module + (comment)+ @comment.documentation + (body_statement + (class))) + +(class + (comment)+ @comment.documentation + (body_statement + (method))) + +(body_statement + (comment)+ @comment.documentation + (method)) + +; Operators +[ + "!" + "=" + "==" + "===" + "<=>" + "=>" + "->" + ">>" + "<<" + ">" + "<" + ">=" + "<=" + "**" + "*" + "/" + "%" + "+" + "-" + "&" + "|" + "^" + "&&" + "||" + "||=" + "&&=" + "!=" + "%=" + "+=" + "-=" + "*=" + "/=" + "=~" + "!~" + "?" + ":" + ".." + "..." +] @operator + +[ + "," + ";" + "." + "&." + "::" +] @punctuation.delimiter + +(regex + "/" @punctuation.bracket) + +(pair + ":" @punctuation.delimiter) + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "%w(" + "%i(" +] @punctuation.bracket + +(block_parameters + "|" @punctuation.bracket) + +(interpolation + "#{" @punctuation.special + "}" @punctuation.special) diff --git a/bex/tag-preprocessor/nvim-reference/rust.scm b/bex/tag-preprocessor/nvim-reference/rust.scm new file mode 100644 index 0000000..de9d096 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/rust.scm @@ -0,0 +1,531 @@ +; Forked from https://github.com/tree-sitter/tree-sitter-rust +; Copyright (c) 2017 Maxim Sokolov +; Licensed under the MIT license. +; Identifier conventions +(shebang) @keyword.directive + +(identifier) @variable + +((identifier) @type + (#lua-match? @type "^[A-Z]")) + +(const_item + name: (identifier) @constant) + +; Assume all-caps names are constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +; Other identifiers +(type_identifier) @type + +(primitive_type) @type.builtin + +(field_identifier) @variable.member + +(shorthand_field_identifier) @variable.member + +(shorthand_field_initializer + (identifier) @variable.member) + +(mod_item + name: (identifier) @module) + +(self) @variable.builtin + +"_" @character.special + +(label + [ + "'" + (identifier) + ] @label) + +; Function definitions +(function_item + (identifier) @function) + +(function_signature_item + (identifier) @function) + +(parameter + [ + (identifier) + "_" + ] @variable.parameter) + +(parameter + (ref_pattern + [ + (mut_pattern + (identifier) @variable.parameter) + (identifier) @variable.parameter + ])) + +(closure_parameters + (_) @variable.parameter) + +; Function calls +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (scoped_identifier + (identifier) @function.call .)) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +(generic_function + function: (identifier) @function.call) + +(generic_function + function: (scoped_identifier + name: (identifier) @function.call)) + +(generic_function + function: (field_expression + field: (field_identifier) @function.call)) + +; Assume other uppercase names are enum constructors +((field_identifier) @constant + (#lua-match? @constant "^[A-Z]")) + +(enum_variant + name: (identifier) @constant) + +; Assume that uppercase names in paths are types +(scoped_identifier + path: (identifier) @module) + +(scoped_identifier + (scoped_identifier + name: (identifier) @module)) + +(scoped_type_identifier + path: (identifier) @module) + +(scoped_type_identifier + path: (identifier) @type + (#lua-match? @type "^[A-Z]")) + +(scoped_type_identifier + (scoped_identifier + name: (identifier) @module)) + +((scoped_identifier + path: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +((scoped_identifier + path: (identifier) @type + name: (identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +((scoped_type_identifier + path: (identifier) @type + name: (type_identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +[ + (crate) + (super) +] @module + +(scoped_use_list + path: (identifier) @module) + +(scoped_use_list + path: (scoped_identifier + (identifier) @module)) + +(use_list + (scoped_identifier + (identifier) @module + . + (_))) + +(use_list + (identifier) @type + (#lua-match? @type "^[A-Z]")) + +(use_as_clause + alias: (identifier) @type + (#lua-match? @type "^[A-Z]")) + +; Correct enum constructors +(call_expression + function: (scoped_identifier + "::" + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z]")) + +; Assume uppercase names in a match arm are constants. +((match_arm + pattern: (match_pattern + (identifier) @constant)) + (#lua-match? @constant "^[A-Z]")) + +((match_arm + pattern: (match_pattern + (scoped_identifier + name: (identifier) @constant))) + (#lua-match? @constant "^[A-Z]")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin "Some" "None" "Ok" "Err")) + +; Macro definitions +"$" @function.macro + +(metavariable) @function.macro + +(macro_definition + "macro_rules!" @function.macro) + +; Attribute macros +(attribute_item + (attribute + (identifier) @function.macro)) + +(inner_attribute_item + (attribute + (identifier) @function.macro)) + +(attribute + (scoped_identifier + (identifier) @function.macro .)) + +; Derive macros (assume all arguments are types) +; (attribute +; (identifier) @_name +; arguments: (attribute (attribute (identifier) @type)) +; (#eq? @_name "derive")) +; Function-like macros +(macro_invocation + macro: (identifier) @function.macro) + +(macro_invocation + macro: (scoped_identifier + (identifier) @function.macro .)) + +; Literals +(boolean_literal) @boolean + +(integer_literal) @number + +(float_literal) @number.float + +[ + (raw_string_literal) + (string_literal) +] @string + +(escape_sequence) @string.escape + +(char_literal) @character + +; Keywords +[ + "use" + "mod" +] @keyword.import + +(use_as_clause + "as" @keyword.import) + +[ + "default" + "impl" + "let" + "move" + "unsafe" + "where" +] @keyword + +[ + "enum" + "struct" + "union" + "trait" + "type" +] @keyword.type + +[ + "async" + "await" + "gen" +] @keyword.coroutine + +"try" @keyword.exception + +[ + "ref" + "pub" + "raw" + (mutable_specifier) + "const" + "static" + "dyn" + "extern" +] @keyword.modifier + +(lifetime + "'" @keyword.modifier) + +(lifetime + (identifier) @attribute) + +(lifetime + (identifier) @attribute.builtin + (#any-of? @attribute.builtin "static" "_")) + +"fn" @keyword.function + +[ + "return" + "yield" +] @keyword.return + +(type_cast_expression + "as" @keyword.operator) + +(qualified_type + "as" @keyword.operator) + +(use_list + (self) @module) + +(scoped_use_list + (self) @module) + +(scoped_identifier + [ + (crate) + (super) + (self) + ] @module) + +(visibility_modifier + [ + (crate) + (super) + (self) + ] @module) + +[ + "if" + "else" + "match" +] @keyword.conditional + +[ + "break" + "continue" + "in" + "loop" + "while" +] @keyword.repeat + +"for" @keyword + +(for_expression + "for" @keyword.repeat) + +; Operators +[ + "!" + "!=" + "%" + "%=" + "&" + "&&" + "&=" + "*" + "*=" + "+" + "+=" + "-" + "-=" + ".." + "..=" + "..." + "/" + "/=" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "?" + "@" + "^" + "^=" + "|" + "|=" + "||" +] @operator + +(use_wildcard + "*" @character.special) + +(remaining_field_pattern + ".." @character.special) + +(range_pattern + [ + ".." + "..=" + "..." + ] @character.special) + +; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(closure_parameters + "|" @punctuation.bracket) + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(bracketed_type + [ + "<" + ">" + ] @punctuation.bracket) + +(for_lifetimes + [ + "<" + ">" + ] @punctuation.bracket) + +[ + "," + "." + ":" + "::" + ";" + "->" + "=>" +] @punctuation.delimiter + +(attribute_item + "#" @punctuation.special) + +(inner_attribute_item + [ + "!" + "#" + ] @punctuation.special) + +(macro_invocation + "!" @function.macro) + +(never_type + "!" @type.builtin) + +(macro_invocation + macro: (identifier) @_identifier @keyword.exception + "!" @keyword.exception + (#eq? @_identifier "panic")) + +(macro_invocation + macro: (identifier) @_identifier @keyword.exception + "!" @keyword.exception + (#contains? @_identifier "assert")) + +(macro_invocation + macro: (identifier) @_identifier @keyword.debug + "!" @keyword.debug + (#eq? @_identifier "dbg")) + +; Comments +[ + (line_comment) + (block_comment) + (outer_doc_comment_marker) + (inner_doc_comment_marker) +] @comment @spell + +(line_comment + (doc_comment)) @comment.documentation + +(block_comment + (doc_comment)) @comment.documentation + +(call_expression + function: (scoped_identifier + path: (identifier) @_regex + (#any-of? @_regex "Regex" "ByteRegexBuilder") + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal + (string_content) @string.regexp))) + +(call_expression + function: (scoped_identifier + path: (scoped_identifier + (identifier) @_regex + (#any-of? @_regex "Regex" "ByteRegexBuilder") .) + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal + (string_content) @string.regexp))) + +(call_expression + function: (scoped_identifier + path: (identifier) @_regex + (#any-of? @_regex "RegexSet" "RegexSetBuilder") + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (array_expression + (raw_string_literal + (string_content) @string.regexp)))) + +(call_expression + function: (scoped_identifier + path: (scoped_identifier + (identifier) @_regex + (#any-of? @_regex "RegexSet" "RegexSetBuilder") .) + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (array_expression + (raw_string_literal + (string_content) @string.regexp)))) diff --git a/bex/tag-preprocessor/nvim-reference/typescript.scm b/bex/tag-preprocessor/nvim-reference/typescript.scm new file mode 100644 index 0000000..2fb13d8 --- /dev/null +++ b/bex/tag-preprocessor/nvim-reference/typescript.scm @@ -0,0 +1,208 @@ +; inherits: ecma + +"require" @keyword.import + +(import_require_clause + source: (string) @string.special.url) + +[ + "declare" + "implements" + "type" + "override" + "module" + "asserts" + "infer" + "is" + "using" +] @keyword + +[ + "namespace" + "interface" + "enum" +] @keyword.type + +[ + "keyof" + "satisfies" +] @keyword.operator + +(as_expression + "as" @keyword.operator) + +(mapped_type_clause + "as" @keyword.operator) + +[ + "abstract" + "private" + "protected" + "public" + "readonly" +] @keyword.modifier + +; types +(type_identifier) @type + +(predefined_type) @type.builtin + +(import_statement + "type" + (import_clause + (named_imports + (import_specifier + name: (identifier) @type)))) + +(template_literal_type) @string + +(non_null_expression + "!" @operator) + +; punctuation +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(object_type + [ + "{|" + "|}" + ] @punctuation.bracket) + +(union_type + "|" @punctuation.delimiter) + +(intersection_type + "&" @punctuation.delimiter) + +(type_annotation + ":" @punctuation.delimiter) + +(type_predicate_annotation + ":" @punctuation.delimiter) + +(index_signature + ":" @punctuation.delimiter) + +(omitting_type_annotation + "-?:" @punctuation.delimiter) + +(adding_type_annotation + "+?:" @punctuation.delimiter) + +(opting_type_annotation + "?:" @punctuation.delimiter) + +"?." @punctuation.delimiter + +(abstract_method_signature + "?" @punctuation.special) + +(method_signature + "?" @punctuation.special) + +(method_definition + "?" @punctuation.special) + +(property_signature + "?" @punctuation.special) + +(optional_parameter + "?" @punctuation.special) + +(optional_type + "?" @punctuation.special) + +(public_field_definition + [ + "?" + "!" + ] @punctuation.special) + +(flow_maybe_type + "?" @punctuation.special) + +(template_type + [ + "${" + "}" + ] @punctuation.special) + +(conditional_type + [ + "?" + ":" + ] @keyword.conditional.ternary) + +; Parameters +(required_parameter + pattern: (identifier) @variable.parameter) + +(optional_parameter + pattern: (identifier) @variable.parameter) + +(required_parameter + (rest_pattern + (identifier) @variable.parameter)) + +; ({ a }) => null +(required_parameter + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a = b }) => null +(required_parameter + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a: b }) => null +(required_parameter + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ a ]) => null +(required_parameter + (array_pattern + (identifier) @variable.parameter)) + +; a => null +(arrow_function + parameter: (identifier) @variable.parameter) + +; global declaration +(ambient_declaration + "global" @module) + +; function signatures +(ambient_declaration + (function_signature + name: (identifier) @function)) + +; method signatures +(method_signature + name: (_) @function.method) + +(abstract_method_signature + name: (property_identifier) @function.method) + +; property signatures +(property_signature + name: (property_identifier) @function.method + type: (type_annotation + [ + (union_type + (parenthesized_type + (function_type))) + (function_type) + ])) diff --git a/bex/tag-preprocessor/queries/c.scm b/bex/tag-preprocessor/queries/c.scm new file mode 100644 index 0000000..442343a --- /dev/null +++ b/bex/tag-preprocessor/queries/c.scm @@ -0,0 +1,341 @@ +; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +((identifier) @variable + (#set! priority 95)) + +(preproc_def + (preproc_arg) @variable) + +[ + "default" + "goto" + "asm" + "__asm__" +] @keyword + +[ + "enum" + "struct" + "union" + "typedef" +] @keyword.type + +[ + "sizeof" + "offsetof" +] @keyword.operator + +(alignof_expression + . + _ @keyword.operator) + +"return" @keyword.return + +[ + "while" + "for" + "do" + "continue" + "break" +] @keyword.repeat + +[ + "if" + "else" + "case" + "switch" +] @keyword.conditional + +[ + "#if" + "#ifdef" + "#ifndef" + "#else" + "#elif" + "#endif" + "#elifdef" + "#elifndef" + (preproc_directive) +] @keyword.directive + +"#define" @keyword.directive.define + +"#include" @keyword.import + +[ + ";" + ":" + "," + "." + "::" +] @punctuation.delimiter + +"..." @punctuation.special + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "-" + "*" + "/" + "+" + "%" + "~" + "|" + "&" + "^" + "<<" + ">>" + "->" + "<" + "<=" + ">=" + ">" + "==" + "!=" + "!" + "&&" + "||" + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" + "--" + "++" +] @operator + +; Make sure the comma operator is given a highlight group after the comma +; punctuator so the operator is highlighted properly. +(comma_expression + "," @operator) + +[ + (true) + (false) +] @boolean + +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(string_literal) @string + +(system_lib_string) @string + +(escape_sequence) @string.escape + +(null) @constant.builtin + +(number_literal) @number + +(char_literal) @character + +(preproc_defined) @function.macro + +((field_expression + (field_identifier) @property) @_parent + (#not-has-parent? @_parent function_declarator call_expression)) + +(field_designator) @property + +((field_identifier) @property + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) + +(statement_identifier) @label + +(declaration + type: (type_identifier) @_type + declarator: (identifier) @label + (#eq? @_type "__label__")) + +[ + (type_identifier) + (type_descriptor) +] @type + +(storage_class_specifier) @keyword.modifier + +[ + (type_qualifier) + (gnu_asm_qualifier) + "__extension__" +] @keyword.modifier + +(linkage_specification + "extern" @keyword.modifier) + +(type_definition + declarator: (type_identifier) @type.definition) + +(primitive_type) @type.builtin + +(sized_type_specifier + _ @type.builtin + type: _?) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(preproc_def + (preproc_arg) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(enumerator + name: (identifier) @constant) + +(case_statement + value: (identifier) @constant) + +((identifier) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(preproc_def + (preproc_arg) @constant.builtin + ; format-ignore + (#any-of? @constant.builtin + "stderr" "stdin" "stdout" + "__FILE__" "__LINE__" "__DATE__" "__TIME__" + "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__" + "__cplusplus" "__OBJC__" "__ASSEMBLER__" + "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__" + "__TIMESTAMP__" "__clang__" "__clang_major__" + "__clang_minor__" "__clang_patchlevel__" + "__clang_version__" "__clang_literal_encoding__" + "__clang_wide_literal_encoding__" + "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" + "__VA_ARGS__" "__VA_OPT__")) + +(attribute_specifier + (argument_list + (identifier) @variable.builtin)) + +(attribute_specifier + (argument_list + (call_expression + function: (identifier) @variable.builtin))) + +((call_expression + function: (identifier) @function.builtin) + (#lua-match? @function.builtin "^__builtin_")) + +((call_expression + function: (identifier) @function.builtin) + (#has-ancestor? @function.builtin attribute_specifier)) + +; Preproc def / undef +(preproc_def + name: (_) @constant.macro) + +(preproc_call + directive: (preproc_directive) @_u + argument: (_) @constant.macro + (#eq? @_u "#undef")) + +(preproc_ifdef + name: (identifier) @constant.macro) + +(preproc_elifdef + name: (identifier) @constant.macro) + +(preproc_defined + (identifier) @constant.macro) + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +(function_declarator + declarator: (identifier) @function) + +(function_declarator + declarator: (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) + +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +; Parameters +(parameter_declaration + declarator: (identifier) @variable.parameter) + +(parameter_declaration + declarator: (array_declarator) @variable.parameter) + +(parameter_declaration + declarator: (pointer_declarator) @variable.parameter) + +; K&R functions +; To enable support for K&R functions, +; add the following lines to your own query config and uncomment them. +; They are commented out as they'll conflict with C++ +; Note that you'll need to have `; extends` at the top of your query file. +; +; (parameter_list (identifier) @variable.parameter) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (identifier) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (array_declarator) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (pointer_declarator) @variable.parameter)) +(preproc_params + (identifier) @variable.parameter) + +[ + "__attribute__" + "__declspec" + "__based" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + (ms_pointer_modifier) + (attribute_declaration) +] @attribute diff --git a/bex/tag-preprocessor/queries/cpp.scm b/bex/tag-preprocessor/queries/cpp.scm new file mode 100644 index 0000000..ac03152 --- /dev/null +++ b/bex/tag-preprocessor/queries/cpp.scm @@ -0,0 +1,273 @@ +; inherits: c + +((identifier) @variable.member + (#lua-match? @variable.member "^m_.*$")) + +(parameter_declaration + declarator: (reference_declarator) @variable.parameter) + +; function(Foo ...foo) +(variadic_parameter_declaration + declarator: (variadic_declarator + (_) @variable.parameter)) + +; int foo = 0 +(optional_parameter_declaration + declarator: (_) @variable.parameter) + +;(field_expression) @variable.parameter ;; How to highlight this? +((field_expression + (field_identifier) @function.method) @_parent + (#has-parent? @_parent template_method function_declarator)) + +(field_declaration + (field_identifier) @variable.member) + +(field_initializer + (field_identifier) @property) + +(function_declarator + declarator: (field_identifier) @function.method) + +(concept_definition + name: (identifier) @type.definition) + +(alias_declaration + name: (type_identifier) @type.definition) + +(auto) @type.builtin + +(namespace_identifier) @module + +((namespace_identifier) @type + (#lua-match? @type "^[%u]")) + +(case_statement + value: (qualified_identifier + (identifier) @constant)) + +(using_declaration + . + "using" + . + "namespace" + . + [ + (qualified_identifier) + (identifier) + ] @module) + +(destructor_name + (identifier) @function.method) + +; functions +(function_declarator + (qualified_identifier + (identifier) @function)) + +(function_declarator + (qualified_identifier + (qualified_identifier + (identifier) @function))) + +(function_declarator + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function)))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function)))) @_parent + (#has-ancestor? @_parent function_declarator)) + +(function_declarator + (template_function + (identifier) @function)) + +(operator_name) @function + +"operator" @function + +"static_assert" @function.builtin + +(call_expression + (qualified_identifier + (identifier) @function.call)) + +(call_expression + (qualified_identifier + (qualified_identifier + (identifier) @function.call))) + +(call_expression + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function.call)))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (identifier) @function.call)))) @_parent + (#has-ancestor? @_parent call_expression)) + +(call_expression + (template_function + (identifier) @function.call)) + +(call_expression + (qualified_identifier + (template_function + (identifier) @function.call))) + +(call_expression + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call)))) + +(call_expression + (qualified_identifier + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call))))) + +((qualified_identifier + (qualified_identifier + (qualified_identifier + (qualified_identifier + (template_function + (identifier) @function.call))))) @_parent + (#has-ancestor? @_parent call_expression)) + +; methods +(function_declarator + (template_method + (field_identifier) @function.method)) + +(call_expression + (field_expression + (field_identifier) @function.method.call)) + +(call_expression + (field_expression + (template_method + (field_identifier) @function.method.call))) + +; constructors +((function_declarator + (qualified_identifier + (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (qualified_identifier + name: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +((call_expression + function: (field_expression + field: (field_identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +; constructing a type in an initializer list: Constructor (): **SuperType (1)** +((field_initializer + (field_identifier) @constructor + (argument_list)) + (#lua-match? @constructor "^%u")) + +; Constants +(this) @variable.builtin + +(null + "nullptr" @constant.builtin) + +(true) @boolean + +(false) @boolean + +; Literals +(raw_string_literal) @string + +; Keywords +[ + "try" + "catch" + "noexcept" + "throw" +] @keyword.exception + +[ + "decltype" + "explicit" + "friend" + "override" + "using" + "requires" + "constexpr" +] @keyword + +[ + "class" + "namespace" + "template" + "typename" + "concept" +] @keyword.type + +[ + "co_await" + "co_yield" + "co_return" +] @keyword.coroutine + +[ + "public" + "private" + "protected" + "final" + "virtual" +] @keyword.modifier + +[ + "new" + "delete" + "xor" + "bitand" + "bitor" + "compl" + "not" + "xor_eq" + "and_eq" + "or_eq" + "not_eq" + "and" + "or" +] @keyword.operator + +"<=>" @operator + +"::" @punctuation.delimiter + +(template_argument_list + [ + "<" + ">" + ] @punctuation.bracket) + +(template_parameter_list + [ + "<" + ">" + ] @punctuation.bracket) + +(literal_suffix) @operator diff --git a/bex/tag-preprocessor/queries/ecma.scm b/bex/tag-preprocessor/queries/ecma.scm new file mode 100644 index 0000000..cec2f4e --- /dev/null +++ b/bex/tag-preprocessor/queries/ecma.scm @@ -0,0 +1,392 @@ +; Types +; Javascript +; Variables +;----------- +(identifier) @variable + +; Properties +;----------- +(property_identifier) @variable.member + +(shorthand_property_identifier) @variable.member + +(private_property_identifier) @variable.member + +(object_pattern + (shorthand_property_identifier_pattern) @variable) + +(object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable)) + +; Special identifiers +;-------------------- +((identifier) @type + (#lua-match? @type "^[A-Z]")) + +((identifier) @constant + (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$")) + +((shorthand_property_identifier) @constant + (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$")) + +((identifier) @variable.builtin + (#any-of? @variable.builtin "arguments" "module" "console" "window" "document")) + +((identifier) @type.builtin + (#any-of? @type.builtin + "Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set" + "WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array" + "Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView" + "Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError" + "URIError")) + +(statement_identifier) @label + +; Function and method definitions +;-------------------------------- +(function_expression + name: (identifier) @function) + +(function_declaration + name: (identifier) @function) + +(generator_function + name: (identifier) @function) + +(generator_function_declaration + name: (identifier) @function) + +(method_definition + name: [ + (property_identifier) + (private_property_identifier) + ] @function.method) + +(method_definition + name: (property_identifier) @constructor + (#eq? @constructor "constructor")) + +(pair + key: (property_identifier) @function.method + value: (function_expression)) + +(pair + key: (property_identifier) @function.method + value: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (function_expression)) + +(variable_declarator + name: (identifier) @function + value: (arrow_function)) + +(variable_declarator + name: (identifier) @function + value: (function_expression)) + +(assignment_expression + left: (identifier) @function + right: (arrow_function)) + +(assignment_expression + left: (identifier) @function + right: (function_expression)) + +; Function and method calls +;-------------------------- +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (member_expression + property: [ + (property_identifier) + (private_property_identifier) + ] @function.method.call)) + +(call_expression + function: (await_expression + (identifier) @function.call)) + +(call_expression + function: (await_expression + (member_expression + property: [ + (property_identifier) + (private_property_identifier) + ] @function.method.call))) + +; Builtins +;--------- +((identifier) @module.builtin + (#eq? @module.builtin "Intl")) + +((identifier) @function.builtin + (#any-of? @function.builtin + "eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI" + "encodeURIComponent" "require")) + +; Constructor +;------------ +(new_expression + constructor: (identifier) @constructor) + +; Decorators +;---------- +(decorator + "@" @attribute + (identifier) @attribute) + +(decorator + "@" @attribute + (call_expression + (identifier) @attribute)) + +(decorator + "@" @attribute + (member_expression + (property_identifier) @attribute)) + +(decorator + "@" @attribute + (call_expression + (member_expression + (property_identifier) @attribute))) + +; Literals +;--------- +[ + (this) + (super) +] @variable.builtin + +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +[ + (true) + (false) +] @boolean + +[ + (null) + (undefined) +] @constant.builtin + +[ + (comment) + (html_comment) +] @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +(hash_bang_line) @keyword.directive + +((string_fragment) @keyword.directive + (#eq? @keyword.directive "use strict")) + +(string) @string + +(template_string) @string + +(escape_sequence) @string.escape + +(regex_pattern) @string.regexp + +(regex_flags) @character.special + +(regex + "/" @punctuation.bracket) ; Regex delimiters + +(number) @number + +((identifier) @number + (#any-of? @number "NaN" "Infinity")) + +; Punctuation +;------------ +[ + ";" + "." + "," + ":" +] @punctuation.delimiter + +[ + "--" + "-" + "-=" + "&&" + "+" + "++" + "+=" + "&=" + "/=" + "**=" + "<<=" + "<" + "<=" + "<<" + "=" + "==" + "===" + "!=" + "!==" + "=>" + ">" + ">=" + ">>" + "||" + "%" + "%=" + "*" + "**" + ">>>" + "&" + "|" + "^" + "??" + "*=" + ">>=" + ">>>=" + "^=" + "|=" + "&&=" + "||=" + "??=" + "..." +] @operator + +(binary_expression + "/" @operator) + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(unary_expression + [ + "!" + "~" + "-" + "+" + ] @operator) + +(unary_expression + [ + "delete" + "void" + ] @keyword.operator) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(template_substitution + [ + "${" + "}" + ] @punctuation.special) @none + +; Imports +;---------- +(namespace_import + "*" @character.special + (identifier) @module) + +(namespace_export + "*" @character.special + (identifier) @module) + +(export_statement + "*" @character.special) + +; Keywords +;---------- +[ + "if" + "else" + "switch" + "case" +] @keyword.conditional + +[ + "import" + "from" + "as" + "export" +] @keyword.import + +[ + "for" + "of" + "do" + "while" + "continue" +] @keyword.repeat + +[ + "break" + "const" + "debugger" + "extends" + "get" + "let" + "set" + "static" + "target" + "var" + "with" +] @keyword + +"class" @keyword.type + +[ + "async" + "await" +] @keyword.coroutine + +[ + "return" + "yield" +] @keyword.return + +"function" @keyword.function + +[ + "new" + "delete" + "in" + "instanceof" + "typeof" +] @keyword.operator + +[ + "throw" + "try" + "catch" + "finally" +] @keyword.exception + +(export_statement + "default" @keyword) + +(switch_default + "default" @keyword.conditional) diff --git a/bex/tag-preprocessor/queries/go.scm b/bex/tag-preprocessor/queries/go.scm new file mode 100644 index 0000000..0251f3b --- /dev/null +++ b/bex/tag-preprocessor/queries/go.scm @@ -0,0 +1,249 @@ +; Forked from tree-sitter-go +; Copyright (c) 2014 Max Brunsfeld (The MIT License) +; +; Identifiers +(type_identifier) @type + +(type_spec + name: (type_identifier) @type.definition) + +(field_identifier) @property + +(identifier) @variable + +(package_identifier) @module + +(parameter_declaration + (identifier) @variable.parameter) + +(variadic_parameter_declaration + (identifier) @variable.parameter) + +(label_name) @label + +(const_spec + name: (identifier) @constant) + +; Function calls +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (selector_expression + field: (field_identifier) @function.method.call)) + +; Function definitions +(function_declaration + name: (identifier) @function) + +(method_declaration + name: (field_identifier) @function.method) + +(method_elem + name: (field_identifier) @function.method) + +; Constructors +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[nN]ew.+$")) + +((call_expression + (identifier) @constructor) + (#lua-match? @constructor "^[mM]ake.+$")) + +; Operators +[ + "--" + "-" + "-=" + ":=" + "!" + "!=" + "..." + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "&^" + "&^=" + "%" + "%=" + "^" + "^=" + "+" + "++" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" +] @operator + +; Keywords +[ + "break" + "const" + "continue" + "default" + "defer" + "goto" + "range" + "select" + "var" + "fallthrough" +] @keyword + +[ + "type" + "struct" + "interface" +] @keyword.type + +"func" @keyword.function + +"return" @keyword.return + +"go" @keyword.coroutine + +"for" @keyword.repeat + +[ + "import" + "package" +] @keyword.import + +[ + "else" + "case" + "switch" + "if" +] @keyword.conditional + +; Builtin types +[ + "chan" + "map" +] @type.builtin + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "any" "bool" "byte" "comparable" "complex128" "complex64" "error" "float32" "float64" "int" + "int16" "int32" "int64" "int8" "rune" "string" "uint" "uint16" "uint32" "uint64" "uint8" + "uintptr")) + +; Builtin functions +((identifier) @function.builtin + (#any-of? @function.builtin + "append" "cap" "clear" "close" "complex" "copy" "delete" "imag" "len" "make" "max" "min" "new" + "panic" "print" "println" "real" "recover")) + +; Delimiters +[ + "." + "," + ":" + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +; Literals +(interpreted_string_literal) @string + +(raw_string_literal) @string + +(rune_literal) @character + +(escape_sequence) @string.escape + +(int_literal) @number + +(float_literal) @number.float + +(imaginary_literal) @number + +[ + (true) + (false) +] @boolean + +[ + (nil) + (iota) +] @constant.builtin + +(keyed_element + . + (literal_element + (identifier) @variable.member)) + +(field_declaration + name: (field_identifier) @variable.member) + +; Comments +(comment) @comment @spell + +; Doc Comments +(source_file + . + (comment)+ @comment.documentation) + +(source_file + (comment)+ @comment.documentation + . + (const_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (function_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (type_declaration)) + +(source_file + (comment)+ @comment.documentation + . + (var_declaration)) + +; Spell +((interpreted_string_literal) @spell + (#not-has-parent? @spell import_spec)) + +; Regex +(call_expression + (selector_expression) @_function + (#any-of? @_function + "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" + "regexp.MustCompile" "regexp.MustCompilePOSIX") + (argument_list + . + [ + (raw_string_literal + (raw_string_literal_content) @string.regexp) + (interpreted_string_literal + (interpreted_string_literal_content) @string.regexp) + ])) diff --git a/bex/tag-preprocessor/queries/java.scm b/bex/tag-preprocessor/queries/java.scm new file mode 100644 index 0000000..641f1e3 --- /dev/null +++ b/bex/tag-preprocessor/queries/java.scm @@ -0,0 +1,333 @@ +; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com) +; Variables +(identifier) @variable + +(underscore_pattern) @character.special + +; Methods +(method_declaration + name: (identifier) @function.method) + +(method_invocation + name: (identifier) @function.method.call) + +(super) @function.builtin + +; Parameters +(formal_parameter + name: (identifier) @variable.parameter) + +(spread_parameter + (variable_declarator + name: (identifier) @variable.parameter)) ; int... foo + +; Lambda parameter +(inferred_parameters + (identifier) @variable.parameter) ; (x,y) -> ... + +(lambda_expression + parameters: (identifier) @variable.parameter) ; x -> ... + +; Operators +[ + "+" + ":" + "++" + "-" + "--" + "&" + "&&" + "|" + "||" + "!" + "!=" + "==" + "*" + "/" + "%" + "<" + "<=" + ">" + ">=" + "=" + "-=" + "+=" + "*=" + "/=" + "%=" + "->" + "^" + "^=" + "&=" + "|=" + "~" + ">>" + ">>>" + "<<" + "::" +] @operator + +; Types +(interface_declaration + name: (identifier) @type) + +(annotation_type_declaration + name: (identifier) @type) + +(class_declaration + name: (identifier) @type) + +(record_declaration + name: (identifier) @type) + +(enum_declaration + name: (identifier) @type) + +(constructor_declaration + name: (identifier) @type) + +(compact_constructor_declaration + name: (identifier) @type) + +(type_identifier) @type + +((type_identifier) @type.builtin + (#eq? @type.builtin "var")) + +((method_invocation + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((method_reference + . + (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((field_access + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +(scoped_identifier + (identifier) @type + (#lua-match? @type "^[A-Z]")) + +; Fields +(field_declaration + declarator: (variable_declarator + name: (identifier) @variable.member)) + +(field_access + field: (identifier) @variable.member) + +[ + (boolean_type) + (integral_type) + (floating_point_type) + (void_type) +] @type.builtin + +; Variables +((identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z%d_]+$")) + +(this) @variable.builtin + +; Annotations +(annotation + "@" @attribute + name: (identifier) @attribute) + +(marker_annotation + "@" @attribute + name: (identifier) @attribute) + +; Literals +(string_literal) @string + +(escape_sequence) @string.escape + +(character_literal) @character + +[ + (hex_integer_literal) + (decimal_integer_literal) + (octal_integer_literal) + (binary_integer_literal) +] @number + +[ + (decimal_floating_point_literal) + (hex_floating_point_literal) +] @number.float + +[ + (true) + (false) +] @boolean + +(null_literal) @constant.builtin + +; Keywords +[ + "assert" + "default" + "extends" + "implements" + "instanceof" + "@interface" + "permits" + "to" + "with" +] @keyword + +[ + "record" + "class" + "enum" + "interface" +] @keyword.type + +(synchronized_statement + "synchronized" @keyword) + +[ + "abstract" + "final" + "native" + "non-sealed" + "open" + "private" + "protected" + "public" + "sealed" + "static" + "strictfp" + "transitive" +] @keyword.modifier + +(modifiers + "synchronized" @keyword.modifier) + +[ + "transient" + "volatile" +] @keyword.modifier + +[ + "return" + "yield" +] @keyword.return + +"new" @keyword.operator + +; Conditionals +[ + "if" + "else" + "switch" + "case" + "when" +] @keyword.conditional + +(ternary_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) + +(wildcard + "?" @character.special) + +; Loops +[ + "for" + "while" + "do" + "continue" + "break" +] @keyword.repeat + +; Includes +[ + "exports" + "import" + "module" + "opens" + "package" + "provides" + "requires" + "uses" +] @keyword.import + +(import_declaration + (asterisk + "*" @character.special)) + +; Punctuation +[ + ";" + "." + "..." + "," +] @punctuation.delimiter + +[ + "{" + "}" +] @punctuation.bracket + +[ + "[" + "]" +] @punctuation.bracket + +[ + "(" + ")" +] @punctuation.bracket + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(string_interpolation + [ + "\\{" + "}" + ] @punctuation.special) + +; Exceptions +[ + "throw" + "throws" + "finally" + "try" + "catch" +] @keyword.exception + +; Labels +(labeled_statement + (identifier) @label) + +; Comments +[ + (line_comment) + (block_comment) +] @comment @spell + +((block_comment) @comment.documentation + (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) + +((line_comment) @comment.documentation + (#lua-match? @comment.documentation "^///[^/]")) + +((line_comment) @comment.documentation + (#lua-match? @comment.documentation "^///$")) diff --git a/bex/tag-preprocessor/queries/javascript.scm b/bex/tag-preprocessor/queries/javascript.scm new file mode 100644 index 0000000..257a731 --- /dev/null +++ b/bex/tag-preprocessor/queries/javascript.scm @@ -0,0 +1,56 @@ +; inherits: ecma,jsx + +; Parameters +(formal_parameters + (identifier) @variable.parameter) + +(formal_parameters + (rest_pattern + (identifier) @variable.parameter)) + +; ({ a }) => null +(formal_parameters + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a = b }) => null +(formal_parameters + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a: b }) => null +(formal_parameters + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ a ]) => null +(formal_parameters + (array_pattern + (identifier) @variable.parameter)) + +; ({ a } = { a }) => null +(formal_parameters + (assignment_pattern + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a = b } = { a }) => null +(formal_parameters + (assignment_pattern + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter)))) + +; a => null +(arrow_function + parameter: (identifier) @variable.parameter) + +; optional parameters +(formal_parameters + (assignment_pattern + left: (identifier) @variable.parameter)) + +; punctuation +(optional_chain) @punctuation.delimiter diff --git a/bex/tag-preprocessor/queries/jsx.scm b/bex/tag-preprocessor/queries/jsx.scm new file mode 100644 index 0000000..c2bf7fb --- /dev/null +++ b/bex/tag-preprocessor/queries/jsx.scm @@ -0,0 +1,153 @@ +(jsx_element + open_tag: (jsx_opening_element + [ + "<" + ">" + ] @tag.delimiter)) + +(jsx_element + close_tag: (jsx_closing_element + [ + "" + ] @tag.delimiter)) + +(jsx_self_closing_element + [ + "<" + "/>" + ] @tag.delimiter) + +(jsx_attribute + (property_identifier) @tag.attribute) + +(jsx_opening_element + name: (identifier) @tag.builtin) + +(jsx_closing_element + name: (identifier) @tag.builtin) + +(jsx_self_closing_element + name: (identifier) @tag.builtin) + +(jsx_opening_element + ((identifier) @tag + (#lua-match? @tag "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_opening_element + (member_expression + (identifier) @tag.builtin + (property_identifier) @tag)) + +(jsx_closing_element + ((identifier) @tag + (#lua-match? @tag "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_closing_element + (member_expression + (identifier) @tag.builtin + (property_identifier) @tag)) + +(jsx_self_closing_element + ((identifier) @tag + (#lua-match? @tag "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_self_closing_element + (member_expression + (identifier) @tag.builtin + (property_identifier) @tag)) + +(html_character_reference) @tag + +(jsx_text) @none @spell + +(html_character_reference) @character.special + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading) + (#eq? @_tag "title")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.1) + (#eq? @_tag "h1")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.2) + (#eq? @_tag "h2")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.3) + (#eq? @_tag "h3")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.4) + (#eq? @_tag "h4")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.5) + (#eq? @_tag "h5")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.heading.6) + (#eq? @_tag "h6")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.strong) + (#any-of? @_tag "strong" "b")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.italic) + (#any-of? @_tag "em" "i")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.strikethrough) + (#any-of? @_tag "s" "del")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.underline) + (#eq? @_tag "u")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.raw) + (#any-of? @_tag "code" "kbd")) + +((jsx_element + (jsx_opening_element + name: (identifier) @_tag) + (jsx_text) @markup.link.label) + (#eq? @_tag "a")) + +((jsx_attribute + (property_identifier) @_attr + (string + (string_fragment) @string.special.url)) + (#any-of? @_attr "href" "src")) + + diff --git a/bex/queries/community/kotlin_highlights.scm b/bex/tag-preprocessor/queries/kotlin.scm similarity index 97% rename from bex/queries/community/kotlin_highlights.scm rename to bex/tag-preprocessor/queries/kotlin.scm index 93eeb33..6f1c968 100644 --- a/bex/queries/community/kotlin_highlights.scm +++ b/bex/tag-preprocessor/queries/kotlin.scm @@ -183,6 +183,7 @@ "require" "requireNotNull" "with" + "suspend" "synchronized" )) @@ -346,11 +347,12 @@ "?:" "!!" "is" + "!is" "in" + "!in" "as" "as?" ".." - "..<" "->" ] @operator @@ -370,9 +372,9 @@ ; NOTE: `interpolated_identifier`s can be highlighted in any way (string_literal - (interpolation_identifier_start) @punctuation.special + "$" @punctuation.special (interpolated_identifier) @none) (string_literal - (interpolation_expression_start) @punctuation.special + "${" @punctuation.special (interpolated_expression) @none - (interpolation_expression_end) @punctuation.special) + "}" @punctuation.special) diff --git a/bex/tag-preprocessor/queries/python.scm b/bex/tag-preprocessor/queries/python.scm new file mode 100644 index 0000000..1b046d6 --- /dev/null +++ b/bex/tag-preprocessor/queries/python.scm @@ -0,0 +1,456 @@ +; From tree-sitter-python licensed under MIT License +; Copyright (c) 2016 Max Brunsfeld +; Variables +(identifier) @variable + +; Reset highlighting in f-string interpolations +(interpolation) @none @nospell + +; Identifier naming conventions +((identifier) @type + (#lua-match? @type "^[A-Z].*[a-z]")) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +((identifier) @constant.builtin + (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + ; https://docs.python.org/3/library/constants.html + "NotImplemented" "Ellipsis" "quit" "exit" "copyright" "credits" "license")) + +"_" @character.special ; match wildcard + +((assignment + left: (identifier) @type.definition + (type + (identifier) @_annotation)) + (#eq? @_annotation "TypeAlias")) + +((assignment + left: (identifier) @type.definition + right: (call + function: (identifier) @_func)) + (#any-of? @_func "TypeVar" "NewType")) + +; Function definitions +(function_definition + name: (identifier) @function) + +(type + (identifier) @type) + +(type + (subscript + (identifier) @type)) ; type subscript: Tuple[int] + +((call + function: (identifier) @_isinstance + arguments: (argument_list + (_) + (identifier) @type)) + (#eq? @_isinstance "isinstance")) + +; Literals +(none) @constant.builtin + +[ + (true) + (false) +] @boolean + +(integer) @number + +(float) @number.float + +(comment) @comment @spell + +((module + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#!/")) + +(string) @string + +[ + (escape_sequence) + (escape_interpolation) +] @string.escape + +; doc-strings +(expression_statement + (string + (string_content) @spell) @string.documentation) + +; Tokens +[ + "-" + "-=" + ":=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "@" + "@=" + "|" + "|=" + "~" + "->" +] @operator + +; Keywords +[ + "and" + "in" + "is" + "not" + "or" + "is not" + "not in" + "del" +] @keyword.operator + +[ + "def" + "lambda" +] @keyword.function + +[ + "assert" + "exec" + "global" + "nonlocal" + "pass" + "print" + "with" + "as" +] @keyword + +[ + "type" + "class" +] @keyword.type + +[ + "async" + "await" +] @keyword.coroutine + +[ + "return" + "yield" +] @keyword.return + +(yield + "from" @keyword.return) + +(future_import_statement + "from" @keyword.import + "__future__" @module.builtin) + +(import_from_statement + "from" @keyword.import) + +"import" @keyword.import + +(aliased_import + "as" @keyword.import) + +(wildcard_import + "*" @character.special) + +(import_statement + name: (dotted_name + (identifier) @module)) + +(import_statement + name: (aliased_import + name: (dotted_name + (identifier) @module) + alias: (identifier) @module)) + +(import_from_statement + module_name: (dotted_name + (identifier) @module)) + +(import_from_statement + module_name: (relative_import + (dotted_name + (identifier) @module))) + +[ + "if" + "elif" + "else" + "match" + "case" +] @keyword.conditional + +[ + "for" + "while" + "break" + "continue" +] @keyword.repeat + +[ + "try" + "except" + "raise" + "finally" +] @keyword.exception + +(raise_statement + "from" @keyword.exception) + +(try_statement + (else_clause + "else" @keyword.exception)) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) + +(format_expression + "{" @punctuation.special + "}" @punctuation.special) + +(line_continuation) @punctuation.special + +(type_conversion) @function.macro + +[ + "," + "." + ":" + ";" + (ellipsis) +] @punctuation.delimiter + +((identifier) @type.builtin + (#any-of? @type.builtin + ; https://docs.python.org/3/library/exceptions.html + "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" + "AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" + "ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError" + "NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError" + "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError" + "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" + "UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" + "IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError" + "BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError" + "FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError" + "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" + "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" + "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning" + ; https://docs.python.org/3/library/stdtypes.html + "bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview" + "set" "frozenset" "dict" "type" "object")) + +; Normal parameters +(parameters + (identifier) @variable.parameter) + +; Lambda parameters +(lambda_parameters + (identifier) @variable.parameter) + +(lambda_parameters + (tuple_pattern + (identifier) @variable.parameter)) + +; Default parameters +(keyword_argument + name: (identifier) @variable.parameter) + +; Naming parameters on call-site +(default_parameter + name: (identifier) @variable.parameter) + +(typed_parameter + (identifier) @variable.parameter) + +(typed_default_parameter + name: (identifier) @variable.parameter) + +; Variadic parameters *args, **kwargs +(parameters + (list_splat_pattern ; *args + (identifier) @variable.parameter)) + +(parameters + (dictionary_splat_pattern ; **kwargs + (identifier) @variable.parameter)) + +; Typed variadic parameters +(parameters + (typed_parameter + (list_splat_pattern ; *args: type + (identifier) @variable.parameter))) + +(parameters + (typed_parameter + (dictionary_splat_pattern ; *kwargs: type + (identifier) @variable.parameter))) + +; Lambda parameters +(lambda_parameters + (list_splat_pattern + (identifier) @variable.parameter)) + +(lambda_parameters + (dictionary_splat_pattern + (identifier) @variable.parameter)) + +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +((identifier) @variable.builtin + (#eq? @variable.builtin "cls")) + +; After @type.builtin bacause builtins (such as `type`) are valid as attribute name +((attribute + attribute: (identifier) @variable.member) + (#lua-match? @variable.member "^[%l_].*$")) + +; Class definitions +(class_definition + name: (identifier) @type) + +(class_definition + body: (block + (function_definition + name: (identifier) @function.method))) + +(class_definition + superclasses: (argument_list + (identifier) @type)) + +((class_definition + body: (block + (expression_statement + (assignment + left: (identifier) @variable.member)))) + (#lua-match? @variable.member "^[%l_].*$")) + +((class_definition + body: (block + (expression_statement + (assignment + left: (_ + (identifier) @variable.member))))) + (#lua-match? @variable.member "^[%l_].*$")) + +((class_definition + (block + (function_definition + name: (identifier) @constructor))) + (#any-of? @constructor "__new__" "__init__")) + +; Function calls +(call + function: (identifier) @function.call) + +(call + function: (attribute + attribute: (identifier) @function.method.call)) + +((call + function: (identifier) @constructor) + (#lua-match? @constructor "^%u")) + +((call + function: (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^%u")) + +; Builtin functions +((call + function: (identifier) @function.builtin) + (#any-of? @function.builtin + "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" + "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" + "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" + "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview" + "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed" + "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type" + "vars" "zip" "__import__")) + +; Regex from the `re` module +(call + function: (attribute + object: (identifier) @_re) + arguments: (argument_list + (string + (string_content) @string.regexp)) + (#eq? @_re "re")) + +(call + function: (attribute + object: (identifier) @_re) + arguments: (argument_list + (concatenated_string + (string + (string_content) @string.regexp))) + (#eq? @_re "re")) + +; Decorators +((decorator + "@" @attribute) + (#set! priority 101)) + +(decorator + (identifier) @attribute) + +(decorator + (attribute + attribute: (identifier) @attribute)) + +(decorator + (call + (identifier) @attribute)) + +(decorator + (call + (attribute + attribute: (identifier) @attribute))) + +((decorator + (identifier) @attribute.builtin) + (#any-of? @attribute.builtin "classmethod" "property" "staticmethod")) diff --git a/bex/tag-preprocessor/queries/ruby.scm b/bex/tag-preprocessor/queries/ruby.scm new file mode 100644 index 0000000..5aa518a --- /dev/null +++ b/bex/tag-preprocessor/queries/ruby.scm @@ -0,0 +1,319 @@ +; Variables +[ + (identifier) + (global_variable) +] @variable + +; Keywords +[ + "alias" + "begin" + "do" + "end" + "ensure" + "module" + "rescue" + "then" +] @keyword + +"class" @keyword.type + +[ + "return" + "yield" +] @keyword.return + +[ + "and" + "or" + "in" + "not" +] @keyword.operator + +[ + "def" + "undef" +] @keyword.function + +(method + "end" @keyword.function) + +[ + "case" + "else" + "elsif" + "if" + "unless" + "when" + "then" +] @keyword.conditional + +(in_clause + "in" @keyword.conditional) + +(if + "end" @keyword.conditional) + +[ + "for" + "until" + "while" + "break" + "redo" + "retry" + "next" +] @keyword.repeat + +(in + "in" @keyword.repeat) + +(constant) @constant + +((identifier) @keyword.modifier + (#any-of? @keyword.modifier "private" "protected" "public")) + +[ + "rescue" + "ensure" +] @keyword.exception + +; Function calls +"defined?" @function + +(call + receiver: (constant)? @type + method: [ + (identifier) + (constant) + ] @function.call) + +(program + (call + (identifier) @keyword.import) + (#any-of? @keyword.import "require" "require_relative" "load")) + +; Function definitions +(alias + (identifier) @function) + +(setter + (identifier) @function) + +(method + name: [ + (identifier) @function + (constant) @type + ]) + +(singleton_method + name: [ + (identifier) @function + (constant) @type + ]) + +(class + name: (constant) @type) + +(module + name: (constant) @type) + +(superclass + (constant) @type) + +; Identifiers +[ + (class_variable) + (instance_variable) +] @variable.member + +((identifier) @constant.builtin + (#any-of? @constant.builtin + "__callee__" "__dir__" "__id__" "__method__" "__send__" "__ENCODING__" "__FILE__" "__LINE__")) + +((identifier) @function.builtin + (#any-of? @function.builtin "attr_reader" "attr_writer" "attr_accessor" "module_function")) + +((call + !receiver + method: (identifier) @function.builtin) + (#any-of? @function.builtin "include" "extend" "prepend" "refine" "using")) + +((identifier) @keyword.exception + (#any-of? @keyword.exception "raise" "fail" "catch" "throw")) + +((constant) @type + (#not-lua-match? @type "^[A-Z0-9_]+$")) + +[ + (self) + (super) +] @variable.builtin + +(method_parameters + (identifier) @variable.parameter) + +(lambda_parameters + (identifier) @variable.parameter) + +(block_parameters + (identifier) @variable.parameter) + +(splat_parameter + (identifier) @variable.parameter) + +(hash_splat_parameter + (identifier) @variable.parameter) + +(optional_parameter + (identifier) @variable.parameter) + +(destructured_parameter + (identifier) @variable.parameter) + +(block_parameter + (identifier) @variable.parameter) + +(keyword_parameter + (identifier) @variable.parameter) + +; Literals +[ + (string_content) + (heredoc_content) + "\"" + "`" +] @string + +[ + (heredoc_beginning) + (heredoc_end) +] @label + +[ + (bare_symbol) + (simple_symbol) + (hash_key_symbol) +] @string.special.symbol + +(delimited_symbol + ":\"" @string.special.symbol + (string_content) @string.special.symbol + "\"" @string.special.symbol) + +(regex + (string_content) @string.regexp) + +(escape_sequence) @string.escape + +(integer) @number + +(float) @number.float + +[ + (true) + (false) +] @boolean + +(nil) @constant.builtin + +(comment) @comment @spell + +((program + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#!/")) + +(program + (comment)+ @comment.documentation + (class)) + +(module + (comment)+ @comment.documentation + (body_statement + (class))) + +(class + (comment)+ @comment.documentation + (body_statement + (method))) + +(body_statement + (comment)+ @comment.documentation + (method)) + +; Operators +[ + "!" + "=" + "==" + "===" + "<=>" + "=>" + "->" + ">>" + "<<" + ">" + "<" + ">=" + "<=" + "**" + "*" + "/" + "%" + "+" + "-" + "&" + "|" + "^" + "&&" + "||" + "||=" + "&&=" + "!=" + "%=" + "+=" + "-=" + "*=" + "/=" + "=~" + "!~" + "?" + ":" + ".." + "..." +] @operator + +[ + "," + ";" + "." + "&." + "::" +] @punctuation.delimiter + +(regex + "/" @punctuation.bracket) + +(pair + ":" @punctuation.delimiter) + +(keyword_pattern + ":" @punctuation.delimiter) + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "%w(" + "%i(" +] @punctuation.bracket + +(block_parameters + "|" @punctuation.bracket) + +(interpolation + "#{" @punctuation.special + "}" @punctuation.special) diff --git a/bex/tag-preprocessor/queries/rust.scm b/bex/tag-preprocessor/queries/rust.scm new file mode 100644 index 0000000..2342dcf --- /dev/null +++ b/bex/tag-preprocessor/queries/rust.scm @@ -0,0 +1,534 @@ +; Forked from https://github.com/tree-sitter/tree-sitter-rust +; Copyright (c) 2017 Maxim Sokolov +; Licensed under the MIT license. +; Identifier conventions +(shebang) @keyword.directive + +(identifier) @variable + +((identifier) @type + (#lua-match? @type "^[A-Z]")) + +(const_item + name: (identifier) @constant) + +; Assume all-caps names are constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +; Other identifiers +(type_identifier) @type + +(primitive_type) @type.builtin + +(field_identifier) @variable.member + +(shorthand_field_identifier) @variable.member + +(shorthand_field_initializer + (identifier) @variable.member) + +(mod_item + name: (identifier) @module) + +(self) @variable.builtin + +"_" @character.special + +(label + [ + "'" + (identifier) + ] @label) + +; Function definitions +(function_item + (identifier) @function) + +(function_signature_item + (identifier) @function) + +(parameter + [ + (identifier) + "_" + ] @variable.parameter) + +(parameter + (ref_pattern + [ + (mut_pattern + (identifier) @variable.parameter) + (identifier) @variable.parameter + ])) + +(closure_parameters + (_) @variable.parameter) + +; Function calls +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (scoped_identifier + (identifier) @function.call .)) + +(call_expression + function: (field_expression + field: (field_identifier) @function.call)) + +(generic_function + function: (identifier) @function.call) + +(generic_function + function: (scoped_identifier + name: (identifier) @function.call)) + +(generic_function + function: (field_expression + field: (field_identifier) @function.call)) + +; Assume other uppercase names are enum constructors +((field_identifier) @constant + (#lua-match? @constant "^[A-Z]")) + +(enum_variant + name: (identifier) @constant) + +; Assume that uppercase names in paths are types +(scoped_identifier + path: (identifier) @module) + +(scoped_identifier + (scoped_identifier + name: (identifier) @module)) + +(scoped_type_identifier + path: (identifier) @module) + +(scoped_type_identifier + path: (identifier) @type + (#lua-match? @type "^[A-Z]")) + +(scoped_type_identifier + (scoped_identifier + name: (identifier) @module)) + +((scoped_identifier + path: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +((scoped_identifier + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +((scoped_identifier + path: (identifier) @type + name: (identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +((scoped_type_identifier + path: (identifier) @type + name: (type_identifier) @constant) + (#lua-match? @type "^[A-Z]") + (#lua-match? @constant "^[A-Z]")) + +[ + (crate) + (super) +] @module + +(scoped_use_list + path: (identifier) @module) + +(scoped_use_list + path: (scoped_identifier + (identifier) @module)) + +(use_list + (scoped_identifier + (identifier) @module + . + (_))) + +(use_list + (identifier) @type + (#lua-match? @type "^[A-Z]")) + +(use_as_clause + alias: (identifier) @type + (#lua-match? @type "^[A-Z]")) + +; Correct enum constructors +(call_expression + function: (scoped_identifier + "::" + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z]")) + +; Assume uppercase names in a match arm are constants. +((match_arm + pattern: (match_pattern + (identifier) @constant)) + (#lua-match? @constant "^[A-Z]")) + +((match_arm + pattern: (match_pattern + (scoped_identifier + name: (identifier) @constant))) + (#lua-match? @constant "^[A-Z]")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin "Some" "None" "Ok" "Err")) + +; Macro definitions +"$" @function.macro + +(metavariable) @function.macro + +(macro_definition + "macro_rules!" @function.macro) + +; Attribute macros +(attribute_item + (attribute + (identifier) @function.macro)) + +(inner_attribute_item + (attribute + (identifier) @function.macro)) + +(attribute + (scoped_identifier + (identifier) @function.macro .)) + +; Derive macros (assume all arguments are types) +; (attribute +; (identifier) @_name +; arguments: (attribute (attribute (identifier) @type)) +; (#eq? @_name "derive")) +; Function-like macros +(macro_invocation + macro: (identifier) @function.macro) + +(macro_invocation + macro: (scoped_identifier + (identifier) @function.macro .)) + +; Literals +(boolean_literal) @boolean + +(integer_literal) @number + +(float_literal) @number.float + +[ + (raw_string_literal) + (string_literal) +] @string + +(escape_sequence) @string.escape + +(char_literal) @character + +; Keywords +[ + "use" + "mod" +] @keyword.import + +(use_as_clause + "as" @keyword.import) + +[ + "default" + "impl" + "let" + "move" + "unsafe" + "where" +] @keyword + +[ + "enum" + "struct" + "union" + "trait" + "type" +] @keyword.type + +[ + "async" + "await" + "gen" +] @keyword.coroutine + +"try" @keyword.exception + +[ + "ref" + "pub" + "raw" + (mutable_specifier) + "const" + "static" + "dyn" + "extern" +] @keyword.modifier + +(lifetime + "'" @keyword.modifier) + +(lifetime + (identifier) @attribute) + +(lifetime + (identifier) @attribute.builtin + (#any-of? @attribute.builtin "static" "_")) + +"fn" @keyword.function + +[ + "return" + "yield" +] @keyword.return + +(type_cast_expression + "as" @keyword.operator) + +(qualified_type + "as" @keyword.operator) + +(use_list + (self) @module) + +(scoped_use_list + (self) @module) + +(scoped_identifier + [ + (crate) + (super) + (self) + ] @module) + +(visibility_modifier + [ + (crate) + (super) + (self) + ] @module) + +[ + "if" + "else" + "match" +] @keyword.conditional + +[ + "break" + "continue" + "in" + "loop" + "while" +] @keyword.repeat + +"for" @keyword + +(for_expression + "for" @keyword.repeat) + +; Operators +[ + "!" + "!=" + "%" + "%=" + "&" + "&&" + "&=" + "*" + "*=" + "+" + "+=" + "-" + "-=" + ".." + "..=" + "..." + "/" + "/=" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "?" + "@" + "^" + "^=" + "|" + "|=" + "||" +] @operator + +(use_wildcard + "*" @character.special) + +(remaining_field_pattern + ".." @character.special) + +(range_pattern + [ + ".." + "..=" + "..." + ] @character.special) + +; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(closure_parameters + "|" @punctuation.bracket) + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(bracketed_type + [ + "<" + ">" + ] @punctuation.bracket) + +(for_lifetimes + [ + "<" + ">" + ] @punctuation.bracket) + +[ + "," + "." + ":" + "::" + ";" + "->" + "=>" +] @punctuation.delimiter + +(attribute_item + "#" @punctuation.special) + +(inner_attribute_item + [ + "!" + "#" + ] @punctuation.special) + +(macro_invocation + "!" @function.macro) + +(never_type + "!" @type.builtin) + +(macro_invocation + macro: (identifier) @_identifier @keyword.exception + "!" @keyword.exception + (#eq? @_identifier "panic")) + +(macro_invocation + macro: (identifier) @_identifier @keyword.exception + "!" @keyword.exception + (#contains? @_identifier "assert")) + +(macro_invocation + macro: (identifier) @_identifier @keyword.debug + "!" @keyword.debug + (#eq? @_identifier "dbg")) + +; Comments +[ + (line_comment) + (block_comment) +] @comment @spell + +[ + (outer_doc_comment_marker) + (inner_doc_comment_marker) +] @comment.documentation + +(line_comment + (doc_comment)) @comment.documentation + +(block_comment + (doc_comment)) @comment.documentation + +(call_expression + function: (scoped_identifier + path: (identifier) @_regex + (#any-of? @_regex "Regex" "ByteRegexBuilder") + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal + (string_content) @string.regexp))) + +(call_expression + function: (scoped_identifier + path: (scoped_identifier + (identifier) @_regex + (#any-of? @_regex "Regex" "ByteRegexBuilder") .) + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal + (string_content) @string.regexp))) + +(call_expression + function: (scoped_identifier + path: (identifier) @_regex + (#any-of? @_regex "RegexSet" "RegexSetBuilder") + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (array_expression + (raw_string_literal + (string_content) @string.regexp)))) + +(call_expression + function: (scoped_identifier + path: (scoped_identifier + (identifier) @_regex + (#any-of? @_regex "RegexSet" "RegexSetBuilder") .) + name: (identifier) @_new + (#eq? @_new "new")) + arguments: (arguments + (array_expression + (raw_string_literal + (string_content) @string.regexp)))) diff --git a/bex/tag-preprocessor/queries/typescript.scm b/bex/tag-preprocessor/queries/typescript.scm new file mode 100644 index 0000000..2fb13d8 --- /dev/null +++ b/bex/tag-preprocessor/queries/typescript.scm @@ -0,0 +1,208 @@ +; inherits: ecma + +"require" @keyword.import + +(import_require_clause + source: (string) @string.special.url) + +[ + "declare" + "implements" + "type" + "override" + "module" + "asserts" + "infer" + "is" + "using" +] @keyword + +[ + "namespace" + "interface" + "enum" +] @keyword.type + +[ + "keyof" + "satisfies" +] @keyword.operator + +(as_expression + "as" @keyword.operator) + +(mapped_type_clause + "as" @keyword.operator) + +[ + "abstract" + "private" + "protected" + "public" + "readonly" +] @keyword.modifier + +; types +(type_identifier) @type + +(predefined_type) @type.builtin + +(import_statement + "type" + (import_clause + (named_imports + (import_specifier + name: (identifier) @type)))) + +(template_literal_type) @string + +(non_null_expression + "!" @operator) + +; punctuation +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +(object_type + [ + "{|" + "|}" + ] @punctuation.bracket) + +(union_type + "|" @punctuation.delimiter) + +(intersection_type + "&" @punctuation.delimiter) + +(type_annotation + ":" @punctuation.delimiter) + +(type_predicate_annotation + ":" @punctuation.delimiter) + +(index_signature + ":" @punctuation.delimiter) + +(omitting_type_annotation + "-?:" @punctuation.delimiter) + +(adding_type_annotation + "+?:" @punctuation.delimiter) + +(opting_type_annotation + "?:" @punctuation.delimiter) + +"?." @punctuation.delimiter + +(abstract_method_signature + "?" @punctuation.special) + +(method_signature + "?" @punctuation.special) + +(method_definition + "?" @punctuation.special) + +(property_signature + "?" @punctuation.special) + +(optional_parameter + "?" @punctuation.special) + +(optional_type + "?" @punctuation.special) + +(public_field_definition + [ + "?" + "!" + ] @punctuation.special) + +(flow_maybe_type + "?" @punctuation.special) + +(template_type + [ + "${" + "}" + ] @punctuation.special) + +(conditional_type + [ + "?" + ":" + ] @keyword.conditional.ternary) + +; Parameters +(required_parameter + pattern: (identifier) @variable.parameter) + +(optional_parameter + pattern: (identifier) @variable.parameter) + +(required_parameter + (rest_pattern + (identifier) @variable.parameter)) + +; ({ a }) => null +(required_parameter + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a = b }) => null +(required_parameter + (object_pattern + (object_assignment_pattern + (shorthand_property_identifier_pattern) @variable.parameter))) + +; ({ a: b }) => null +(required_parameter + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ a ]) => null +(required_parameter + (array_pattern + (identifier) @variable.parameter)) + +; a => null +(arrow_function + parameter: (identifier) @variable.parameter) + +; global declaration +(ambient_declaration + "global" @module) + +; function signatures +(ambient_declaration + (function_signature + name: (identifier) @function)) + +; method signatures +(method_signature + name: (_) @function.method) + +(abstract_method_signature + name: (property_identifier) @function.method) + +; property signatures +(property_signature + name: (property_identifier) @function.method + type: (type_annotation + [ + (union_type + (parenthesized_type + (function_type))) + (function_type) + ])) diff --git a/references/tags-queries/ANALYSIS.md b/references/tags-queries/ANALYSIS.md index 0fb9dd0..bfc2597 100644 --- a/references/tags-queries/ANALYSIS.md +++ b/references/tags-queries/ANALYSIS.md @@ -1,81 +1,212 @@ -# TreeSitter Tag Queries for Dervish +# Community Tree-Sitter Query Analysis -## What We Got - -Queries from 8 official TreeSitter language packages (`references/tags-queries/*.scm`): - -| Language | TAGS_QUERY | HIGHLIGHTS_QUERY | Tag nodes | Dervish-relevant | -|----------|-----------|-----------------|-----------|-----------------| -| Java | ✅ 20 lines | ✅ 60 lines | `class_declaration`, `method_declaration`, `method_invocation`, `annotation` | `annotation`, `marker_annotation`, `method_invocation` | -| Python | ✅ 14 lines | ✅ 50 lines | `class_definition`, `function_definition`, `call`, `assignment` | `call`, `decorator` | -| TypeScript | ✅ 23 lines | ✅ 30 lines | `function_signature`, `interface_declaration`, `method_signature` | (none directly) | -| Go | ✅ 42 lines | ✅ 55 lines | `function_declaration`, `call_expression`, `method_declaration` | `call_expression` | -| C# | empty | ✅ | — | — | -| C++ | ✅ 15 lines | ✅ 40 lines | `struct_specifier`, `function_declarator` | `call_expression` | -| Rust | ✅ 60 lines | ✅ 80 lines | `struct_item`, `function_item`, `call_expression`, `macro_invocation` | `call_expression`, `macro_invocation` | -| YAML | — | ✅ 30 lines | — | — | +Analyzed: July 3, 2026 +Source: nvim-treesitter (master branch) tag queries + highlight queries ## Key Finding -**Community TAGS_QUERIES are for code navigation (Go to Definition), NOT for Dervish.** +**Community TAGS queries are for code navigation (Go to Definition), NOT for Dervish.** -They capture: -- `@definition.class` — where classes are declared -- `@definition.method` — where methods are declared -- `@reference.call` — where methods are CALLED (this IS useful for us) +Dervish needs **behavioral sequences**: what operations happen in what order. +Tags queries only capture declaration sites and reference locations. -## Dervish Needs Behavioral Nodes +## Language-by-Language Gap Analysis -From actual code parsing tests, these node types exist across languages: +### JAVA -| Pattern | Java | Python | Go | Rust | -|---------|------|--------|----|------| -| Function calls | `method_invocation` | `call` | `call_expression` | `call_expression` | -| Annotations | `annotation`, `marker_annotation` | `decorator` | — | `macro_invocation` | -| Conditionals | `if_statement` | `if_statement` | `if_statement` | `if_expression` | -| Error throwing | `throw_statement` | `raise_statement` | `return`-based | `return`-based | -| Error handling | `try_statement` | `try_statement` | — | — | -| Variable decl | `local_variable_declaration` | `assignment` | `short_var_declaration` | `let_declaration` | -| Returns | `return_statement` | `return_statement` | `return_statement` | `return` (no _statement) | +**Tags captures:** +- `@definition.class` — class declaration sites +- `@definition.method` — method declaration sites +- `@definition.interface` — interface declaration sites +- `@reference.call` — method invocations (ONLY with `argument_list`) +- `@reference.implementation` — implements clauses +- `@reference.class` — `new Type()` expressions + superclass refs -## Universal Query Approach (Confirmed Viable) +**What is MISSING for Dervish:** +- `@annotation` / `@decorator` — annotations only exist in highlights as `@attribute`, not in tags +- `@reference.call` excludes parameterless calls like `foo()` — requires `argument_list` +- No `throw_statement`, `try_statement`, `catch_clause` in tags +- No `if_statement`, `return_statement` captures +- No mechanism to extract ORDERED sequences +- Highlights collapse all control-flow keywords into `@keyword` -TreeSitter silently ignores non-existent node types in queries. One query for all languages: +### KOTLIN (from highlights.scm since no tags.scm exists at that path) -```scheme -; === CALLS (all imperative langs) === -(call_expression) @call ; Go, Rust, C++, TS/JS -(call) @call ; Python -(method_invocation) @call ; Java +**Available captures (highlights only):** +- `@function.call` — `call_expression` with `simple_identifier` +- `@constructor` — `constructor_invocation`, `primary_constructor`, secondary +- `@attribute` — `annotation` with `user_type` +- `@keyword.conditional` — `if`/`else`/`when` +- `@keyword.repeat` — `for`/`do`/`while` +- `@keyword.exception` — `try`/`catch`/`throw`/`finally` +- `@keyword.return` — `return` +- `@function` — `function_declaration` -; === METADATA === -(annotation) @meta ; Java, C#, Kotlin -(marker_annotation) @meta ; Java -(decorator) @meta ; Python -(macro_invocation) @meta ; Rust macros +**What is MISSING for Dervish:** +- No tags.scm available on nvim-treesitter master for Kotlin +- Call expressions captured as `@function.call` in highlights, not structured for sequence extraction +- Navigation expressions (`obj.method()`) captured but as `@function.call` on the suffix +- No `when_structure` / `when_condition` structural capture +- No `navigation_expression` itself as a token — only the method name inside +- No sequencing mechanism -; === CONTROL FLOW === -(if_statement) @branch ; Java, Go, Python, C++ -(if_expression) @branch ; Rust -(throw_statement) @throw ; Java, C++, C# -(raise_statement) @throw ; Python -(try_statement) @try ; Java, Python, C++, TS/JS -(catch_clause) @catch ; Java, C++, TS/JS -(except_clause) @catch ; Python -(return_statement) @return ; Java, Go, Python, C++ +### PYTHON -; === RESOURCE MANAGEMENT === -(with_statement) @resource ; Python, TS/JS -(defer_statement) @resource ; Go +**Tags captures:** +- `@definition.constant` — module-level assignments +- `@definition.class` — class definitions +- `@definition.function` — function definitions +- `@reference.call` — direct function calls + method calls via attribute -; === OBJECT CREATION === -(object_creation_expression) @new ; Java, C++ -(new_expression) @new ; TS/JS -``` +**What is MISSING for Dervish:** +- No `decorator` capture in tags (only in highlights as `@function`) +- `call` only captured as reference, not as behavioral sequence token +- No `raise_statement`, `try_statement`, `except_clause` in tags +- No `if_statement`, `return_statement`, `with_statement` in tags +- Highlights `@function` conflates decorators, definitions, and calls -## Next Steps +### GO -1. Implement TreeSitter parser wrapper that loads correct grammar by file extension -2. Apply the universal query to extract symbol sequences -3. Add single-pass frequency analysis to filter noise -4. Feed cleaned sequences into Dervish (CRX/iDRegEx) +**Tags captures:** +- `@definition.function` — function declarations (with doc comments) +- `@definition.method` — method declarations +- `@definition.type` — type specs +- `@reference.call` — direct calls + selector calls (`obj.Method()`) +- `@reference.type` — type identifier references +- Plus: var/const/import/struct/interface tracking + +**What is MISSING for Dervish:** +- No `defer_statement` capture (only `defer` keyword in highlights) +- No `go` (goroutine launch) as structural capture +- No `if_statement`, `return_statement`, `for_statement`, `switch_statement` in tags +- `call_expression` well captured but only function name as `@name`, not whole expression +- Highlights distinguish builtins (`append`, `len`, `make`, `panic`, etc.) but not structured + +### RUST + +**Tags captures:** +- `@definition.class` — struct/enum/union/type alias +- `@definition.method` — methods in impl blocks +- `@definition.function` — free functions +- `@definition.interface` — trait definitions +- `@definition.module` — module definitions +- `@definition.macro` — macro definitions +- `@reference.call` — direct calls + method calls + macro invocations +- `@reference.implementation` — trait/inherent impl tracking + +**What is MISSING for Dervish:** +- Best coverage of any language — captures calls, macros, implementations +- Still: no `if_expression` / `match_expression` / `return` in tags +- No `unsafe` block capture +- `@attribute` (`#[derive]`) only in highlights, not tags +- No sequencing mechanism + +### TYPESCRIPT / JAVASCRIPT + +**Tags captures:** +- `@definition.function` — function signatures only (definitions) +- `@definition.method` — method signatures +- `@definition.class` — class + abstract class declarations +- `@definition.module` — module declarations +- `@definition.interface` — interface declarations +- `@reference.type` — type annotations +- `@reference.class` — `new Foo()` constructor calls + +**What is MISSING for Dervish:** +- **NO `call_expression` capture at all** — neither in tags nor highlights +- **NO `@reference.call`** — critical gap +- No function/method call tracking +- Highlight query is extremely minimal (35 lines) +- Missing: `arrow_function`, `call_expression`, `method_invocation` +- Query file seems designed for `.d.ts` type definitions, not implementation code + +### C++ + +**Tags captures:** +- `@definition.class` — struct/union/class specifiers +- `@definition.function` — function declarators +- `@definition.method` — qualified methods (with namespace scope) +- `@definition.type` — typedef/enum + +**What is MISSING for Dervish:** +- **NO `call_expression` capture in tags** — call tracking only in highlights as `@function` +- **NO `@reference.call`** in tags at all +- No `template_function`, `template_method` in tags +- No `new_expression`, `delete_expression` in tags +- No `throw_statement`, `try_statement`, `catch_clause` in tags +- No sequencing mechanism + +### YAML + +**What is MISSING for Dervish:** +- No tags query exists at all +- YAML is data-oriented, not code-oriented +- Highlights only capture data types (strings, numbers, booleans) and key names +- YAML sequence extraction (for Ansible/Helm) needs a different approach entirely + +## Cross-Cutting Findings + +### What community tags DO capture (for Dervish, partially useful): + +| Capture | Languages | Dervish Value | +|---------|-----------|--------------| +| `@reference.call` | Java, Python, Go, Rust | **Partial** — identifies call sites but per-language inconsistencies | +| `@reference.class` / `new` | Java, TypeScript | **Partial** — constructor calls | +| `@reference.implementation` | Java, Rust | Low — inheritance tracking | +| macro invocations (as `@reference.call`) | Rust | **Useful** — Rust macros ARE behavioral tokens | + +### What community tags do NOT capture (GAPS): + +| Dervish Need | In Tags? | In Highlights? | +|-------------|----------|---------------| +| `@annotation` / `@decorator` / `@attribute` | **0 languages** | Java `@attribute`, Python `@function` (decorator), Rust `@attribute`, Kotlin `@attribute` | +| Control flow (`if`/`else`/`when`) | **0 languages** | All: collapsed in `@keyword` | +| Error handling (`try`/`catch`/`throw`) | **0 languages** | All: collapsed in `@keyword` | +| `@return` | **0 languages** | All: collapsed in `@keyword` | +| Call expressions | Java, Python, Go, Rust | All except TS | +| Ordered sequences | **0 languages** | **0 languages** | +| Variable declarations | Go only | Not structural | +| Resource management (`defer`/`with`) | **0 languages** | Go: `defer` in keyword; Python: `with` in keyword | +| Goroutines / async / coroutines | **0 languages** | Go `go` in keyword; Python async/await in keyword; Kotlin `suspend` as `@keyword.coroutine` | + +### The Naming Inconsistency Problem + +Same tree-sitter node types have DIFFERENT capture names across languages: + +| Node | Java | Python | Go | Rust | C++ | TS | +|------|------|--------|----|------|-----|----| +| call expr | `@reference.call` | `@reference.call` | `@reference.call` | `@reference.call` | NONE | NONE | +| class def | `@definition.class` | `@definition.class` | -- | `@definition.class` | `@definition.class` | `@definition.class` | +| function def | -- | `@definition.function` | `@definition.function` | `@definition.function` | `@definition.function` | `@definition.function` | + +Dervish cannot rely on capture names alone. Must either: +1. Use universal query with Dervish-specific capture names, OR +2. Map language-specific capture names to canonical Dervish vocabulary + +### Community tags.scm availability on nvim-treesitter master + +Checked July 3, 2026 via `raw.githubusercontent.com/nvim-treesitter/nvim-treesitter/master/queries//tags.scm`: + +| Language | tags.scm exists? | highlights.scm? | +|----------|-----------------|-----------------| +| Java | 404 | yes (in refs) | +| Kotlin | 404 | yes (newly downloaded) | +| Python | 404 | yes (in refs) | +| Go | 404 | yes (in refs) | +| Rust | 404 | yes (in refs) | +| TypeScript | 404 | yes (in refs) | +| C++ | 404 | yes (in refs) | +| YAML | never | yes (in refs) | + +All tags.scm returned 404 — nvim-treesitter may have restructured or moved to a different branch/tag. + +## Verdict + +**Community queries alone are insufficient for Dervish sequence extraction.** They: +1. Purpose-built for navigation, not behavioral sequence extraction +2. Lack critical behavioral captures (annotations, control flow, error handling) +3. Inconsistent across languages +4. No sequencing/traversal mechanism +5. tags.scm no longer available on nvim-treesitter master + +A **universal query file** (like the deleted `universal.scm`) using actual tree-sitter node type names is the correct approach, supplemented by a custom AST traversal to produce ordered sequences.