Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions packages/rbtr/src/rbtr/languages/c.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""C language plugin.

Provides symbol extraction (functions, structs, enums) and
include directive capture.
Provides symbol extraction (functions, function prototypes, structs,
unions, enums, typedefs, global variables, and function/object-like
macros) and include directive capture. Object-like macros and
pointer-declared globals are variables; function-like macros and
prototypes are functions.

Extracted chunks::

Expand Down Expand Up @@ -34,18 +37,55 @@
path: (string_literal) @_import_module) @import

(struct_specifier
name: (type_identifier) @_cls_name) @class
name: (type_identifier) @_cls_name
body: (field_declaration_list)) @class

(union_specifier
name: (type_identifier) @_cls_name
body: (field_declaration_list)) @class

(enum_specifier
name: (type_identifier) @_cls_name) @class
name: (type_identifier) @_cls_name
body: (enumerator_list)) @class

(enumerator
name: (identifier) @_var_name) @variable

(type_definition
declarator: (type_identifier) @_cls_name) @class

(type_definition
declarator: (function_declarator
declarator: (parenthesized_declarator
(pointer_declarator
declarator: (type_identifier) @_cls_name)))) @class

(preproc_function_def
name: (identifier) @_fn_name) @function

(preproc_def
name: (identifier) @_var_name) @variable

(translation_unit
(declaration
declarator: (function_declarator
declarator: (identifier) @_fn_name)) @function)

(translation_unit
(declaration
declarator: (init_declarator
declarator: (identifier) @_var_name)) @variable)

(translation_unit
(declaration
declarator: (pointer_declarator
declarator: (identifier) @_var_name)) @variable)

(translation_unit
(declaration
declarator: (init_declarator
declarator: (pointer_declarator
declarator: (identifier) @_var_name))) @variable)
"""

# ── Plugin ───────────────────────────────────────────────────────────
Expand All @@ -68,6 +108,6 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
doc_comment_node_types=frozenset({"comment"}),
source_roots=("", "include", "src"),
test_prefix="test_",
language_plugin_version=2,
language_plugin_version=3,
),
]
83 changes: 78 additions & 5 deletions packages/rbtr/src/rbtr/languages/cpp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""C++ language plugin.

Provides symbol extraction (functions, classes, structs, enums,
methods) and include directive capture.
Provides symbol extraction (functions, prototypes, classes, structs,
unions, enums, type aliases, namespaces, methods including operator
overloads, namespace/global variables, and function/object-like
macros) and include directive capture. Namespaces are both a symbol
(class) and a naming scope.

Extracted chunks::

Expand Down Expand Up @@ -31,31 +34,101 @@ class Foo {
declarator: (function_declarator
declarator: (field_identifier) @_fn_name)) @function

(function_definition
declarator: (function_declarator
declarator: (operator_name) @_fn_name)) @function

(field_declaration
declarator: (function_declarator
declarator: (field_identifier) @_method_name)) @method

(field_declaration_list
(declaration
declarator: (function_declarator
declarator: (identifier) @_method_name)) @method)

(preproc_include
path: (system_lib_string) @_import_module) @import

(preproc_include
path: (string_literal) @_import_module) @import

(preproc_function_def
name: (identifier) @_fn_name) @function

(preproc_def
name: (identifier) @_var_name) @variable

(class_specifier
name: (type_identifier) @_cls_name) @class
name: (type_identifier) @_cls_name
body: (field_declaration_list)) @class

(struct_specifier
name: (type_identifier) @_cls_name) @class
name: (type_identifier) @_cls_name
body: (field_declaration_list)) @class

(union_specifier
name: (type_identifier) @_cls_name
body: (field_declaration_list)) @class

(enum_specifier
name: (type_identifier) @_cls_name
body: (enumerator_list)) @class

(alias_declaration
name: (type_identifier) @_cls_name) @class

(namespace_definition
name: (namespace_identifier) @_cls_name) @class

(concept_definition
name: (identifier) @_cls_name) @class

(translation_unit
(declaration
declarator: (function_declarator
declarator: (identifier) @_fn_name)) @function)

(namespace_definition
body: (declaration_list
(declaration
declarator: (function_declarator
declarator: (identifier) @_fn_name)) @function))

(translation_unit
(declaration
declarator: (init_declarator
declarator: (identifier) @_var_name)) @variable)

(translation_unit
(declaration
declarator: (pointer_declarator
declarator: (identifier) @_var_name)) @variable)

(translation_unit
(declaration
declarator: (init_declarator
declarator: (pointer_declarator
declarator: (identifier) @_var_name))) @variable)

(namespace_definition
body: (declaration_list
(declaration
declarator: (init_declarator
declarator: (identifier) @_var_name)) @variable))

(namespace_definition
body: (declaration_list
(declaration
declarator: (pointer_declarator
declarator: (identifier) @_var_name)) @variable))

(namespace_definition
body: (declaration_list
(declaration
declarator: (init_declarator
declarator: (pointer_declarator
declarator: (identifier) @_var_name))) @variable))
"""

# ── Plugin ───────────────────────────────────────────────────────────
Expand All @@ -80,6 +153,6 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
doc_comment_node_types=frozenset({"comment"}),
source_roots=("", "include", "src"),
test_prefix="test_",
language_plugin_version=4,
language_plugin_version=5,
),
]
21 changes: 18 additions & 3 deletions packages/rbtr/src/rbtr/languages/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,35 @@
name: (identifier) @_fn_name) @function

(method_declaration
receiver: (parameter_list
(parameter_declaration
type: [
(type_identifier) @_scope
(pointer_type (type_identifier) @_scope)
]))
name: (field_identifier) @_method_name) @method

(type_declaration
(type_spec
name: (type_identifier) @_cls_name)) @class

(type_spec
(interface_type
(method_elem
name: (field_identifier) @_method_name) @method))

(type_declaration
(type_alias
name: (type_identifier) @_cls_name)) @class

(import_declaration
(import_spec
path: (interpreted_string_literal) @_import_module)) @import
path: (interpreted_string_literal) @_import_module) @import)

(import_declaration
(import_spec_list
(import_spec
path: (interpreted_string_literal) @_import_module))) @import
path: (interpreted_string_literal) @_import_module) @import))

(source_file
(var_declaration
Expand Down Expand Up @@ -85,6 +100,6 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
# type for both line and block forms.
doc_comment_node_types=frozenset({"comment"}),
test_suffix="_test",
language_plugin_version=2,
language_plugin_version=3,
),
]
46 changes: 44 additions & 2 deletions packages/rbtr/src/rbtr/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,43 @@ class Service {
(method_declaration
name: (identifier) @_method_name) @method

(constructor_declaration
name: (identifier) @_method_name) @method

(field_declaration
declarator: (variable_declarator
name: (identifier) @_var_name)) @variable

(class_declaration
name: (identifier) @_cls_name) @class

(interface_declaration
name: (identifier) @_cls_name) @class

(enum_declaration
name: (identifier) @_cls_name) @class

(enum_declaration
body: (enum_body
(enum_constant
name: (identifier) @_var_name) @variable))

(record_declaration
name: (identifier) @_cls_name) @class

(record_declaration
parameters: (formal_parameters
(formal_parameter
name: (identifier) @_var_name) @variable))

(annotation_type_declaration
name: (identifier) @_cls_name) @class

(annotation_type_declaration
body: (annotation_type_body
(annotation_type_element_declaration
name: (identifier) @_method_name) @method))

(import_declaration
(scoped_identifier) @_import_module) @import
"""
Expand All @@ -53,14 +87,22 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
extensions=frozenset({".java"}),
grammar_module="tree_sitter_java",
query=_QUERY,
scope_types=frozenset({"class_declaration"}),
scope_types=frozenset(
{
"class_declaration",
"interface_declaration",
"enum_declaration",
"record_declaration",
"annotation_type_declaration",
}
),
# Javadoc uses `block_comment`; `//` runs use
# `line_comment`. Attach either when they sit
# directly above a method or class.
doc_comment_node_types=frozenset({"block_comment", "line_comment"}),
source_roots=("", "src/main/java"),
test_suffix="Test",
module_style=ModuleStyle.DOTTED,
language_plugin_version=2,
language_plugin_version=3,
),
]
37 changes: 32 additions & 5 deletions packages/rbtr/src/rbtr/languages/rust.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Rust language plugin.

Provides full support: functions, structs, enums, impl blocks,
and `use` declaration extraction.
Provides full support: functions, structs, enums, unions, type
aliases, traits, modules, impl blocks, `macro_rules!` definitions,
and `use` declaration extraction. Traits, modules, and impl blocks
form naming scopes; trait and impl members are methods.

Extracted chunks::

Expand Down Expand Up @@ -36,12 +38,35 @@
(function_item
name: (identifier) @_fn_name) @function

(function_signature_item
name: (identifier) @_fn_name) @function

(struct_item
name: (type_identifier) @_cls_name) @class

(enum_item
name: (type_identifier) @_cls_name) @class

(enum_item
body: (enum_variant_list
(enum_variant
name: (identifier) @_var_name) @variable))

(union_item
name: (type_identifier) @_cls_name) @class

(type_item
name: (type_identifier) @_cls_name) @class

(trait_item
name: (type_identifier) @_cls_name) @class

(mod_item
name: (identifier) @_cls_name) @class

(macro_definition
name: (identifier) @_fn_name) @function

(impl_item
type: (type_identifier) @_cls_name) @class

Expand Down Expand Up @@ -160,8 +185,10 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
grammar_module="tree_sitter_rust",
query=_QUERY,
import_extractor=extract_import_meta,
scope_types=frozenset({"impl_item", "struct_item", "mod_item"}),
class_scope_types=frozenset({"impl_item", "struct_item"}),
scope_types=frozenset(
{"impl_item", "struct_item", "trait_item", "mod_item", "enum_item"}
),
class_scope_types=frozenset({"impl_item", "struct_item", "trait_item"}),
# Rust splits doc comments (`///`, `//!`) from
# regular line/block comments at parse time by
# wrapping them in distinct grammar rules, but
Expand All @@ -172,6 +199,6 @@ def rbtr_register_languages(self) -> list[LanguageRegistration]:
index_files=frozenset({"mod.rs"}),
path_substitutions=(("crate/", "src/"),),
test_prefix="test_",
language_plugin_version=3,
language_plugin_version=4,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"c.c::#include \"greeter.h\" -> greeter.h::GREETER_H [imports]",
"c.c::#include \"greeter.h\" -> greeter.h::Greeter [imports]",
"c.c::#include \"greeter.h\" -> greeter.h::Greeter [imports]",
"c.c::#include \"greeter.h\" -> greeter.h::MAX_NAME [imports]"
]
Loading