Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 31f2fb8a5a
1679 files changed
+1024562

No files matched your search

@@ -0,0 +1,58 @@
"""Modular's mojo-syntax skill: its table of removed syntax and replacements.
The skill is Modular's correction layer for code written from old tutorials,
which is exactly what students paste. Its "Removed syntax" table becomes the
candidate list for Stage 2's quick fixes; each one is checked against the
compiler's own fix-its (messages/) and against the pinned release notes
(release/) before Programming+ offers it.
The skill targets "latest" Mojo, which can be ahead of the pin; the dialect
markers in mojo/pin.json and verify are what decide, not this table.
Writes skill/removed-syntax.json.
"""
from __future__ import annotations
import re
from ..common import PipelineError, write_json
from . import Context, fresh_dir
NAME = "skill"
SOURCE = "skills"
INPUTS = ["mojo-syntax/SKILL.md"]
def table_after(md: str, heading: str) -> list[list[str]]:
m = re.search(rf"(?m)^##\s+{re.escape(heading)}\s*$", md)
if not m:
raise PipelineError(f"skill: no '## {heading}' section")
rows = []
for line in md[m.end():].split("\n"):
if line.startswith("## "):
break
if not line.startswith("|"):
if rows:
break
continue
cells = [c.strip() for c in line.strip().strip("|").split("|")]
if all(re.fullmatch(r":?-+:?", c) for c in cells):
continue
rows.append(cells)
return rows
def code_spans(cell: str) -> list[str]:
return re.findall(r"`([^`]+)`", cell)
def run(ctx: Context) -> dict:
out = fresh_dir(NAME)
md = (ctx.root / "mojo-syntax" / "SKILL.md").read_text(encoding="utf-8")
rows = table_after(md, "Removed syntax — DO NOT generate these")
header, body = rows[0], rows[1:]
entries = [{"removed": r[0], "replacement": r[1], "removedCode": code_spans(r[0]), "replacementCode": code_spans(r[1])}
for r in body if len(r) >= 2]
write_json(out / "removed-syntax.json", {"processor": NAME, "provenance": ctx.prov("mojo-syntax/SKILL.md"),
"columns": header, "entries": entries})
return {"entries": len(entries)}