| 9 | |
| 10 | |
| 11 | class CppParser(LanguageParser): |
| 12 | |
| 13 | BLACKLISTED_FUNCTION_NAMES = ['main', 'constructor'] |
| 14 | |
| 15 | @staticmethod |
| 16 | def get_docstring(node, blob=None): |
| 17 | """ |
| 18 | Get docstring description for node |
| 19 | |
| 20 | Args: |
| 21 | node (tree_sitter.Node) |
| 22 | blob (str): original source code which parse the `node` |
| 23 | Returns: |
| 24 | str: docstring |
| 25 | """ |
| 26 | if blob: |
| 27 | logger.info('From version `0.0.6` this function will update argument in the API') |
| 28 | docstring_node = CppParser.get_docstring_node(node) |
| 29 | docstring = '\n'.join(get_node_text(s) for s in docstring_node) |
| 30 | return docstring |
| 31 | |
| 32 | @staticmethod |
| 33 | def get_docstring_node(node): |
| 34 | """ |
| 35 | Get docstring node from it parent node. |
| 36 | C and C++ share the same syntax. Their docstring usually is 1 single block |
| 37 | Expect length of return list == 1 |
| 38 | |
| 39 | Args: |
| 40 | node (tree_sitter.Node): parent node (usually function node) to get its docstring |
| 41 | Return: |
| 42 | List: list of docstring nodes (expect==1) |
| 43 | Example: |
| 44 | str = ''' |
| 45 | /** |
| 46 | * Find 2 sum |
| 47 | * |
| 48 | * @param nums List number. |
| 49 | * @param target Sum target. |
| 50 | * @return postion of 2 number. |
| 51 | */ |
| 52 | vector<int> twoSum(vector<int>& nums, int target) { |
| 53 | ... |
| 54 | } |
| 55 | ''' |
| 56 | ... |
| 57 | print(CppParser.get_docstring_node(function_node)) |
| 58 | |
| 59 | >>> [<Node type=comment, start_point=(x, y), end_point=(x, y)>] |
| 60 | """ |
| 61 | docstring_node = [] |
| 62 | |
| 63 | prev_node = node.prev_sibling |
| 64 | if prev_node and prev_node.type == 'comment': |
| 65 | docstring_node.append(prev_node) |
| 66 | prev_node = prev_node.prev_sibling |
| 67 | |
| 68 | while prev_node and prev_node.type == 'comment': |
nothing calls this directly
no outgoing calls
no test coverage detected