Coverage for parsers/shared.py: 100%

1"""Shared parser utilities for all languages."""

2

3 from __future__ import annotations

4

5 from parsers.common import parse_with_language

6

7

8 def create_parse(language):

9 """Create parse function for a specific language."""

10

11 def parse(code: str):

12 """Parse source code and return the tree root node."""

13 return parse_with_language(code, language)

14

15 return parse

16

17

18 def create_collect_functions(recursive_collect_fn):

19 """Create collect_functions wrapper from language-specific recursive function."""

20

21 def collect_functions(root) -> list:

22 """Collect all function nodes at all depths."""

23 functions = []

24 recursive_collect_fn(root, functions)

25 return functions

26

27 return collect_functions