INNER CODE UNIT · Python

_block_delta

Cooler2/ApusGameEngine · tools/normalize_indent.py:78

def _block_delta(line):
    """Net change in begin/end depth for this line (opens minus closes)."""
    s = line.strip()
    cp = s.find('//')
    code = (s[:cp] if cp >= 0 else s).lower()
    return len(_BLOCK_OPEN_RE.findall(code)) - len(_END_RE.findall(code))


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

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…