Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ component grammar SysMLExpressions
* name of the function to be invoked and an argument list for any remaining arguments (see 7.4.9.4). This is
* useful for chaining invocations in an effective data flow
*/
SysMLFunctionOperationExpression implements Expression =
Expression "->" Name ("(" (SysMLParameter || ",")* ")")? ("{" SysMLElement* inner:Expression "}")? ;
SysMLFunctionOperationExpression implements Expression <291> =
Expression "->" SysMLQualifiedName (Arguments)?
("{" SysMLElement* inner:Expression "}")? ;

// Eigentlich ist "^" der Name einer CalcDef aus den Domain Libraries
CalcDefPowerExpression implements Expression =
Expand Down
62 changes: 62 additions & 0 deletions language/src/test/java/parser/ExpressionParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import de.monticore.lang.sysmlexpressions._ast.ASTSysMLFunctionOperationExpression;
import de.monticore.expressions.commonexpressions._ast.ASTFieldAccessExpression;

import java.io.IOException;

Expand Down Expand Up @@ -82,4 +84,64 @@ public void testElementOf() throws IOException {
assertThat(ast.get()).isInstanceOf(ASTElementOfExpression.class);
}

@Test
public void testSysMLFunctionOperatorExprMinimal() throws IOException {
var ast = parser.parse_StringExpression("x->b()");

assertThat(ast).isPresent();
assertThat(Log.getFindings()).isEmpty();
assertThat(ast.get())
.isInstanceOf(ASTSysMLFunctionOperationExpression.class);
}

@Test
public void testSysMLFunctionOperatorExpr() throws IOException {
var ast = parser.parse_StringExpression("x->excludes(y)");

assertThat(ast).isPresent();
assertThat(Log.getFindings()).isEmpty();
assertThat(ast.get())
.isInstanceOf(ASTSysMLFunctionOperationExpression.class);
}

@Test
public void testSysMLFunctionOperatorExpr2() throws IOException {
var ast = parser.parse_StringExpression("x->excludes(y.z)");

assertThat(ast).isPresent();
assertThat(Log.getFindings()).isEmpty();
assertThat(ast.get())
.isInstanceOf(ASTSysMLFunctionOperationExpression.class);
}

/**
* Checks that qualified names on both sides of a function operation
* are parsed with the correct binding.
*/
@ParameterizedTest
@ValueSource(strings = {
"a.b->c.d",
"a::b->c::d",
"a::b->c.d",
"a.b->c::d"
})
public void testQualifiedNamesInFunctionOperation(String expr)
throws IOException {

var ast = parser.parse_StringExpression(expr);

assertThat(ast).isPresent();
assertThat(Log.getFindings()).isEmpty();
assertThat(ast.get())
.isInstanceOf(ASTSysMLFunctionOperationExpression.class);

var functionOperation =
(ASTSysMLFunctionOperationExpression) ast.get();

assertThat(functionOperation.getExpression())
.isInstanceOf(ASTFieldAccessExpression.class);
assertThat(functionOperation.getSysMLQualifiedName().getPartsList())
.containsExactly("c", "d");
}

}
Loading