Parser for Mir Korabley Unbound 2 (.unbound) UI framework definition files — serialization and deserialization with perfect round-trip fidelity
Project description
ub2parser — Unbound 2 Parser
A Python library for parsing and serializing Mir Korabley's Unbound 2 UI framework definition files (.unbound). It converts source files into a concrete syntax tree that can be inspected or transformed, then writes them back with byte-level fidelity — comments, whitespace, and formatting are preserved unchanged.
Supported constructs
Validated against 579 .unbound files from the game's UI codebase:
- Definitions:
constant,element,css,macro,struct - Scope & bindings:
scope,var,event,bind,bindcall,sync,dispatch - Display objects:
sprite,tf,block,element,htile,vtile - Controllers & styles:
controller,style,filters,args,extends - Value types: numbers with units (
100px,50%), hex literals (0xFF0000), multi-line strings, maps{}, lists[], dot-path identifiers (SC.path.Value), function-call syntax
Installation
pip install ub2parser
For local development:
pip install -e .
Usage
from ub2parser import tokenize, parse, serialize
with open('my_ui.unbound', 'r', encoding='utf-8') as f:
source = f.read()
tokens = tokenize(source) # lexical analysis
doc = parse(tokens) # build CST
# traverse the tree
for d in doc.definitions:
print(f"{d.def_kind} {d.name.name}")
for child in d.body:
print(f" {type(child).__name__}")
# serialize — always byte-identical to the original
result = serialize(doc, tokens)
assert source == result
CLI
# AST summary
python -m ub2parser parse file.unbound
python -m ub2parser parse file.unbound -v
# Validate one file or a directory tree
python -m ub2parser validate file.unbound
python -m ub2parser validate --all examples/
# Verify round-trip fidelity
python -m ub2parser roundtrip file.unbound
# Inspect token stream
python -m ub2parser tokens file.unbound
Architecture
The processing pipeline has three stages:
- Tokenizer — converts source text into a flat token stream. Every byte is accounted for: structural tokens, value literals, whitespace, newlines, and comments are all retained.
- Parser — a recursive-descent parser that builds a concrete syntax tree (CST). Each node records its start and end positions within the token stream.
- Serializer — walks the CST and replays the original tokens in document order, producing output that is byte-for-byte identical to the input.
AST node reference
Every top-level definition becomes a DefNode with a def_kind field ("constant", "element", "css", "macro", or "struct"), a name, and a body list.
Specialized node types produced by the parser:
| Node | Syntax |
|---|---|
Property |
(width = 100px) |
ScopeNode |
(scope ...) |
VarDecl |
(var name:type = expr) |
EventDecl |
(event name) |
BindNode |
(bind target "source") |
BindCallNode |
(bindcall method ...) |
DispatchNode |
(dispatch event ...) |
MacroCallNode |
(macro Name ...) |
DOMethod |
(block ...), (tf ...), (sprite ...) |
StyleNode |
(style ...) |
ControllerNode |
(controller $Name ...) |
All nodes carry token_start and token_end indices into the token list, which enables the serializer to reproduce the exact source text.
License
LGPL-3.0-only — see LICENSE.
References
- Unbound 2 documentation (Korabley Forum, Russian)
- Unbound 2 macros
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ub2parser-0.1.2.tar.gz.
File metadata
- Download URL: ub2parser-0.1.2.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d38937fece0ccc3f397b2e3ea6d161a7724a328c5808cb7f01915e26deb74f5
|
|
| MD5 |
1197e015ce1efe5d20decde64196cf19
|
|
| BLAKE2b-256 |
a4075cd64e4a097cfd784a03b1712cf30c976a10b44a081011eec1053da204b4
|
Provenance
The following attestation bundles were made for ub2parser-0.1.2.tar.gz:
Publisher:
publish.yml on OpenKorabli/ub2parser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ub2parser-0.1.2.tar.gz -
Subject digest:
8d38937fece0ccc3f397b2e3ea6d161a7724a328c5808cb7f01915e26deb74f5 - Sigstore transparency entry: 1982572392
- Sigstore integration time:
-
Permalink:
OpenKorabli/ub2parser@0ff0d5ad580a6d257c3f14aea8eeb6b14ca57160 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/OpenKorabli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ff0d5ad580a6d257c3f14aea8eeb6b14ca57160 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ub2parser-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ub2parser-0.1.2-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3f2d86546a2169bf85a8b2bc1d6fc1fad799bec32ddb70341c35a14b836f73b
|
|
| MD5 |
04a804157b557da12723ff71b48f2a1e
|
|
| BLAKE2b-256 |
e6ab6fdd130b760c8905f33b9121a57ef0ed7870a13a3e5508085dccd2d5c8e9
|
Provenance
The following attestation bundles were made for ub2parser-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on OpenKorabli/ub2parser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ub2parser-0.1.2-py3-none-any.whl -
Subject digest:
d3f2d86546a2169bf85a8b2bc1d6fc1fad799bec32ddb70341c35a14b836f73b - Sigstore transparency entry: 1982572616
- Sigstore integration time:
-
Permalink:
OpenKorabli/ub2parser@0ff0d5ad580a6d257c3f14aea8eeb6b14ca57160 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/OpenKorabli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ff0d5ad580a6d257c3f14aea8eeb6b14ca57160 -
Trigger Event:
push
-
Statement type: