Files
pplus-web/core/scripts/mojo/mojocorpus/kde.py
T
alexmandClaude 82e18f7966 Move the engine core into core/, a project of its own (pplus-core)
What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.

- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
  mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
  place of the site's Session), scripts (corpus pipeline, play, the
  exercise and probe starters, engines export/diff), and its docs
  (engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
  package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
  page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
  platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
  index.html, "imports" in package.json for node, core's declarations for
  tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
  quarto-export and quarto-css read core/dist and core/mojo; quarto-css
  copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
  describe the split (checkout with submodules; core's tests and corpus
  status run against the pinned commit).

Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
2026-10-05 05:43:58 +00:00

123 lines
5.5 KiB
Python

"""A KDE syntax definition for Mojo, for Pandoc and Quarto listings.
Generated from the same harvested words as the editor's highlighter
(corpus/tokens/tokens.json), so a printed listing and the Mojo pane colour
the same words the same way: keywords, the ownership conventions, the
postfix transfer ^, words 1.1.0 removed, decorators, and prelude names.
Strings, including triple-quoted docstrings across lines, are their own
contexts.
"""
from __future__ import annotations
from xml.sax.saxutils import escape
TRIPLE_DOUBLE = "&quot;&quot;&quot;"
TRIPLE_SINGLE = "'" * 3
def _items(words) -> str:
return "\n".join(f" <item>{escape(w)}</item>" for w in words)
def mojo_xml(version: str, repo: str, commit: str, keywords: list[str], conventions: list[str], removed: list[str],
prelude: list[str], effects: list[str]) -> str:
kw = sorted((set(keywords) - {"var", "ref"}) | set(effects)) # var and ref are coloured as conventions
conv = sorted(set(conventions) | {"var", "ref"})
q = "&quot;"
return f"""<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by scripts/mojo/corpus.py emit from {repo}@{commit[:12]} (Mojo {version}). Do not edit. -->
<language name="Mojo"
section="Sources"
version="1"
kateversion="5.0"
extensions="*.mojo;*.🔥"
mimetype="text/x-mojo"
author="Programming+"
license="MIT">
<highlighting>
<list name="keywords">
{_items(kw)}
</list>
<list name="conventions">
{_items(conv)}
</list>
<list name="removed">
{_items(removed)}
</list>
<list name="builtins">
{_items(prelude)}
</list>
<contexts>
<context name="Normal" attribute="Normal Text" lineEndContext="#stay">
<DetectSpaces/>
<DetectChar attribute="Comment" char="#" context="Comment"/>
<RegExpr attribute="String" String="[rRtT]{{0,2}}{TRIPLE_DOUBLE}" context="TripleDouble"/>
<RegExpr attribute="String" String="[rRtT]{{0,2}}{TRIPLE_SINGLE}" context="TripleSingle"/>
<RegExpr attribute="String" String="[rRtT]{{0,2}}{q}" context="StringDouble"/>
<RegExpr attribute="String" String="[rRtT]{{0,2}}'" context="StringSingle"/>
<RegExpr attribute="Decorator" String="@[A-Za-z_][A-Za-z0-9_.]*" context="#stay" firstNonSpace="true"/>
<keyword attribute="Removed" String="removed"/>
<keyword attribute="Convention" String="conventions"/>
<keyword attribute="Keyword" String="keywords"/>
<keyword attribute="Builtin" String="builtins"/>
<RegExpr attribute="Transfer" String="(?&lt;=[A-Za-z0-9_\\)\\]])\\^(?=\\s*[\\),\\]\\}}:]|\\s*$)" context="#stay"/>
<RegExpr attribute="Float" String="\\b[0-9][0-9_]*\\.[0-9_]*(?:[eE][+-]?[0-9]+)?|\\b[0-9][0-9_]*[eE][+-]?[0-9]+\\b" context="#stay"/>
<RegExpr attribute="Decimal" String="\\b(?:0[xX][0-9a-fA-F_]+|0[oO][0-7_]+|0[bB][01_]+|[0-9][0-9_]*)\\b" context="#stay"/>
<RegExpr attribute="Function" String="\\b[A-Za-z_][A-Za-z0-9_]*(?=\\s*[\\(\\[])" context="#stay"/>
<AnyChar attribute="Operator" String="+-*/%&lt;&gt;=!^~&amp;|:,.@[](){{}}"/>
</context>
<context name="Comment" attribute="Comment" lineEndContext="#pop">
<DetectSpaces/>
<RegExpr attribute="Alert" String="\\b(TODO|FIXME|NOTE)\\b" context="#stay"/>
<DetectIdentifier/>
</context>
<context name="TripleDouble" attribute="String" lineEndContext="#stay">
<DetectChar attribute="String" char="\\" context="Escape"/>
<StringDetect attribute="String" String="{TRIPLE_DOUBLE}" context="#pop"/>
</context>
<context name="TripleSingle" attribute="String" lineEndContext="#stay">
<DetectChar attribute="String" char="\\" context="Escape"/>
<StringDetect attribute="String" String="{TRIPLE_SINGLE}" context="#pop"/>
</context>
<context name="StringDouble" attribute="String" lineEndContext="#pop">
<DetectChar attribute="String" char="\\" context="Escape"/>
<DetectChar attribute="String" char="{q}" context="#pop"/>
</context>
<context name="StringSingle" attribute="String" lineEndContext="#pop">
<DetectChar attribute="String" char="\\" context="Escape"/>
<DetectChar attribute="String" char="'" context="#pop"/>
</context>
<context name="Escape" attribute="String" lineEndContext="#pop">
<RegExpr attribute="String" String="." context="#pop"/>
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Keyword" defStyleNum="dsKeyword"/>
<itemData name="Convention" defStyleNum="dsAttribute" bold="1" italic="1"/>
<itemData name="Transfer" defStyleNum="dsSpecialChar" bold="1"/>
<itemData name="Removed" defStyleNum="dsError"/>
<itemData name="Builtin" defStyleNum="dsBuiltIn"/>
<itemData name="Decorator" defStyleNum="dsAttribute"/>
<itemData name="Function" defStyleNum="dsFunction"/>
<itemData name="Decimal" defStyleNum="dsDecVal"/>
<itemData name="Float" defStyleNum="dsFloat"/>
<itemData name="String" defStyleNum="dsString"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Alert" defStyleNum="dsAlert"/>
<itemData name="Operator" defStyleNum="dsOperator"/>
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start="#"/>
</comments>
<keywords casesensitive="1"/>
</general>
</language>
"""