From 09dcc2a2c64eb2544d810bbc586241346130d258 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Feb 2025 17:12:36 +0000 Subject: Parse type-level params for function type --- .../compiler/ast/untyped/UntypedFunctionTypeNode.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/main/java/org/shedlang/compiler/ast') diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNode.java index b4a465b3..c1b7ad3d 100644 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNode.java +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNode.java @@ -5,9 +5,11 @@ import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.util.P; +import java.util.List; import java.util.Optional; public record UntypedFunctionTypeNode( + Optional> typeLevelParams, UntypedFunctionTypeParamsNode params, Optional effect, UntypedTypeLevelExpressionNode returnType, @@ -15,6 +17,7 @@ public record UntypedFunctionTypeNode( ) implements UntypedTypeLevelExpressionNode { public static Builder builder() { return new Builder( + Optional.empty(), P.vector(), P.vector(), Optional.empty(), @@ -23,6 +26,7 @@ public record UntypedFunctionTypeNode( } public record Builder( + Optional> typeLevelParams, PVector positionalParams, PVector namedParams, Optional effect, @@ -30,6 +34,7 @@ public record UntypedFunctionTypeNode( ) { public UntypedFunctionTypeNode build() { return new UntypedFunctionTypeNode( + this.typeLevelParams, new UntypedFunctionTypeParamsNode(this.positionalParams, this.namedParams, Sources.NULL), this.effect, this.returnType, @@ -37,8 +42,19 @@ public record UntypedFunctionTypeNode( ); } + public Builder withTypeLevelParams(List typeLevelParams) { + return new Builder( + Optional.of(typeLevelParams), + this.positionalParams, + this.namedParams, + this.effect, + this.returnType + ); + } + public Builder addPositionalParam(UntypedTypeLevelExpressionNode param) { return new Builder( + this.typeLevelParams, this.positionalParams.plus(param), this.namedParams, this.effect, @@ -48,6 +64,7 @@ public record UntypedFunctionTypeNode( public Builder addNamedParam(String name, UntypedTypeLevelExpressionNode type) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams.plus(new UntypedFunctionTypeNamedParamNode(name, type, Sources.NULL)), this.effect, @@ -57,6 +74,7 @@ public record UntypedFunctionTypeNode( public Builder withEffect(UntypedTypeLevelExpressionNode effect) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, Optional.of(effect), @@ -66,6 +84,7 @@ public record UntypedFunctionTypeNode( public Builder withReturnType(UntypedTypeLevelExpressionNode returnType) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, this.effect, -- cgit v1.2.3