2020 CommentType .cpp : {"function_definition" , "class_definition" },
2121 CommentType .cs : {"method_declaration" , "class_declaration" , "property_declaration" },
2222 CommentType .yaml : {"block_mapping_pair" , "block_sequence_item" , "document" },
23+ # @Rust Scope Node Types, IMPL_RUST_2, impl, [FE_RUST];
24+ CommentType .rust : {
25+ "function_item" ,
26+ "struct_item" ,
27+ "enum_item" ,
28+ "impl_item" ,
29+ "trait_item" ,
30+ "mod_item" ,
31+ },
2332}
2433
2534# initialize logger
4756CPP_QUERY = """(comment) @comment"""
4857C_SHARP_QUERY = """(comment) @comment"""
4958YAML_QUERY = """(comment) @comment"""
59+ RUST_QUERY = """
60+ (line_comment) @comment
61+ (block_comment) @comment
62+ """
5063
5164
5265def is_text_file (filepath : Path , sample_size : int = 2048 ) -> bool :
@@ -64,7 +77,7 @@ def is_text_file(filepath: Path, sample_size: int = 2048) -> bool:
6477 return False
6578
6679
67- # @Tree-sitter parser initialization for multiple languages, IMPL_LANG_1, impl, [FE_C_SUPPORT, FE_CPP, FE_PY, FE_YAML]
80+ # @Tree-sitter parser initialization for multiple languages, IMPL_LANG_1, impl, [FE_C_SUPPORT, FE_CPP, FE_PY, FE_YAML, FE_RUST ]
6881def init_tree_sitter (comment_type : CommentType ) -> tuple [Parser , Query ]:
6982 if comment_type == CommentType .cpp :
7083 import tree_sitter_cpp # noqa: PLC0415
@@ -86,6 +99,11 @@ def init_tree_sitter(comment_type: CommentType) -> tuple[Parser, Query]:
8699
87100 parsed_language = Language (tree_sitter_yaml .language ())
88101 query = Query (parsed_language , YAML_QUERY )
102+ elif comment_type == CommentType .rust :
103+ import tree_sitter_rust # noqa: PLC0415
104+
105+ parsed_language = Language (tree_sitter_rust .language ())
106+ query = Query (parsed_language , RUST_QUERY )
89107 else :
90108 raise ValueError (f"Unsupported comment style: { comment_type } " )
91109 parser = Parser (parsed_language )
0 commit comments