diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-02-25 18:48:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-02-25 18:48:53 +0000 |
| commit | e7d00f5a62e0f03161dbc12939840d332dc76506 (patch) | |
| tree | c0f76daa9549e18f5808b057d27d8e78c51293cb /src/main/java | |
| parent | 5396117397cda16a4ab23e6c098253af20f085ff (diff) | |
Parse type level params in function signature
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ast/untyped/UntypedFunctionSignatureNode.java | 11 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/parser/Parser.java | 3 |
2 files changed, 14 insertions, 0 deletions
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<List<UntypedTypeLevelParamNode>> typeLevelParams, UntypedParamsNode params, Optional<UntypedTypeLevelExpressionNode> effect, Optional<UntypedTypeLevelExpressionNode> 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<List<UntypedTypeLevelParamNode>> typeLevelParams, PVector<UntypedParamNode> positionalParams, PVector<UntypedParamNode> namedParams, Optional<UntypedTypeLevelExpressionNode> 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<UntypedTypeLevelExpressionNode> 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, |
