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

Class GoParser

src/codetext/parser/go_parser.py:10–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class GoParser(LanguageParser):
11
12 BLACKLISTED_FUNCTION_NAMES = ['test', 'vendor']
13
14 @staticmethod
15 def get_comment_node(function_node):
16 """
17 Return all comment node inside a parent node
18 Args:
19 node (tree_sitter.Node)
20 Return:
21 List: list of comment nodes
22 """
23 comment_node = get_node_by_kind(function_node, kind='comment')
24 return comment_node
25
26 @staticmethod
27 def get_docstring_node(node):
28 """
29 Get docstring node from it parent node.
30 Go's docstring is written line by line
31
32 Args:
33 node (tree_sitter.Node): parent node (usually function node) to get its docstring
34 Return:
35 List: list of docstring nodes
36 Example:
37 str = '''
38 // The path package should only be used for paths separated by forward
39 // slashes, such as the paths in URLs. This package does not deal with
40 // Windows paths with drive letters or backslashes; to manipulate
41 // operating system paths, use the [path/filepath] package.
42 func (e TypeError) Error() string {
43 ...
44 }
45 '''
46 ...
47 print(GoParser.get_docstring_node(function_node))
48
49 >>> [<Node type=comment, start_point=(x, y), end_point=(x, y)>, \
50 <Node type=comment, start_point=(x, y), end_point=(x, y)>, \
51 <Node type=comment, start_point=(x, y), end_point=(x, y)>, \
52 <Node type=comment, start_point=(x, y), end_point=(x, y)>]
53 """
54 docstring_node = []
55
56 prev_node = node.prev_sibling
57 if prev_node and prev_node.type == 'comment':
58 docstring_node.append(prev_node)
59 prev_node = prev_node.prev_sibling
60
61 while prev_node and prev_node.type == 'comment':
62 # Assume the comment is dense
63 x_current = prev_node.start_point[0]
64 x_next = prev_node.next_sibling.start_point[0]
65 if x_next - x_current > 1:
66 break
67

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected