From e7d00f5a62e0f03161dbc12939840d332dc76506 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 25 Feb 2024 18:48:53 +0000 Subject: Parse type level params in function signature --- .../compiler/ast/untyped/UntypedFunctionSignatureNode.java | 11 +++++++++++ src/main/java/org/shedlang/compiler/parser/Parser.java | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionSignatureNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionSignatureNode.java index 641a9411..42795805 100644 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionSignatureNode.java +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionSignatureNode.java @@ -5,9 +5,11 @@ import org.pcollections.PVector; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; +import java.util.List; import java.util.Optional; public record UntypedFunctionSignatureNode( + Optional> typeLevelParams, UntypedParamsNode params, Optional effect, Optional returnType, @@ -15,6 +17,7 @@ public record UntypedFunctionSignatureNode( ) implements UntypedNode { public static Builder builder() { return new Builder( + Optional.empty(), Empty.vector(), Empty.vector(), Optional.empty(), @@ -24,6 +27,7 @@ public record UntypedFunctionSignatureNode( } public record Builder( + Optional> typeLevelParams, PVector positionalParams, PVector namedParams, Optional effect, @@ -32,6 +36,7 @@ public record UntypedFunctionSignatureNode( ) { public UntypedFunctionSignatureNode build() { return new UntypedFunctionSignatureNode( + typeLevelParams, new UntypedParamsNode(positionalParams, namedParams, Sources.NULL), effect, returnType, @@ -49,6 +54,7 @@ public record UntypedFunctionSignatureNode( ) { var paramNode = new UntypedParamNode(name, type, Sources.NULL); return new Builder( + this.typeLevelParams, this.positionalParams.plus(paramNode), this.namedParams, this.effect, @@ -64,6 +70,7 @@ public record UntypedFunctionSignatureNode( public Builder addNamedParam(String name, Optional type) { var paramNode = new UntypedParamNode(name, type, Sources.NULL); return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams.plus(paramNode), this.effect, @@ -74,6 +81,7 @@ public record UntypedFunctionSignatureNode( public Builder withEffect(UntypedTypeLevelExpressionNode effect) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, Optional.of(effect), @@ -84,6 +92,7 @@ public record UntypedFunctionSignatureNode( public Builder withReturnType(UntypedTypeLevelExpressionNode returnType) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, this.effect, @@ -94,6 +103,7 @@ public record UntypedFunctionSignatureNode( public Builder withoutReturnType() { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, this.effect, @@ -104,6 +114,7 @@ public record UntypedFunctionSignatureNode( public Builder addStatement(UntypedFunctionStatementNode statement) { return new Builder( + this.typeLevelParams, this.positionalParams, this.namedParams, this.effect, diff --git a/src/main/java/org/shedlang/compiler/parser/Parser.java b/src/main/java/org/shedlang/compiler/parser/Parser.java index aed9d79d..73f9cb23 100644 --- a/src/main/java/org/shedlang/compiler/parser/Parser.java +++ b/src/main/java/org/shedlang/compiler/parser/Parser.java @@ -501,6 +501,8 @@ public class Parser { ) { var start = tokens.position(); + var typeLevelParams = parseTypeLevelParamsOptional(tokens); + tokens.skip(TokenType.SYMBOL_PAREN_OPEN); var params = parseParams(tokens); tokens.skip(TokenType.SYMBOL_PAREN_CLOSE); @@ -513,6 +515,7 @@ public class Parser { var source = start.to(end); return new UntypedFunctionSignatureNode( + typeLevelParams, params, effect, returnType, -- cgit v1.2.3