Skip to content

Commit 057aa13

Browse files
committedDec 11, 2024·
Tree-Sitter queries moved to folder structure for better organization
1 parent 17a2e51 commit 057aa13

File tree

12 files changed

+977
-1089
lines changed

12 files changed

+977
-1089
lines changed
 

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ version_scheme = "post-release"
6464

6565
[tool.setuptools.packages.find]
6666
where = ["src"]
67-
include = ["version", "cedarscript_editor*", "text_manipulation*"]
67+
include = ["version", "tree-sitter-queries", "cedarscript_editor*", "text_manipulation*"]
6868
exclude = ["cedarscript_ast_parser.tests*"]
6969
namespaces = false
7070

‎src/cedarscript_editor/tree_sitter_identifier_finder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from text_manipulation import IdentifierFinder
1111
from tree_sitter_languages import get_language, get_parser
1212
from pylibtreesitter import nodes_by_type_suffix
13-
from .tree_sitter_identifier_queries import LANG_TO_TREE_SITTER_QUERY
13+
from .tree_sitter_identifier_queries import get_query
1414

1515
"""
1616
Parser for extracting identifier information from source code using tree-sitter.
@@ -48,7 +48,7 @@ def __init__(self, fname: str, source: str | Sequence[str], parent_restriction:
4848
self.query_info = None
4949
_log.info(f"[TreeSitterIdentifierFinder] NO LANGUAGE for `{fname}`")
5050
return
51-
self.query_info: dict[str, dict[str, str]] = LANG_TO_TREE_SITTER_QUERY[langstr]
51+
self.query_info: dict[str, str] = get_query(langstr)
5252
self.language = get_language(langstr)
5353
_log.info(f"[TreeSitterIdentifierFinder] Selected {self.language}")
5454
self.tree = get_parser(langstr).parse(bytes(source, "utf-8"))

‎src/cedarscript_editor/tree_sitter_identifier_queries.py

+17-1,086
Large diffs are not rendered by default.

‎src/tree-sitter-queries/TODO/TODO.txt

+845
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: (simple_identifier) @_{type}_name
2+
(#match? @_{type}_name "^{{name}}$")
3+
(#set! role name)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; Regular class definitions with optional annotations and KDoc
2+
(class_declaration
3+
(modifiers (annotation) )* @class.decorator
4+
(comment)? @class.docstring
5+
["data" "enum"]? @class.subtype
6+
{definition_base}
7+
body: (class_body) @class.body
8+
) @class.definition
9+
10+
; Interface definitions
11+
(interface_declaration
12+
(modifiers (annotation) @class.decorator)*
13+
(comment)? @class.docstring
14+
name: (type_identifier) @_class_name
15+
(#match? @_class_name "^{{name}}$")
16+
(#set! role name)
17+
body: (class_body) @class.body
18+
) @class.definition
19+
20+
; Object declarations
21+
(object_declaration
22+
(modifiers (annotation) @class.decorator)*
23+
(comment)? @class.docstring
24+
name: (type_identifier) @_class_name
25+
(#match? @_class_name "^{{name}}$")
26+
(#set! role name)
27+
body: (class_body) @class.body
28+
) @class.definition

‎src/tree-sitter-queries/kotlin/common.scm

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function_declaration
2+
(comment)? @function.docstring
3+
(modifiers (annotation) )* @function.decorator
4+
(receiver_type: (type_reference))? @function.receiver
5+
(comment)? @function.docstring
6+
{definition_base}
7+
(type_parameters: (type_parameters))? @function.type_parameters
8+
body: (function_body) @function.body
9+
) @function.definition
10+
11+
; Constructor definitions
12+
(constructor_declaration
13+
(modifiers (annotation) )* @function.decorator
14+
(comment)? @function.docstring
15+
body: (function_body) @function.body
16+
) @function.definition
17+
18+
; Lambda expressions
19+
(lambda_literal
20+
body: (_) @function.body
21+
) @function.definition
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: (identifier) @_{type}_name
2+
(#match? @_{type}_name "^{{name}}$")
3+
(#set! role name)
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; Class Definitions
2+
(class_definition
3+
{definition_base}
4+
{common_body}
5+
) @class.definition
6+
7+
; Decorated Class Definitions
8+
(decorated_definition
9+
(decorator)+ @class.decorator
10+
(class_definition
11+
{definition_base}
12+
{common_body}
13+
) @class.definition
14+
)
15+
16+
; Nested Classes
17+
(class_definition
18+
body: (block
19+
(class_definition
20+
{definition_base}
21+
{common_body}
22+
) @class.definition
23+
)
24+
)
25+
26+
; Decorated Nested Classes
27+
(class_definition
28+
body: (block
29+
(decorated_definition
30+
(decorator)+ @class.decorator
31+
(class_definition
32+
{definition_base}
33+
{common_body}
34+
) @class.definition
35+
)
36+
)
37+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; Common pattern for body and docstring capture
2+
body: (block
3+
.
4+
(expression_statement
5+
(string) @{type}.docstring)?
6+
) @{type}.body
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; Function Definitions
2+
(function_definition
3+
{definition_base}
4+
{common_body}
5+
) @function.definition
6+
7+
; Decorated Function Definitions
8+
(decorated_definition
9+
(decorator)+ @function.decorator
10+
(function_definition
11+
{definition_base}
12+
{common_body}
13+
) @function.definition
14+
)

0 commit comments

Comments
 (0)
Please sign in to comment.