Skip to content

Commit caa8148

Browse files
BREAKING CHANGE: Adopt new structure for proper grammar generation (#60)
* Reworked the parser generation * Use an UTF-8 maven build * Working python grammar * JS grammar generation is now working * Minor changes to the README * fix: remove tests which are not necessary here * docs: change some guidance on the uvl-models * Updated Java to 21 * Fixed arithmatic expression bug * New npm command for the grammar generation * Removed unnecessary exports * Restored comments in UVLJavaLexer" * Fixed wrong symbols in the grammar * fix: Closes #41, wrong pointer to same charakter --------- Co-authored-by: Miriam Gaus <ugwan@student.kit.edu>
1 parent 7991247 commit caa8148

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+729
-754
lines changed

.gitignore

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
# User-specific stuff
1+
# VSCode, Eclipse, and IntelliJ IDEA project files
22
.vscode
3+
.settings
4+
.classpath
5+
.project
6+
.idea
7+
8+
# Python virtual environments
39
env
10+
build
411
python/uvl/__pycache__
5-
uvl/.antlr
12+
python/uvl/*
13+
!python/uvl/UVLCustomLexer.py
14+
15+
# Node.js
616
js/node_modules
7-
js/package-lock.json
17+
js/package-lock.json
18+
19+
# Java build files
20+
.antlr/
21+
target/

Makefile

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1+
.PHONY: all java_parser python_parser js_parser python_prepare_package clean test dev
2+
13
all: java_parser python_parser js_parser
24

5+
LIB_FLAG = -lib
6+
LIB_PATH = uvl
7+
8+
ROOT_DIR = $(shell pwd)
9+
PYTHON_OUTPUT_DIR = python/uvl
10+
JAVASCRIPT_OUTPUT_DIR = js/src/lib
11+
312
java_parser:
4-
antlr4 -Dlanguage=Java -o java/src/main/ uvl/UVLJava.g4
5-
cd java && mvn compile
13+
cd java && mvn package
614
cd java && mvn install
715

16+
js_parser:
17+
mkdir -p $(JAVASCRIPT_OUTPUT_DIR)
18+
cd uvl/JavaScript && \
19+
antlr4 $(LIB_FLAG) $(ROOT_DIR)/$(LIB_PATH) -Dlanguage=JavaScript -o $(ROOT_DIR)/$(JAVASCRIPT_OUTPUT_DIR) UVLJavaScriptLexer.g4 UVLJavaScriptParser.g4
20+
821
python_parser:
9-
antlr4 -Dlanguage=Python3 -o python uvl/UVLPython.g4
10-
cp README.md python
11-
cd python && python setup.py build
22+
cd uvl/Python && \
23+
antlr4 $(LIB_FLAG) $(ROOT_DIR)/$(LIB_PATH) -Dlanguage=Python3 -o $(ROOT_DIR)/$(PYTHON_OUTPUT_DIR) UVLPythonLexer.g4 UVLPythonParser.g4
1224

13-
js_parser:
14-
mkdir -p js/src/lib
15-
antlr4 -Dlanguage=JavaScript -o js/src/lib/ uvl/UVLJavaScript.g4
16-
1725
python_prepare_package:
1826
cd python && python3 -m build
1927

2028
clean:
21-
# Remove generated Java files except CustomLexer.java and Main.java
22-
find java/src/ -type f ! -name 'UVLCustomLexer.java' ! -name 'Main.java' -delete
29+
# Clean Java build artifacts
30+
cd java && mvn clean
31+
2332
# Remove generated Python files except custom_lexer.py and main.py
2433
find python/uvl/ -type f ! -name 'UVLCustomLexer.py' ! -name 'main.py' -delete
2534
# Remove compiled Python files
2635
find . -name "*.pyc" -exec rm {} \;
2736
# Remove Python build artifacts
2837
rm -rf python/build python/dist
29-
# Clean Java build artifacts
30-
cd java && mvn clean
38+
39+
# Clean JavaScript generated files
40+
rm -rf js/src/lib
41+
3142

3243
test:
3344
python3 ./python/main.py ./tests/parsing/boolean.uvl

README.md

Lines changed: 157 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,186 @@
11
# UVL - Universal Variability Language
22

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
2444
```
25-
constraints
26-
sum(att, rootFeature).
45+
### JavaScript Parser
46+
Install the package via npm:
47+
```bash
48+
npm install uvl-parser
2749
```
50+
2. **Build the parser manually** See the sections below for details.
2851

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
3053

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
3167
```
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
5679
```
5780

58-
In this snippet, we can recognize the following elements:
81+
3. Include the generated JAR in your Java project.
5982

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+
---
6884

69-
## Building a jar
85+
### Python Parser
7086

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
7288

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
73104
```
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
75110
```
76111

77-
The `target/uvl-parser-1.0-SNAPSHOT-jar-with-dependencies.jar` includes all dependencies.
112+
### JavaScript Parser
78113

79-
## Usage from Java
114+
#### Prerequisites
80115

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/)
84118

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
91120

121+
1. Clone the repository:
92122

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
97125
```
98126

99-
## Links
127+
2. Build the parser:
100128

101-
UVL models:
129+
```bash
130+
make javascript_parser
131+
```
102132

103-
- https://github.com/Universal-Variability-Language/uvl-models
133+
## This will generate the parser files in the `js/` directory.
104134

105-
Other parsers:
135+
## 💡 Universal-Variability-Language (UVL)
136+
137+
For comprehensive guidance on utilizing UVL, please refer to the following publication:
138+
139+
[![DOI](https://img.shields.io/badge/DOI-10.1016%2Fj.jss.2024.112326-blue)](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+
```
106180

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+
---
109182

110-
Usage of UVL:
183+
## 📬 Contact & Contributions
111184

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

Comments
 (0)