summaryrefslogtreecommitdiffstats
path: root/Tools/c-analyzer/table-file.py
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-12-07 22:02:47 (GMT)
committerGitHub <noreply@github.com>2022-12-07 22:02:47 (GMT)
commitd47ffeb9e35dbc7264ffa12fddaa6e0d3ba767a4 (patch)
treedf492a2e76ca4e427164b4ae6c3a041c84b8b436 /Tools/c-analyzer/table-file.py
parentd92407ed497e3fc5acacb0294ab6095013e600f4 (diff)
downloadcpython-d47ffeb9e35dbc7264ffa12fddaa6e0d3ba767a4.zip
cpython-d47ffeb9e35dbc7264ffa12fddaa6e0d3ba767a4.tar.gz
cpython-d47ffeb9e35dbc7264ffa12fddaa6e0d3ba767a4.tar.bz2
gh-90110: Clean Up the C-analyzer Globals Lists (gh-100091)
https://github.com/python/cpython/issues/90110
Diffstat (limited to 'Tools/c-analyzer/table-file.py')
-rw-r--r--Tools/c-analyzer/table-file.py83
1 files changed, 50 insertions, 33 deletions
diff --git a/Tools/c-analyzer/table-file.py b/Tools/c-analyzer/table-file.py
index 3cc05cc..d36f814 100644
--- a/Tools/c-analyzer/table-file.py
+++ b/Tools/c-analyzer/table-file.py
@@ -1,43 +1,59 @@
+KINDS = [
+ 'section-major',
+ 'section-minor',
+ 'section-group',
+ 'row',
+]
+
+
def iter_clean_lines(lines):
lines = iter(lines)
- for line in lines:
- line = line.strip()
- if line.startswith('# XXX'):
+ for rawline in lines:
+ line = rawline.strip()
+ if line.startswith('#') and not rawline.startswith('##'):
continue
- yield line
+ yield line, rawline
def parse_table_lines(lines):
lines = iter_clean_lines(lines)
- for line in lines:
- if line.startswith(('####', '#----')):
- kind = 0 if line[1] == '#' else 1
- try:
- line = next(lines).strip()
- except StopIteration:
- line = ''
- if not line.startswith('# '):
- raise NotImplementedError(line)
- yield kind, line[2:].lstrip()
- continue
-
- maybe = None
- while line.startswith('#'):
- if line != '#' and line[1] == ' ':
- maybe = line[2:].lstrip()
- try:
- line = next(lines).strip()
- except StopIteration:
- return
- if not line:
- break
- else:
- if line:
- if maybe:
- yield 2, maybe
- yield 'row', line
+ group = None
+ prev = ''
+ for line, rawline in lines:
+ if line.startswith('## '):
+ assert not rawline.startswith(' '), (line, rawline)
+ if group:
+ assert prev, (line, rawline)
+ kind, after, _ = group
+ assert kind and kind != 'section-group', (group, line, rawline)
+ assert after is not None, (group, line, rawline)
+ else:
+ assert not prev, (prev, line, rawline)
+ kind, after = group = ('section-group', None)
+ title = line[3:].lstrip()
+ assert title, (line, rawline)
+ if after is not None:
+ try:
+ line, rawline = next(lines)
+ except StopIteration:
+ line = None
+ if line != after:
+ raise NotImplementedError((group, line, rawline))
+ yield kind, title
+ group = None
+ elif group:
+ raise NotImplementedError((group, line, rawline))
+ elif line.startswith('##---'):
+ assert line.rstrip('-') == '##', (line, rawline)
+ group = ('section-minor', '', line)
+ elif line.startswith('#####'):
+ assert not line.strip('#'), (line, rawline)
+ group = ('section-major', '', line)
+ elif line:
+ yield 'row', line
+ prev = line
def iter_sections(lines):
@@ -49,12 +65,13 @@ def iter_sections(lines):
if header is None:
header = value
continue
- raise NotImplementedError(value)
+ raise NotImplementedError(repr(value))
yield tuple(section), value
else:
if header is None:
header = False
- section[kind:] = [value]
+ start = KINDS.index(kind)
+ section[start:] = [value]
def collect_sections(lines):