• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from .parser import parse as _parse
2from .preprocessor import get_preprocessor as _get_preprocessor
3
4
5def parse_file(filename, *,
6               match_kind=None,
7               get_file_preprocessor=None,
8               ):
9    if get_file_preprocessor is None:
10        get_file_preprocessor = _get_preprocessor()
11    yield from _parse_file(filename, match_kind, get_file_preprocessor)
12
13
14def parse_files(filenames, *,
15                match_kind=None,
16                get_file_preprocessor=None,
17                ):
18    if get_file_preprocessor is None:
19        get_file_preprocessor = _get_preprocessor()
20    for filename in filenames:
21        yield from _parse_file(filename, match_kind, get_file_preprocessor)
22
23
24def _parse_file(filename, match_kind, get_file_preprocessor):
25    # Preprocess the file.
26    preprocess = get_file_preprocessor(filename)
27    preprocessed = preprocess()
28    if preprocessed is None:
29        return
30
31    # Parse the lines.
32    srclines = ((l.file, l.data) for l in preprocessed if l.kind == 'source')
33    for item in _parse(srclines):
34        if match_kind is not None and not match_kind(item.kind):
35            continue
36        if not item.filename:
37            raise NotImplementedError(repr(item))
38        yield item
39
40
41def parse_signature(text):
42    raise NotImplementedError
43
44
45# aliases
46from .info import resolve_parsed
47