shast.py

clew/shast.py

The shell dialect: function definitions for the parse-built front end.

harvest_definitions

dict[str, list[dict[str, Any]]] clew.shast.harvest_definitions(Any tree, bytes src_bytes)

Harvest one shell file's function definitions.

clew/shast.py:98

Show on the map →

Called by none

Calls _definition_name, _function_record, walk_nodes

Source · 22 lines
def harvest_definitions(tree: Any, src_bytes: bytes) -> dict[str, list[dict[str, Any]]]:
    """Positions are 1-based lines and 0-based columns, as doxygen writes them, and the
    payload is rowid-free JSON so it caches per file content like every other stage.

    `classes` is present and empty: shell has no class-like construct, and the shape is
    shared with the JS/TS payload the same writer consumes.

    @brief Harvest shell definitions.
    @return The definitions payload.
    """
    out: dict[str, list[dict[str, Any]]] = {"functions": [], "classes": []}
    if tree.root_node.type != SH_ROOT:
        return out
    lines = src_bytes.decode("utf-8", errors="replace").splitlines()
    for node in walk_nodes(tree.root_node):
        name = _definition_name(node)
        if name:
            out["functions"].append(_function_record(node, name, lines))
    out["functions"].sort(key=lambda fn: (fn["line"], fn["name"]))
    return out

Activity · 10 steps
lines 108–108out: dict[str, list[dict[str, Any]]] = {"functions": [], "classes": []}lines 109–109◇ if tree.root_node.type != SH_ROOTlines 110–110return outlines 111–111lines = src_bytes.decode("utf-8", errors="replace").splitlines()lines 112–112◇ for node in walk_nodes(tree.root_node)lines 113–113name = _definition_name(node)lines 114–114◇ if namelines 115–115out["functions"].append(_function_record(node, name, lines))lines 116–116out["functions"].sort(key=lambda fn: (fn["line"], fn["name"]))lines 117–117return out

Requirements

REQ-DDB-PIPE-012