MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / RustParser

Class RustParser

src/codetext/parser/rust_parser.py:13–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class RustParser(LanguageParser):
14
15 FILTER_PATHS = ('test', 'vendor')
16
17 BLACKLISTED_FUNCTION_NAMES = ['main']
18
19 @staticmethod
20 def get_function_list(node):
21 res = get_node_by_kind(node, ['function_item'])
22 return res
23
24 @staticmethod
25 def get_class_list(node):
26 res = get_node_by_kind(node, ['impl_item', 'mod_item']) # trait is like an interface
27 return res
28
29 @staticmethod
30 def get_docstring_node(node) -> List:
31 docstring_node = []
32
33 prev_node = node.prev_sibling
34 if prev_node:
35 if prev_node.type == 'block_comment':
36 docstring_node.append(prev_node)
37
38 elif prev_node.type == 'line_comment':
39 docstring_node.append(prev_node)
40 prev_node = prev_node.prev_sibling
41
42 while prev_node and prev_node.type == 'line_comment':
43 # Assume the comment is dense
44 x_current = prev_node.start_point[0]
45 x_next = prev_node.next_sibling.start_point[0]
46 if x_next - x_current > 1:
47 break
48
49 docstring_node.insert(0, prev_node)
50 prev_node = prev_node.prev_sibling
51
52 return docstring_node
53
54 @staticmethod
55 def get_docstring(node, blob=None):
56 if blob:
57 logger.info('From version `0.0.6` this function will update argument in the API')
58 docstring_node = RustParser.get_docstring_node(node)
59 docstring = []
60 if docstring_node:
61 for item in docstring_node:
62 doc = get_node_text(item)
63 docstring.append(doc)
64
65 docstring = '\n'.join(docstring)
66 return docstring
67
68 @staticmethod
69 def get_function_metadata(function_node, blob=None) -> Dict[str, str]:
70 if blob:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected