Parser for the Universal Variability Language (UVL) with conversion support to CNF/SMT
Project description
uvllang
A Python parser for the Universal Variability Language (UVL) with support for both Lark (default) and ANTLR parsers. In addition, uvllang supports conversion of UVL to CNF / SMT.
Installation
# Install with Lark parser (default, pure Python)
pip install uvllang
# Install with both Lark and ANTLR parsers
pip install uvllang[antlr]
Usage
Basic Usage
from uvllang import UVL
# Parse a UVL file with Lark (default)
model = UVL(from_file="examples/automotive01.uvl")
# Or use ANTLR parser
model = UVL(from_file="examples/automotive01.uvl", use_antlr = True)
# Access features
print(f"Number of features:", len(model.features))
# Access constraints
print("All constraints:", len(model.constraints))
print("Boolean constraints:", len(model.boolean_constraints))
print("Arithmetic constraints:", len(model.arithmetic_constraints))
CNF Conversion
Convert feature models to Conjunctive Normal Form (CNF) for SAT solvers:
from uvllang import UVL
# Parse UVL file
model = UVL(from_file="model.uvl")
# Convert to CNF (returns PySAT CNF object)
cnf = model.to_cnf()
cnf.to_file("output.dimacs")
SMT-LIB 2 Conversion
Convert feature models to SMT-LIB 2 format for SMT solvers (supports arithmetic constraints, types, and aggregates):
from uvllang import UVL
# Parse UVL file with arithmetic constraints
model = UVL(from_file="model.uvl")
# Convert to SMT-LIB 2 format
smt_content = model.to_smt()
# Save to file
with open("output.smt2", "w") as f:
f.write(smt_content)
# Or use Z3 directly
import z3
solver = z3.Solver()
solver.from_string(smt_content)
result = solver.check()
print(result) # sat, unsat, or unknown
SMT-LIB 2 Features:
- Boolean feature selection constraints
- Arithmetic constraints with integer and real types
- String features and length constraints
- Aggregate functions:
sum(attr),avg(attr),len(feature) - Feature attributes and typed declarations
Command Line Interface
# Basic conversion (uses Lark)
uvl2cnf model.uvl
# Specify output file
uvl2cnf model.uvl output.dimacs
# Verbose mode (lists ignored non-Boolean constraints)
uvl2cnf model.uvl -v
# Use ANTLR parser (requires: pip install uvllang[antlr])
uvl2cnf model.uvl --antlr
SMT-LIB 2 conversion:
# Basic conversion (uses Lark)
uvl2smt model.uvl
# Specify output file
uvl2smt model.uvl output.smt2
# Verbose mode (shows model statistics)
uvl2smt model.uvl -v
# Use ANTLR parser
uvl2smt model.uvl --antlr
# Solve with Z3
uvl2smt model.uvl model.smt2 && z3 model.smt2
Dependencies
Core dependencies (always installed):
lark: Lark parsersympy: Symbolic mathematics for Boolean constraint processingpython-sat: SAT solver library for CNF handling
Optional dependencies:
antlr4-python3-runtime: ANTLR4 parser runtime (install with:pip install uvllang[antlr])z3-solver: Z3 SMT solver for solving SMT-LIB 2 constraints (install with:pip install z3-solver)
Both parsers provide identical functionality. Lark is used by default for easier installation and pure Python compatibility.
Testing
# Install development dependencies
pip install -e .[dev]
# Run tests
python -m pytest tests/
Development
# Generate parsers from grammar files (ANTLR)
python generate_parsers.py
# Build
python -m build
Citation
If you use UVL in your research, please cite:
@article{UVL2024,
title = {UVL: Feature modelling with the Universal Variability Language},
journal = {Journal of Systems and Software},
volume = {225},
pages = {112326},
year = {2025},
doi = {https://doi.org/10.1016/j.jss.2024.112326},
author = {David Benavides and Chico Sundermann and Kevin Feichtinger and José A. Galindo and Rick Rabiser and Thomas Thüm}
}
Links
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
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 uvllang-0.2.2.tar.gz.
File metadata
- Download URL: uvllang-0.2.2.tar.gz
- Upload date:
- Size: 51.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bba0e65ca2682932433e36ae2d5a7cd08875ba22dd175e697b57efa4a78755e
|
|
| MD5 |
1bed64276b6008c40bea5543fbe348bd
|
|
| BLAKE2b-256 |
ec5638383c519d0194878753d5802b600cd743babd1979b2e4caaf7185edf3ba
|
File details
Details for the file uvllang-0.2.2-py3-none-any.whl.
File metadata
- Download URL: uvllang-0.2.2-py3-none-any.whl
- Upload date:
- Size: 48.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df14c05b9f1bb13e318645e24fbe3ceb58a9a59661e29fb8a07b753e5434feb5
|
|
| MD5 |
f25cb8d627b05148a1dc0c040f81a556
|
|
| BLAKE2b-256 |
5f9578babd538f66833e6186cf0dfc05868f0cd1cc2c9f38447a8f02ab5cf0ba
|