Skip to main content

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:

  1. 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.
  2. Parser — a recursive-descent parser that builds a concrete syntax tree (CST). Each node records its start and end positions within the token stream.
  3. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ub2parser-0.1.2.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ub2parser-0.1.2-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

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

Hashes for ub2parser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d38937fece0ccc3f397b2e3ea6d161a7724a328c5808cb7f01915e26deb74f5
MD5 1197e015ce1efe5d20decde64196cf19
BLAKE2b-256 a4075cd64e4a097cfd784a03b1712cf30c976a10b44a081011eec1053da204b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ub2parser-0.1.2.tar.gz:

Publisher: publish.yml on OpenKorabli/ub2parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ub2parser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3f2d86546a2169bf85a8b2bc1d6fc1fad799bec32ddb70341c35a14b836f73b
MD5 04a804157b557da12723ff71b48f2a1e
BLAKE2b-256 e6ab6fdd130b760c8905f33b9121a57ef0ed7870a13a3e5508085dccd2d5c8e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ub2parser-0.1.2-py3-none-any.whl:

Publisher: publish.yml on OpenKorabli/ub2parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page