diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-02-02 13:09:06 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-02-02 13:10:52 +0000 |
| commit | 1c88d4563baea119c86f90ba2ba0c1f9f2e37b91 (patch) | |
| tree | 421e7ed25dede77fd7823a8b4a1c310378d347bf /src/main/java/org/shedlang/compiler/ast | |
| parent | fb439df085eb1f7095d987973475a7753d0a1103 (diff) | |
Parse native type declarations
Diffstat (limited to 'src/main/java/org/shedlang/compiler/ast')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java | 2 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNode.java | 71 |
2 files changed, 72 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java index c4981b68..a49a3c85 100644 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java @@ -1,4 +1,4 @@ package org.shedlang.compiler.ast.untyped; -public sealed interface UntypedNamespaceStatementNode extends UntypedNode permits UntypedAssignNode, UntypedEffectDefinitionNode, UntypedFunctionDefinitionNode, UntypedNativeFunctionDeclarationNode, UntypedStructDefinitionNode, UntypedSumTypeDefinitionNode { +public sealed interface UntypedNamespaceStatementNode extends UntypedNode permits UntypedAssignNode, UntypedEffectDefinitionNode, UntypedFunctionDefinitionNode, UntypedNativeFunctionDeclarationNode, UntypedNativeTypeDeclarationNode, UntypedStructDefinitionNode, UntypedSumTypeDefinitionNode { } diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNode.java new file mode 100644 index 00000000..fcfda66d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNode.java @@ -0,0 +1,71 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.PVector; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.types.Visibility; +import org.shedlang.compiler.util.P; + +import java.util.List; +import java.util.Optional; + +public record UntypedNativeTypeDeclarationNode( + String name, + Visibility visibility, + Optional<List<UntypedTypeLevelParamNode>> typeLevelParams, + List<UntypedNativeFunctionDeclarationNode> methods, + Source source +) implements UntypedNamespaceStatementNode, UntypedVariableDeclarationNode { + public static Builder builder() { + return new Builder( + "X", + Visibility.PRIVATE, + Optional.empty(), + P.vector() + ); + } + + public record Builder( + String name, + Visibility visibility, + Optional<List<UntypedTypeLevelParamNode>> typeLevelParams, + PVector<UntypedNativeFunctionDeclarationNode> methods + ) { + public UntypedNativeTypeDeclarationNode build() { + return new UntypedNativeTypeDeclarationNode( + this.name, + this.visibility, + this.typeLevelParams, + this.methods, + Sources.NULL + ); + } + + public Builder withName(String name) { + return new Builder( + name, + this.visibility, + this.typeLevelParams, + this.methods + ); + } + + public Builder withTypeLevelParams(List<UntypedTypeLevelParamNode> typeLevelParams) { + return new Builder( + this.name, + this.visibility, + Optional.of(typeLevelParams), + this.methods + ); + } + + public Builder addMethod(UntypedNativeFunctionDeclarationNode method) { + return new Builder( + this.name, + this.visibility, + this.typeLevelParams, + this.methods.plus(method) + ); + } + } +} |
