|
1 | 1 | # UVL - Universal Variability Language |
2 | 2 |
|
3 | | -This is a small default library used to parse and print the Universal Variability Language (UVL). |
4 | | - |
5 | | -Under the hood it uses [ANTLR4](https://www.antlr.org/) as the parsing library. |
6 | | -The grammar in EBNF form is located in `uvl/UVL.g4` and the modifications for Java and Python |
7 | | - |
8 | | -## The Language |
9 | | - |
10 | | -On a high level, each feature model in UVL consists of five optional separated elements: |
11 | | - |
12 | | -1. **A list of used language levels** |
13 | | - 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. |
14 | | -2. **A namespace which can be used for references in other models** |
15 | | -3. **A list of imports that can be used to reference external feature models** |
16 | | - The models are referenced by their file name and can be given an alias using a Java import like syntax. |
17 | | - External models in subdirectories can be referenced like this: subdir.filename as fn |
18 | | -4. **The tree hierarchy consisting of: features, group types, and attributes whose relations are specified using nesting (indentation)** |
19 | | - Groups may have an arbitrary number of features as child nodes. A feature can also have a feature cardinality. |
20 | | - 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 be `constraints` |
21 | | -5. **Cross-tree constraints** |
22 | | - 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). |
23 | | - The sum and avg functions compute the total or average of a numeric attribute across all instances, optionally limited to a specified feature subtree, using the syntax e.g. |
| 3 | +**UVL (Universal Variability Language)** is a concise and extensible language for modeling variability in software product lines. It supports multiple programming languages and provides a grammar-based foundation for building tools and parsers. |
| 4 | + |
| 5 | +This repository contains the **ANTLR4 grammar files** for UVL. With these, you can generate parsers for UVL tailored to specific programming languages like Java, JavaScript, and Python. |
| 6 | + |
| 7 | +## ✨ Key Features |
| 8 | + |
| 9 | +- Language-level modularity |
| 10 | +- Namespaces and imports |
| 11 | +- Feature trees with attributes and cardinalities |
| 12 | +- Cross-tree constraints |
| 13 | +- Extensible for different target languages |
| 14 | + |
| 15 | +## 📦 Repository Structure |
| 16 | + |
| 17 | +- `uvl/UVLParser.g4` – Base grammar in EBNF form |
| 18 | +- `uvl/UVLLexer.g4` – Base lexer grammar for UVL |
| 19 | +- `uvl/Java/UVLJava*.g4`, `uvl/Python/UVLPython*.g4`, etc. – Language-specific grammar files |
| 20 | +- `java/` – Java-based parser implementation using Maven (generated) |
| 21 | +- `python/` – Python-based parser implementation (generated) |
| 22 | +- `js/` – JavaScript-based parser implementation (generated) |
| 23 | + |
| 24 | +UVL uses [ANTLR4](https://www.antlr.org/) as its parser generator. |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +To use UVL in your projects, you can either: |
| 29 | + |
| 30 | +1. **Use the pre-built parsers** |
| 31 | + ### Java Parser |
| 32 | + Include the following dependency in your Maven project: |
| 33 | + ```xml |
| 34 | + <dependency> |
| 35 | + <groupId>io.github.universal-variability-language</groupId> |
| 36 | + <artifactId>uvl-parser</artifactId> |
| 37 | + <version>0.3</version> |
| 38 | + </dependency> |
| 39 | + ``` |
| 40 | + ### Python Parser |
| 41 | + Install the package via pip: |
| 42 | + ```bash |
| 43 | + pip install uvlparser |
24 | 44 | ``` |
25 | | - constraints |
26 | | - sum(att, rootFeature). |
| 45 | + ### JavaScript Parser |
| 46 | + Install the package via npm: |
| 47 | + ```bash |
| 48 | + npm install uvl-parser |
27 | 49 | ``` |
| 50 | +2. **Build the parser manually** See the sections below for details. |
28 | 51 |
|
29 | | -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](https://github.com/Universal-Variability-Language/uvl-models/tree/main/Feature_Models). |
| 52 | +## ⚙️ Building the Parser manually |
30 | 53 |
|
| 54 | +### Java Parser |
| 55 | + |
| 56 | +#### Prerequisites |
| 57 | + |
| 58 | +- Java 17+ |
| 59 | +- [Maven](https://maven.apache.org/) |
| 60 | + |
| 61 | +#### Build Steps |
| 62 | + |
| 63 | +1. Clone the repository: |
| 64 | + |
| 65 | +```bash |
| 66 | + git clone https://github.com/Universal-Variability-Language/uvl-parser |
31 | 67 | ``` |
32 | | -namespace Server |
33 | | -
|
34 | | -features |
35 | | - Server {abstract} |
36 | | - mandatory |
37 | | - FileSystem |
38 | | - or // with cardinality: [1..*] |
39 | | - NTFS |
40 | | - APFS |
41 | | - EXT4 |
42 | | - OperatingSystem {abstract} |
43 | | - alternative |
44 | | - Windows |
45 | | - macOS |
46 | | - Debian |
47 | | - optional |
48 | | - Logging { |
49 | | - default, |
50 | | - log_level "warn" // Feature Attribute |
51 | | - } |
52 | | -
|
53 | | -constraints |
54 | | - Windows => NTFS |
55 | | - macOS => APFS |
| 68 | + |
| 69 | +2. Build the parser: |
| 70 | + |
| 71 | +```bash |
| 72 | +make java_parser |
| 73 | +``` |
| 74 | + |
| 75 | +This will generate the jar file in the `java/target/` directory. You can also build the JAR with: |
| 76 | + |
| 77 | +```bash |
| 78 | +cd java && mvn clean package |
56 | 79 | ``` |
57 | 80 |
|
58 | | -In this snippet, we can recognize the following elements: |
| 81 | +3. Include the generated JAR in your Java project. |
59 | 82 |
|
60 | | -- The feature `Server` is abstract (i.e., corresponds to no implementation artifact. |
61 | | -- Each `Server` requires a `FileSystem`and an `OperatingSystem` denoted by the _mandatory_ group |
62 | | -- The `Server` may have `Logging` denoted by the _optional_ group |
63 | | -- A `FileSystem` requires at least one type of `NTFS`, `APFS`, and `Ext4` denoted by the _or_ group |
64 | | -- An `OperatingSystem` has exactly one type of `Windows`, `macOS`, and `Debian`denoted by the _alternative_ group |
65 | | -- `Logging` has the feature attribute `log_level` attached which is set to "warn" |
66 | | -- `Windows` requires `NTFS` denoted by the first cross-tree constraint |
67 | | -- `macOS`requires `APFS` |
| 83 | +--- |
68 | 84 |
|
69 | | -## Building a jar |
| 85 | +### Python Parser |
70 | 86 |
|
71 | | -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: |
| 87 | +#### Prerequisites |
72 | 88 |
|
| 89 | +- Python 3.8+ |
| 90 | +- [ANTLR4](https://www.antlr.org/) |
| 91 | + |
| 92 | +#### Build Steps |
| 93 | + |
| 94 | +1. Clone the repository: |
| 95 | + |
| 96 | +```bash |
| 97 | + git clone https://github.com/Universal-Variability-Language/uvl-parser |
| 98 | +``` |
| 99 | + |
| 100 | +2. Build the parser: |
| 101 | + |
| 102 | +```bash |
| 103 | + make python_parser |
73 | 104 | ``` |
74 | | -mvn clean compile assembly:single |
| 105 | + |
| 106 | +This will generate the parser files in the `python/` directory. To build the wheel package, run: |
| 107 | + |
| 108 | +```bash |
| 109 | + make python_prepare_package |
75 | 110 | ``` |
76 | 111 |
|
77 | | -The `target/uvl-parser-1.0-SNAPSHOT-jar-with-dependencies.jar` includes all dependencies. |
| 112 | +### JavaScript Parser |
78 | 113 |
|
79 | | -## Usage from Java |
| 114 | +#### Prerequisites |
80 | 115 |
|
81 | | -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. |
82 | | -A model can be printed with the `toString()` method of the `de.vill.model.FeatureModel` object. |
83 | | -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](https://github.com/Universal-Variability-Language/java-fm-metamodel/blob/main/src/main/java/de/vill/main/Example.java) |
| 116 | +- Node.js 14+ |
| 117 | +- [ANTLR4](https://www.antlr.org/) |
84 | 118 |
|
85 | | -```Java |
86 | | -// Read |
87 | | -Path filePath = Paths.get(pathAsString); |
88 | | -String content = new String(Files.readAllBytes(filePath)); |
89 | | -UVLModelFactory uvlModelFactory = new UVLModelFactory(); |
90 | | -FeatureModel featureModel = uvlModelFactory.parse(content); |
| 119 | +#### Build Steps |
91 | 120 |
|
| 121 | +1. Clone the repository: |
92 | 122 |
|
93 | | -// Write |
94 | | -String uvlModel = featureModel.toString(); |
95 | | -Path filePath = Paths.get(featureModel.getNamespace() + ".uvl"); |
96 | | -Files.write(filePath, uvlModel.getBytes()); |
| 123 | +```bash |
| 124 | + git clone https://github.com/Universal-Variability-Language/uvl-parser |
97 | 125 | ``` |
98 | 126 |
|
99 | | -## Links |
| 127 | +2. Build the parser: |
100 | 128 |
|
101 | | -UVL models: |
| 129 | +```bash |
| 130 | +make javascript_parser |
| 131 | +``` |
102 | 132 |
|
103 | | -- https://github.com/Universal-Variability-Language/uvl-models |
| 133 | +## This will generate the parser files in the `js/` directory. |
104 | 134 |
|
105 | | -Other parsers: |
| 135 | +## 💡 Universal-Variability-Language (UVL) |
| 136 | + |
| 137 | +For comprehensive guidance on utilizing UVL, please refer to the following publication: |
| 138 | + |
| 139 | +[](https://doi.org/10.1016/j.jss.2024.112326) |
| 140 | + |
| 141 | +🔗 **Sample UVL models** are available at: https://github.com/Universal-Variability-Language/uvl-models |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## 📚 Resources |
| 146 | + |
| 147 | +**UVL Models & Tools** |
| 148 | + |
| 149 | +- https://github.com/Universal-Variability-Language/uvl-models |
| 150 | +- https://www.uvlhub.io/ |
| 151 | + |
| 152 | +**Tooling Ecosystem** |
| 153 | + |
| 154 | +- https://github.com/FeatureIDE/FeatureIDE |
| 155 | +- https://ide.flamapy.org/ |
| 156 | +- https://github.com/Universal-Variability-Language/uvl-lsp |
| 157 | +- https://github.com/SECPS/TraVarT |
| 158 | +- https://github.com/AlexCortinas/spl-js-engine |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## 📖 Citation |
| 163 | + |
| 164 | +If you use UVL in your research, please cite: |
| 165 | + |
| 166 | +```bibtex |
| 167 | +@article{UVL2024, |
| 168 | + title = {UVL: Feature modelling with the Universal Variability Language}, |
| 169 | + journal = {Journal of Systems and Software}, |
| 170 | + volume = {225}, |
| 171 | + pages = {112326}, |
| 172 | + year = {2025}, |
| 173 | + issn = {0164-1212}, |
| 174 | + doi = {https://doi.org/10.1016/j.jss.2024.112326}, |
| 175 | + url = {https://www.sciencedirect.com/science/article/pii/S0164121224003704}, |
| 176 | + author = {David Benavides and Chico Sundermann and Kevin Feichtinger and José A. Galindo and Rick Rabiser and Thomas Thüm}, |
| 177 | + keywords = {Feature model, Software product lines, Variability} |
| 178 | +} |
| 179 | +``` |
106 | 180 |
|
107 | | -- https://github.com/Universal-Variability-Language/uvl-parser _deprecated, Initial UVL Parser, based on Clojure and instaparse_ **UVL-Parser** |
108 | | -- https://github.com/diverso-lab/uvl-diverso/ _Under development, Antlr4 Parser_ **Diverso Lab** |
| 181 | +--- |
109 | 182 |
|
110 | | -Usage of UVL: |
| 183 | +## 📬 Contact & Contributions |
111 | 184 |
|
112 | | -- https://github.com/FeatureIDE/FeatureIDE _Feature modelling tool_ |
| 185 | +Feel free to open issues or pull requests if you have suggestions or improvements. For questions or collaboration inquiries, visit the UVL Website: |
| 186 | +https://universal-variability-language.github.io/ |
0 commit comments