org.aya.syntax.concrete.stmt.decl.FnBody Maven / Gradle / Ivy
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.syntax.concrete.stmt.decl;
import kala.collection.immutable.ImmutableSeq;
import org.aya.syntax.concrete.Expr;
import org.aya.syntax.concrete.Pattern;
import org.aya.syntax.ref.LocalVar;
import org.aya.util.error.PosedConsumer;
import org.aya.util.error.PosedUnaryOperator;
import org.aya.util.error.WithPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
public sealed interface FnBody {
FnBody map(@NotNull PosedUnaryOperator f, @NotNull UnaryOperator g);
void forEach(@NotNull PosedConsumer f, @NotNull Consumer g);
record ExprBody(@NotNull WithPos expr) implements FnBody {
@Override public ExprBody map(@NotNull PosedUnaryOperator f, @NotNull UnaryOperator g) {
return new ExprBody(expr.descent(f));
}
@Override public void forEach(@NotNull PosedConsumer f, @NotNull Consumer g) {
f.accept(expr);
}
}
/**
* @param elims NotNull after resolving
*/
record BlockBody(
@NotNull ImmutableSeq clauses,
@Nullable ImmutableSeq elims,
@NotNull ImmutableSeq> rawElims
) implements FnBody {
@Override public BlockBody map(@NotNull PosedUnaryOperator f, @NotNull UnaryOperator g) {
return new BlockBody(clauses.map(g), elims, rawElims);
}
@Override public void forEach(@NotNull PosedConsumer f, @NotNull Consumer g) {
clauses.forEach(g);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy