1from . import preprocessor
2
3
4def iter_clean_lines(lines):
5    incomment = False
6    for line in lines:
7        # Deal with comments.
8        if incomment:
9            _, sep, line = line.partition('*/')
10            if sep:
11                incomment = False
12            continue
13        line, _, _ = line.partition('//')
14        line, sep, remainder = line.partition('/*')
15        if sep:
16            _, sep, after = remainder.partition('*/')
17            if not sep:
18                incomment = True
19                continue
20            line += ' ' + after
21
22        # Ignore blank lines and leading/trailing whitespace.
23        line = line.strip()
24        if not line:
25            continue
26
27        yield line
28
29
30def iter_lines(filename, *,
31               preprocess=preprocessor.run,
32               ):
33    content = preprocess(filename)
34    return iter(content.splitlines())
35