Files
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

125 lines
5.6 KiB
Python

# SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
# SPDX-License-Identifier: Apache-2.0
"""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 color
the same words the same way: keywords, the ownership conventions, the
postfix transfer ^, words the pin 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 = """""
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 colored 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="Apache-2.0">
<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>
"""