Skip to content

feat(ingestion): add experimental LPC support - #6186

Open
rainearii wants to merge 2 commits into
repowise-dev:mainfrom
rainearii:feat/lpc-language-support
Open

rainearii wants to merge 2 commits into
repowise-dev:mainfrom
rainearii:feat/lpc-language-support

Conversation

@rainearii

Copy link
Copy Markdown

Refs #6139. First of a short series (one PR at a time, as agreed in the issue).

Adds LPC (LDMud) as an opt-in language:

  • .c/.h files are LPC only under configured mudlib roots (REPOWISE_LPC_CONFIG / REPOWISE_LPC_ROOTS); everything else keeps the C/C++ classification.
  • The grammar is the optional extra repowise[lpc] (tree-sitter-lpc>=0.1,<0.2, the repowise-dev fork on PyPI). The import is guarded: without it LPC stays inactive (files stay C/C++, one warning naming the extra). CI installs it with uv sync --extra lpc.
  • Symbols: functions with bodies, globals, structs, macros, with visibility. Literal inherit and #include imports.
  • Tests include .c/.h outside configured roots still parsing as C/C++ (symbols and includes), and LPC inactive without the grammar.
  • Docs: docs/reference/LPC.md.

uv.lock was regenerated with CI's uv 0.13.9: it rewrites revision 3 -> 5 and drops the redundant python_full_version < '3.13' markers under fastembed (already gated by the local-embed extra). uv lock --check passes.

How it was measured

6,912 / 55,760 inherit statements resolve (12.4%); most use macros (inherit STD_ROOM;), which the next PR handles.

Corpus: a private LDMud mudlib (68,254 files traversed, 67,529 parsed as LPC, 55,760 inherit statements; default traversal, nothing excluded). Only counts are quoted; the test fixtures are synthetic. Each statement goes through the normal resolver (resolve_import) against the set of traversed files; resolved = it names an indexed file. Later PRs use the same mudlib revision and config, switching on only the keys they add.

Script
"""Share of LPC `inherit` statements repowise resolves to an indexed file (read-only).

Traverses the mudlib like `repowise init`, parses every LPC file, and resolves each
`inherit` import through the normal resolver against the set of traversed files.
Run once per branch of the upstream series with that branch's config:

    REPOWISE_LPC_CONFIG=cfg.json .venv/bin/python lpc-inherit-rate.py <mudlib> [--limit N]

Prints JSON: files, LPC files, inherit statements, resolved, rate, and the top
unresolved operands.
"""

import argparse
import collections
import json
import re
from pathlib import Path

import networkx as nx

from repowise.core.ingestion.parser import parse_file
from repowise.core.ingestion.resolvers import resolve_import
from repowise.core.ingestion.resolvers.context import ResolverContext
from repowise.core.ingestion.traverser import FileTraverser

INHERIT = re.compile(r"^\s*(?:(?:private|protected|public|static|virtual|nosave|functions|variables)\s+)*inherit\b(.*)", re.S)


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("root", type=Path)
    parser.add_argument("--limit", type=int, default=0)
    args = parser.parse_args()
    root = args.root.resolve()
    files = list(FileTraverser(root).traverse())
    path_set = {info.path for info in files}
    lpc = [info for info in files if info.language == "lpc"]
    if args.limit:
        lpc = lpc[: args.limit]
    ctx = ResolverContext(path_set=path_set, stem_map={}, graph=nx.DiGraph(), repo_path=root)
    total = resolved = 0
    unresolved: collections.Counter[str] = collections.Counter()
    for info in lpc:
        parsed = parse_file(info, Path(info.abs_path).read_bytes())
        for imp in parsed.imports:
            match = INHERIT.match(imp.module_path)
            if not match:
                continue
            total += 1
            if resolve_import(imp.module_path, info.path, "lpc", ctx):
                resolved += 1
            else:
                unresolved[match[1].strip().rstrip(";").strip()] += 1
    print(json.dumps({
        "files": len(files), "lpc_files": len(lpc), "inherits": total, "resolved": resolved,
        "rate": round(resolved / total, 4) if total else None,
        "top_unresolved": unresolved.most_common(10),
    }, indent=1))


if __name__ == "__main__":
    main()

Tests

tests/unit/ingestion: 7,173 passed on this branch; ruff check clean; LPC tests also pass on the tree-sitter 0.25.0 floor with tree-sitter-lpc 0.1.0 from PyPI.

🤖 Generated with Claude Code

@repowise-bot

repowise-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

⚪ Looks safe to merge: no open points, no breaking contract change found.

Reviewed the whole diff: nothing to fix.

✅ Health of changed files: 5.7 → 6.2 (+0.5; structure +0.4) Average full file score (structure and history) of 21 changed code files, weighted by size before this PR; not the repository score.

👀 Suggested reviewers RaghavChamadiya


View on Repowise
Plain markdown for agents · Reviews (3) · Last reviewed commit: perf(lpc): cache the parsed LPC config between classifier calls · Since the last review: 1 answered in its thread

Settings and updates

Silence one PR with [skip repowise] in the title · Bot settings
/repowise recheck reviews the current head again
/repowise review deep runs the deep review on it
/repowise remember <text> tells the reviewer what to leave out next time (reply on a finding to scope it to that file)
/repowise help lists the commands
⭐ Star Repowise · 📥 Install on another repo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rainearii
rainearii force-pushed the feat/lpc-language-support branch from d9bde1f to 3486dfa Compare November 22, 2026 16:05
The file classifier runs per file, and for .c/.h paths it now checks the LPC
roots. config() re-resolved every root on each call; it now costs one stat of
the config file, with the parsed result cached per environment, working
directory and config file version (85 -> 58 us per .c/.h file on a 67k-file
mudlib). The classifier docstring no longer claims it does no file I/O.

Addresses the repowise-bot review on repowise-dev#6186.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant