From 1c88d4563baea119c86f90ba2ba0c1f9f2e37b91 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 2 Feb 2025 13:09:06 +0000 Subject: Parse native type declarations --- .../UntypedNativeTypeDeclarationNodeMatcher.java | 60 ++++++++++++++++++++++ .../compiler/ast/untyped/UntypedNodeMatchers.java | 4 ++ 2 files changed, 64 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNodeMatcher.java new file mode 100644 index 00000000..f88ecc59 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNativeTypeDeclarationNodeMatcher.java @@ -0,0 +1,60 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.types.Visibility; +import org.shedlang.compiler.util.P; +import org.zwobble.precisely.Matcher; + +import java.util.Optional; + +import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.has; + +public class UntypedNativeTypeDeclarationNodeMatcher extends MatcherBuilder< + UntypedNamespaceStatementNode, + UntypedNativeTypeDeclarationNode, + UntypedNativeTypeDeclarationNodeMatcher +> { + public static UntypedNativeTypeDeclarationNodeMatcher empty() { + return new UntypedNativeTypeDeclarationNodeMatcher(P.vector()); + } + + public UntypedNativeTypeDeclarationNodeMatcher( + PVector> submatchers + ) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedNativeTypeDeclarationNode.class; + } + + @Override + protected UntypedNativeTypeDeclarationNodeMatcher create( + PVector> submatchers + ) { + return new UntypedNativeTypeDeclarationNodeMatcher(submatchers); + } + + public UntypedNativeTypeDeclarationNodeMatcher withName(String name) { + return with(has("name", x -> x.name(), equalTo(name))); + } + + public UntypedNativeTypeDeclarationNodeMatcher withTypeLevelParams( + Matcher>> typeLevelParams + ) { + return with(has("typeLevelParams", x -> x.typeLevelParams(), typeLevelParams)); + } + + public UntypedNativeTypeDeclarationNodeMatcher withVisibility(Visibility visibility) { + return with(has("visibility", x -> x.visibility(), equalTo(visibility))); + } + + public UntypedNativeTypeDeclarationNodeMatcher withMethods( + Matcher> methods + ) { + return with(has("methods", x -> x.methods(), methods)); + } +} diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java index 94fc68e1..24cb61ca 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -239,6 +239,10 @@ public class UntypedNodeMatchers { return UntypedNativeFunctionDeclarationNodeMatcher.empty(); } + public static UntypedNativeTypeDeclarationNodeMatcher isUntypedNativeTypeDeclarationNode() { + return UntypedNativeTypeDeclarationNodeMatcher.empty(); + } + public static Matcher isUntypedNotEqualNode( Matcher left, Matcher right -- cgit v1.2.3