scriptast.py

clew/scriptast.py

What the shell and CMake front ends share: a tree walk, node text, and the `#` doc block.

comment_block_above

str clew.scriptast.comment_block_above(int line_index, list[str] lines)

The # comment block immediately above a line, with its markers stripped.

clew/scriptast.py:65

Show on the map →

Called by _definition_record, _function_record

Calls none

Source · 22 lines
def comment_block_above(line_index: int, lines: list[str]) -> str:
    """THE SHARED RULE. Immediately above, with no blank line between — a detached comment
    documents nothing, which is what every other front end here already enforces for its
    own comment form.

    A shebang is not documentation: it addresses the kernel, not a reader, so a block that
    reaches one stops there. That matters for the common shape of a script whose first
    line is `#!/bin/bash` followed by a title comment: the title documents the FILE, and
    attributing it to whatever function happens to be defined first would be wrong.

    @brief The preceding comment block, markers stripped.
    @return The block text.
    """
    collected: list[str] = []
    index = line_index - 1
    while index >= 0:
        stripped = lines[index].strip()
        if not stripped.startswith("#") or stripped.startswith("#!"):
            break
        collected.append(stripped.lstrip("#").strip())
        index -= 1
    return "\n".join(reversed(collected)).strip()

1 more lines, not shown

Activity · 9 steps
lines 78–78collected: list[str] = []lines 79–79index = line_index - 1lines 80–80◇ while index >= 0lines 81–81stripped = lines[index].strip()lines 82–82◇ if not stripped.startswith("#") or stripped.startswith("#!")lines 83–83breaklines 84–84collected.append(stripped.lstrip("#").strip())lines 85–85index -= 1lines 86–86return "\n".join(reversed(collected)).strip()

Requirements

REQ-DDB-PIPE-012