|
Download README.md from Snapkitty/sovereign-xml-compiler: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/Snapkitty/sovereign-xml-compiler/resolve/main/README.md
- Command line
-
hf download hf://Snapkitty/sovereign-xml-compiler/README.md
-
curl -L -o README.md https://huggingface.co/Snapkitty/sovereign-xml-compiler/resolve/main/README.md
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 | |