Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lang/expression-parser/model/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tools.vitruv</groupId>
<artifactId>tools.vitruv.neojoin.expression_parser</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>

<artifactId>tools.vitruv.neojoin.expression_parser.model</artifactId>

<name>Expression Parser Model</name>
<description />

<dependencies>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.Nullable;

/**
* A FeatureCall represents a feature (e.g. a variable), stores information about the type and is
* the first operation in a reference chain.
*
* <p>An example expression may look like
*
* <pre>
* {@code someResult = car.axis.flatMap(a -> a.wheels).toList()}
* </pre>
*
* Here, {@code car} is a FeatureCall
*
* <p>A FeatureCall is also the first operation in a nested expression:
*
* <pre>
* {@code someResult = car.axis.flatMap(oneAxis -> oneAxis.wheels).toList()}
* </pre>
*
* Here, {@code oneAxis} is also a FeatureCall
*/
@Data
@RequiredArgsConstructor
public class FeatureCall implements ReferenceOperator {
@Nullable final String identifier;
@Nullable final String simpleName;

@Nullable ReferenceOperator followingOperator;

public static FeatureCall empty() {
return new FeatureCall(null, null);
}

@Override
public String toString() {
final String stringRepresentation = "FeatureCall(" + simpleName + ")";
if (followingOperator == null) {
return stringRepresentation;
}

return stringRepresentation + "->" + followingOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Value;

@Value
public class FeatureInformation {
String featureName;
String featureClassSimpleName;
String featureClassIdentifier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.Nullable;

/**
* FindAny selects any element from a collection of elements. There are no guarantees which element
* will be selected
*
* <p>Example expressions may look like
*
* <pre>
* {@code
* someResult = car.axis.findFirst()
* someResult = car.axis.findLast()
* }
* </pre>
*
* Here, {@code X.findFirst()} and {@code X.findLast()} are FindAny operations
*/
@Data
@RequiredArgsConstructor
public class FindAny implements ReferenceOperator {
@Nullable ReferenceOperator followingOperator;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* A FlatMap represents mapping a parent object to some children along a <b>one-to-many</b>
* reference and flattening the result. It contains information about the reference and the child type
*
* <p>An example expression may look like
*
* <pre>
* {@code someResult = car.axis.flatMap(a -> a.wheels).toList()}
* </pre>
*
* Here, {@code X.flatMap(a -> a.wheels)} is a FlatMap
*/
@Data
@RequiredArgsConstructor
public class FlatMap implements ReferenceOperator {
@NonNull final FeatureInformation featureInformation;

@Nullable ReferenceOperator followingOperator;

@Override
public String toString() {
final String stringRepresentation = "FlatMap(" + featureInformation.getFeatureName() + ")";
if (followingOperator == null) {
return stringRepresentation;
}

return stringRepresentation + "->" + followingOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* A Map represents mapping a parent object to some child along a <b>one-to-one</b> reference. It
* contains information about the reference and the child type
*
* <p>An example expression may look like
*
* <pre>
* {@code someResult = car.axis.map(a -> a.axisInformation).toList()}
* </pre>
*
* Here, {@code X.map(a -> a.axisInformation)} is a Map
*/
@Data
@RequiredArgsConstructor
public class Map implements ReferenceOperator {
@NonNull final FeatureInformation featureInformation;

@Nullable ReferenceOperator followingOperator;

@Override
public String toString() {
final String stringRepresentation = "Map(" + featureInformation.getFeatureName() + ")";
if (followingOperator == null) {
return stringRepresentation;
}

return stringRepresentation + "->" + followingOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* A MemberFeatureCall represents a field/reference access of a parent class. It contains
* information about the type and reference name. The reference can have an upper and/or lower bound
*
* <p>An example expression may look like
*
* <pre>
* {@code someResult = car.axis.flatMap(a -> a.wheels).toList()}
* </pre>
*
* Here, {@code X.axis} is a MemberFeatureCall
*/
@Data
@RequiredArgsConstructor
public class MemberFeatureCall implements ReferenceOperator {
@NonNull final FeatureInformation featureInformation;
final boolean isCollection;

@Nullable ReferenceOperator followingOperator;

@Override
public String toString() {
final String stringRepresentation = "MemberFeatureCall(" + featureInformation.getFeatureName() + ")";
if (followingOperator == null) {
return stringRepresentation;
}

return stringRepresentation + "->" + followingOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package tools.vitruv.neojoin.expression_parser.model;

import lombok.Data;
import lombok.RequiredArgsConstructor;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import tools.vitruv.neojoin.expression_parser.model.predicate_expression.ComparisonOperator;
import tools.vitruv.neojoin.expression_parser.model.predicate_expression.ConstantValue;

/**
* A ReferenceFilter represents a predicate for the previous ReferenceOperator. Only predicates that
* compare a feature to some constant value are supported
*
* <p>An example expression may look like
*
* <pre>
* {@code someResult = car.axis.filter(a -> a.position == "front").toList()}
* </pre>
*
* Here, {@code X.filter(a -> a.position == "front")} is a ReferenceFilter
*/
@Data
@RequiredArgsConstructor
public class ReferenceFilter implements ReferenceOperator {
@NonNull final String feature;
@NonNull final ComparisonOperator operator;
@NonNull final ConstantValue constantValue;

@Nullable ReferenceOperator followingOperator;

@Override
public String toString() {
final String stringRepresentation =
"ReferenceFilter("
+ feature
+ " "
+ operator.getRepresentation()
+ " "
+ constantValue
+ ")";
if (followingOperator == null) {
return stringRepresentation;
}

return stringRepresentation + "->" + followingOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tools.vitruv.neojoin.expression_parser.model;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* A ReferenceOperator is a (partial) parsed expression that can be used for model transformations.
* It contains the required properties (e.g. type, field names) for the following steps and possibly
* the following ReferenceOperator-chain
*/
public interface ReferenceOperator {
@Nullable ReferenceOperator getFollowingOperator();

void setFollowingOperator(ReferenceOperator followingOperator);

/** Returns the last ReferenceOperator in this chain */
@NonNull
default ReferenceOperator getLastOperatorInChain() {
ReferenceOperator lastOperator = this;
while (lastOperator.getFollowingOperator() != null) {
lastOperator = lastOperator.getFollowingOperator();
}
return lastOperator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tools.vitruv.neojoin.expression_parser.model.predicate_expression;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ComparisonOperator {
Equals("=="),
NotEquals("!="),
LessThan("<"),
LessEquals("<="),
GreaterThan(">"),
GreaterEquals(">=");

final String representation;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tools.vitruv.neojoin.expression_parser.model.predicate_expression;

import lombok.Value;

@Value
public class ConstantValue {
String value;
boolean isString;

public static ConstantValue fromString(String value) {
return new ConstantValue(value, true);
}

public static ConstantValue fromBoolean(boolean isTrue) {
return ConstantValue.of(Boolean.toString(isTrue));
}

public static ConstantValue of(String value) {
return new ConstantValue(value, false);
}

@Override
public String toString() {
if (isString) {
return "\"" + value + "\"";
}
return value;
}
}
Loading
Loading