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

Class RubyParser

src/codetext/parser/ruby_parser.py:14–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class RubyParser(LanguageParser):
15
16 FILTER_PATHS = ('test', 'vendor')
17
18 BLACKLISTED_FUNCTION_NAMES = ['initialize', 'to_text', 'display', 'dup', 'clone', 'equal?', '==', '<=>',
19 '===', '<=', '<', '>', '>=', 'between?', 'eql?', 'hash']
20
21 @staticmethod
22 def get_function_list(node):
23 res = get_node_by_kind(node, ['method',
24 'singleton_method'])
25 return res
26
27 @staticmethod
28 def get_class_list(node):
29 res = get_node_by_kind(node, ['class', 'module'])
30
31 # remove class keywords
32 for node in res[:]:
33 if not node.children:
34 res.remove(node)
35
36 return res
37
38 @staticmethod
39 def get_docstring_node(node) -> str:
40 docstring_node = []
41
42 prev_node = node.prev_sibling
43 if not prev_node or prev_node.type != 'comment':
44 parent_node = node.parent
45 if parent_node:
46 prev_node = parent_node.prev_sibling
47
48 if prev_node and prev_node.type == 'comment':
49 docstring_node.append(prev_node)
50 prev_node = prev_node.prev_sibling
51
52 while prev_node and prev_node.type == 'comment':
53 # Assume the comment is dense
54 x_current = prev_node.start_point[0]
55 x_next = prev_node.next_sibling.start_point[0]
56 if x_next - x_current > 1:
57 break
58
59 docstring_node.insert(0, prev_node)
60 prev_node = prev_node.prev_sibling
61
62 return docstring_node
63
64 @staticmethod
65 def get_docstring(node, blob=None):
66 if blob:
67 logger.info('From version `0.0.6` this function will update argument in the API')
68 docstring_node = RubyParser.get_docstring_node(node)
69 docstring = []
70 for item in docstring_node:
71 doc = get_node_text(item)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected