Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,122 @@
|
||||
"""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 = """""
|
||||
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 = """
|
||||
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="(?<=[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="+-*/%<>=!^~&|:,.@[](){{}}"/>
|
||||
</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>
|
||||
"""
|
||||
Reference in new issue
Block a user