SNAPKITTYWEST's picture
Metadata: discovery tags (collection, languages)
cca49da verified
|
Raw History Blame Contribute Delete
13.7 kB
---
license: other
license_name: snapkitty-tri-license
license_link: https://huggingface.co/Snapkitty/sovereign-xml-compiler/blob/main/LICENSE.tri
library_name: custom
tags:
- code
- sovereign-compute
- snapkitty
- compilers
- python
---
<p align="center">
```
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β• β•šβ•β•β•β•β•β•β•β•šβ•β• β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β• β•šβ•β•β•β•
β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—
β•šβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•
β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•
β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘
β•šβ•β• β•šβ•β•β•šβ•β• β•šβ•β•β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β• β•šβ•β•β•šβ•β•
```
</p>
<h3 align="center">XML in. SVG out. Zero dependencies.</h3>
<p align="center">
<img src="https://img.shields.io/badge/language-Python-3776AB?style=flat-square"/>
<img src="https://img.shields.io/badge/deps-zero-black?style=flat-square"/>
<img src="https://img.shields.io/badge/tests-6_passing-brightgreen?style=flat-square"/>
<img src="https://img.shields.io/badge/also-XSLT_in_browser-orange?style=flat-square"/>
<img src="https://img.shields.io/badge/Docker-ready-2496ED?style=flat-square"/>
</p>
---
## What Is This?
Two compilers that turn XML into visual output:
1. **XMLToSVG** β€” takes a scene description in XML, outputs a standalone SVG image
2. **ConstraintGraphCompiler** β€” takes a directed graph in XML, outputs both an SVG visualization AND a runtime execution pipeline (topological order via Kahn's algorithm)
Both run server-side (Python), client-side (XSLT in any browser), and as a CLI. No lxml. No numpy. No external packages. Pure Python stdlib.
```
╔══════════════════════════════════════════════════════════════════╗
β•‘ β•‘
β•‘ YOUR XML OUTPUT β•‘
β•‘ ──────── ────── β•‘
β•‘ β•‘
β•‘ <scene width="800" height="600"> β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β•‘
β•‘ <rect .../> β”‚ β”‚ β•‘
β•‘ <circle .../> ──────> β”‚ Beautiful SVG image β”‚ β•‘
β•‘ <text .../> β”‚ (dark theme, styled) β”‚ β•‘
β•‘ </scene> β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘
β•‘ β•‘
β•‘ <graph> β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β•‘
β•‘ <node id="A"/> β”‚ SVG graph diagram β”‚ β•‘
β•‘ <node id="B"/> ──────> β”‚ + execution pipeline β”‚ β•‘
β•‘ <edge from="A" to="B"/> β”‚ ["A", "B", "C"] β”‚ β•‘
β•‘ </graph> β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘
β•‘ β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
```
---
## Quick Start
```bash
# From source
git clone https://github.com/SNAPKITTYWEST/sovereign-xml-compiler
cd sovereign-xml-compiler
# Scene to SVG
python xml2svg.py examples/scene.xml > output.svg
# Constraint graph to SVG
python constraint_graph_svg.py examples/constraint_graph.xml > graph.svg
# Run in browser (no server-side code needed)
python -m http.server 8000
# open http://localhost:8000/browser/graph_browser.html
```
---
## Install
```bash
# pip (installs CLI commands: xml2svg, constraint-graph)
pip install sovereign-xml-compiler
# from source (editable)
pip install -e .
# docker
docker run -p 8000:8000 ghcr.io/snapkittywest/sovereign-xml-compiler
# open http://localhost:8000/browser/graph_browser.html
```
Requires Python 3.9+. Zero external dependencies.
---
## User Guide
### Compiler 1: XML Scene to SVG
Write a scene in XML using simple shape primitives:
```xml
<scene width="800" height="600">
<rect x="10" y="10" width="200" height="100" fill="#1a1a2e" stroke="#e94560"/>
<circle cx="400" cy="300" r="50" fill="#e94560"/>
<line x1="0" y1="0" x2="800" y2="600" stroke="white" stroke-width="2"/>
<text x="100" y="50" fill="white" font-size="24">Hello, Sovereign</text>
<group transform="translate(50,50)">
<rect x="0" y="0" width="50" height="50" fill="gold"/>
</group>
</scene>
```
Compile it:
```bash
# CLI
xml2svg scene.xml output.svg
# Python
from xml2svg import XMLToSVG
svg_string = XMLToSVG().compile(open("scene.xml").read())
```
Supported elements: `rect`, `circle`, `line`, `path`, `text`, `group`
### Compiler 2: Constraint Graph to SVG + Runtime
Define a processing pipeline as a directed graph:
```xml
<graph>
<node id="input" type="Input" label="Raw Data"/>
<node id="validate" type="Transform" label="Validate"/>
<node id="transform" type="Transform" label="Process"/>
<node id="output" type="Output" label="Result"/>
<edge from="input" to="validate"/>
<edge from="validate" to="transform"/>
<edge from="transform" to="output"/>
</graph>
```
Get both a visualization AND an execution order:
```python
from constraint_graph_svg import ConstraintGraphCompiler
compiler = ConstraintGraphCompiler()
# Dark-themed SVG visualization of the graph
svg = compiler.compile_to_svg(xml_string)
# Executable runtime dict with topological pipeline
runtime = compiler.compile_to_runtime(xml_string)
# runtime = {
# "nodes": [...],
# "edges": [...],
# "pipeline": ["input", "validate", "transform", "output"]
# }
```
The `pipeline` field is computed via **Kahn's algorithm** β€” guaranteed topological order. Cycles are detected and rejected.
### Browser Mode (XSLT, No Server)
Open `browser/graph_browser.html` in any modern browser. It uses the browser's native `XSLTProcessor` to transform XML into SVG client-side. No JavaScript frameworks. No build step.
```
╔══════════════════════════════════════════════════════════════╗
β•‘ browser/graph_browser.html β•‘
β•‘ β”‚ β•‘
β•‘ β”œβ”€β”€ fetches constraint_graph.xml β•‘
β•‘ β”œβ”€β”€ fetches constraint_graph.xsl β•‘
β•‘ β”œβ”€β”€ applies XSLTProcessor (browser-native) β•‘
β•‘ └── renders SVG in sandboxed <iframe> β•‘
β•‘ β•‘
β•‘ Zero JavaScript dependencies. Pure XML/XSLT/CSS. β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
```
---
## CLI Reference
```bash
# XML scene β†’ SVG
xml2svg input.xml # stdout
xml2svg input.xml output.svg # file
# Constraint graph β†’ SVG
constraint-graph input.xml # stdout (SVG)
constraint-graph input.xml out.svg # file (SVG)
constraint-graph input.xml --runtime # stdout (JSON pipeline)
```
---
## Architecture
```
XML Source Document
β”‚
β–Ό
xml.etree.ElementTree.fromstring() ← stdlib, no lxml
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SEMANTIC VALIDATION β”‚
β”‚ β”‚
β”‚ XMLToSVG: whitelist {rect,circle,line,path, β”‚
β”‚ text,group} β€” rejects unknown elements β”‚
β”‚ β”‚
β”‚ GraphComp: Kahn's topological sort β”‚
β”‚ cycle detection β†’ error on DAG violation β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ IR CONSTRUCTION β”‚
β”‚ β”‚
β”‚ XMLToSVG: SVGNode dataclass tree β”‚
β”‚ GraphComp: {nodes: list, edges: list, pipeline} β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ CODE GENERATION β”‚
β”‚ β”‚
β”‚ XMLToSVG: recursive ir_to_svg() β†’ SVG string β”‚
β”‚ GraphComp: _render_svg() β†’ dark-theme SVG β”‚
β”‚ compile_to_runtime() β†’ JSON dict β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
---
## Files
```
sovereign-xml-compiler/
β”œβ”€β”€ xml2svg.py XMLToSVG compiler (scene β†’ SVG)
β”œβ”€β”€ constraint_graph_svg.py ConstraintGraphCompiler (graph β†’ SVG + runtime)
β”œβ”€β”€ pyproject.toml Package config + CLI entry points
β”œβ”€β”€ test_compilers.py 6 tests, zero dependencies
β”œβ”€β”€ Dockerfile Containerized browser server
β”œβ”€β”€ examples/
β”‚ β”œβ”€β”€ scene.xml 800x600 scene with shapes + text
β”‚ └── constraint_graph.xml 7-node processing pipeline
└── browser/
β”œβ”€β”€ index.html Sovereign browser host page
β”œβ”€β”€ graph_browser.html XSLT graph visualizer (no JS deps)
β”œβ”€β”€ browser.xsl HTML transform (dark theme, CSS nav)
β”œβ”€β”€ constraint_graph.xsl SVG transform (graph β†’ visual)
β”œβ”€β”€ browser.xml 2-page sovereign browser source
└── validate_xslt.py CI: validates XSL as well-formed XML
```
---
## Tests
```bash
python test_compilers.py
# 6 tests: 6 passed, 0 failed
```
Tests cover: scene compilation, graph compilation, topological sort correctness, cycle detection, empty input handling, SVG well-formedness.
---
<p align="center"><b>Built by Ahmad Ali Parr + SnapKitty Collective</b></p>
<p align="center"><i>XML is a compiler target. SVG is the output format. Python stdlib is the only dependency.</i></p>
---
## License
Licensed under **SnapKitty Tri-License**. Full text: [LICENSE.tri](LICENSE.tri).
### πŸ’Ό Commercial License
Snapkitty code is free and open under **AGPL-3.0** for open-source use. Building a commercial product or service? A **proprietary commercial license** from Snapkitty Collective LLC lets you ship this code without the AGPL's source-sharing and network-use obligations.
**[β†’ Get a commercial license](mailto:A.parr@belespritdaccord.uk?subject=Commercial%20license:%20sovereign-xml-compiler)** Β· A.parr@belespritdaccord.uk