This module provides a get_tree function to obtain an ANTLR parse-tree from a UVL-defined feature model
Project description
UVL - Universal Variability Language
This is a small default library used to parse and print the Universal Variability Language (UVL).
Under the hood it uses ANTLR4 as the parsing library.
The grammar in EBNF form is located in src/main/antlr4/de/vill/UVL.g4
The Language
On a high level, each feature model in UVL consists of five optional separated elements:
- A list of used language levels
The model can use different concepts which are part of language levels. These levels can either be enumerated with the
include
keyword or be implicit. - A namespace which can be used for references in other models
- A list of imports that can be used to reference external feature models The models are referenced by their file name and can be given an alias using a Java import like syntax. External models in subdirectories can be referenced like this: subdir.filename as fn
- The tree hierarchy consisting of: features, group types, and attributes whose relations are specified using nesting (indentation)
Groups may have an arbitrary number of features as child nodes. A feature can also have a feature cardinality.
Attributes consist of a key-value pair whose key is always a string and its value may be a boolean, number, string, a list attributes, a vector, or a constraint. If the value is a constraint the key must be
constraint
. If the value is a list of constraints the key must beconstraints
- Cross-tree constraints Cross-tree constraints may be arbitrary propositional formulas with the following symbols: => (implies), <=> (iff), & (and), | (or), ! (not), or brackets. Through the usage of language levels cross-tree constraints can also contain equations (<,>,==) which consist of expressions (+,-,*,/) with numbers or numerical feature attributes as literals and aggregate functions (avg, sum).
The following snippet shows a simplified server architecture in UVL. We provide more examples (e.g., to show the composition mechanism) in https://github.com/Universal-Variability-Language/uvl-models/tree/main/Feature_Models.
namespace Server
features
Server {abstract}
mandatory
FileSystem
or // with cardinality: [1..*]
NTFS
APFS
EXT4
OperatingSystem {abstract}
alternative
Windows
macOS
Debian
optional
Logging {
default,
log_level "warn" // Feature Attribute
}
constraints
Windows => NTFS
macOS => APFS
In this snippet, we can recognize the following elements:
- The feature
Server
is abstract (i.e., corresponds to no implementation artifact. - Each
Server
requires aFileSystem
and anOperatingSystem
denoted by the mandatory group - The
Server
may haveLogging
denoted by the optional group - A
FileSystem
requires at least one type ofNTFS
,APFS
, andExt4
denoted by the or group - An
OperatingSystem
has exactly one type ofWindows
,macOS
, andDebian
denoted by the alternative group Logging
has the feature attributelog_level
attached which is set to "warn"Windows
requiresNTFS
denoted by the first cross-tree constraintmacOS
requiresAPFS
Building a jar
The library is a maven project and can therefore be build with maven. To update the generated parser classes and create a jar with all necessary dependencies, use:
mvn clean compile assembly:single
The target/uvl-parser-1.0-SNAPSHOT-jar-with-dependencies.jar
includes all dependencies.
Usage from Java
The class de.vill.main.UVLModelFactory
exposes the static method parse(String)
which will return an instance of a de.vill.model.FeatureModel
class. If there is something wrong, a de.vill.exception.ParseError
is thrown. The parser tries to parse the whole model, even if there are errors. If there are multiple errors, a de.vill.exception.ParseErrorList
is returned which contains all errors that occurred.
A model can be printed with the toString()
method of the de.vill.model.FeatureModel
object.
The following snippet shows a minimal example to read and write UVL models using the jar. More usage examples that also show how to use the acquired UVLModel object can be found in src/main/java/de/vill/main/Example.java
// Read
Path filePath = Paths.get(pathAsString);
String content = new String(Files.readAllBytes(filePath));
UVLModelFactory uvlModelFactory = new UVLModelFactory();
FeatureModel featureModel = uvlModelFactory.parse(content);
// Write
String uvlModel = featureModel.toString();
Path filePath = Paths.get(featureModel.getNamespace() + ".uvl");
Files.write(filePath, uvlModel.getBytes());
Links
UVL models:
Other parsers:
- https://github.com/Universal-Variability-Language/uvl-parser deprecated, Initial UVL Parser, based on Clojure and instaparse UVL-Parser
- https://github.com/diverso-lab/uvl-diverso/ Under development, Antlr4 Parser Diverso Lab
Usage of UVL:
- https://github.com/FeatureIDE/FeatureIDE Feature modelling tool
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
File details
Details for the file uvlparser-2.0.0.tar.gz
.
File metadata
- Download URL: uvlparser-2.0.0.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d997b946911b13b775ce647c46a4e8520c3af09d0a7ca340465a3872355b747b |
|
MD5 | e9fbbb3aa0c6a0c4fb9fcee5af681e7b |
|
BLAKE2b-256 | 729cb0070615b1c0e93e28c2ab8da42776e6eb5821048632ffa09bcc8f867c39 |
File details
Details for the file uvlparser-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: uvlparser-2.0.0-py3-none-any.whl
- Upload date:
- Size: 27.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10603768cd21ad3d67661e95b2ff1db1976f38ed1b68ab0b4395a0ad44aedfda |
|
MD5 | d2f273ffafa5d999274a4bec692a85fb |
|
BLAKE2b-256 | c7b36e5ab7332e2f316d95a23957069f035d1bd29fa11edcbde4322c7c4a645d |