INNER CODE UNIT · Python

_compute_reductions

Cooler2/ApusGameEngine · tools/normalize_indent.py:86

def _compute_reductions(lines):
    """
    For each line index, compute how many indent levels to subtract before
    multiplying by 2.

    Problem: in 1-space Pascal code, procedure/function bodies often have
    var/begin/end at proc_indent+1 instead of proc_indent.  After plain 2x
    multiplication this produces wrong indentation.

    Fix: for each such body, all lines from the first body line through the
    matching `end;` get reduction +1, so they use (indent - 1) * 2.
    Nested procedures accumulate reductions (each nesting level adds 1).

    Returns dict {line_index: reduction_count}.
    """
    reductions = {}
    n = len(lines)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…