feat(muscript): add factory methods for ExprGroup
This commit is contained in:
parent
3ec097ce28
commit
4205297661
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue