forge: DRY collapse duplicate fence-tracking in queue_index.parse
This commit is contained in:
1 parent
e0019ea158
commit
40f1095590
1 file changed
+21
-10
+21
-10
@@ -195,19 +195,34 @@ def status_value(raw):
|
||||
return raw
|
||||
|
||||
|
||||
def fence_mask(lines):
|
||||
"""1-based line numbers to skip: fence delimiters and every line they hide.
|
||||
|
||||
A fenced block is quoted material, not document structure -- headings inside
|
||||
it are not sections, and id tokens inside it are not records. Stated once
|
||||
here and reused by parse(), rather than restated verbatim in each scan loop.
|
||||
"""
|
||||
out = set()
|
||||
in_fence = False
|
||||
for i, ln in enumerate(lines, 1):
|
||||
if FENCE.match(ln.strip()):
|
||||
in_fence = not in_fence
|
||||
out.add(i)
|
||||
elif in_fence:
|
||||
out.add(i)
|
||||
return out
|
||||
|
||||
|
||||
def parse(text):
|
||||
"""Return the structural parse: sections, nested ids, id map, byte accounting."""
|
||||
lines, trailing_newline = split_lines(text)
|
||||
n = len(lines)
|
||||
sizes = [line_bytes(ln, i == n - 1, trailing_newline) for i, ln in enumerate(lines)]
|
||||
fenced = fence_mask(lines)
|
||||
|
||||
headings = [] # (line_no, id, rest)
|
||||
in_fence = False
|
||||
for i, ln in enumerate(lines, 1):
|
||||
if FENCE.match(ln.strip()):
|
||||
in_fence = not in_fence
|
||||
continue
|
||||
if in_fence:
|
||||
if i in fenced:
|
||||
continue
|
||||
m = HEADING.match(ln)
|
||||
if m:
|
||||
@@ -261,12 +276,8 @@ def parse(text):
|
||||
# (Q54/Q55/Q56/Q58 as artifact filenames, Q62 inside `Q31-Q62`, Q77/Q99 inside
|
||||
# a quoted `--outside` list) is not an item at all.
|
||||
mentioned = {}
|
||||
in_fence = False
|
||||
for i, ln in enumerate(lines, 1):
|
||||
if FENCE.match(ln.strip()):
|
||||
in_fence = not in_fence
|
||||
continue
|
||||
if in_fence:
|
||||
if i in fenced:
|
||||
continue
|
||||
for m in ID_TOKEN.finditer(ln):
|
||||
qid = m.group(0)
|
||||
|
||||
Reference in new issue
Block a user