feat(muscript): add factory methods for ExprGroup

This commit is contained in:
Johannes Frohnmeyer 2024-04-05 17:56:57 +02:00
parent 3ec097ce28
commit 4205297661
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.muscript.ast.dynamic;
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
import io.gitlab.jfronny.muscript.ast.Expr;
import io.gitlab.jfronny.muscript.ast.NullLiteral;
import io.gitlab.jfronny.muscript.ast.context.ExprUtils;
import io.gitlab.jfronny.muscript.core.CodeLocation;
import io.gitlab.jfronny.muscript.core.Order;
@ -15,6 +16,16 @@ public record ExprGroup(CodeLocation location, List<Expr> steps, DynamicExpr fin
this(location, expressions.subList(0, expressions.size() - 1), ExprUtils.asDynamic(expressions.getLast()), packedArgs, fork);
}
public static Expr of(CodeLocation location, List<Expr> expressions) {
return of(location, expressions, true);
}
public static Expr of(CodeLocation location, List<Expr> expressions, boolean fork) {
if (expressions.isEmpty()) return new NullLiteral(location);
if (!fork && expressions.size() == 1) return expressions.getFirst();
return new ExprGroup(location, expressions, null, fork);
}
public Stream<Expr> stream() {
return Stream.concat(steps.stream(), Stream.of(finish));
}