From d1d0984bc8a157a2f001d3c991dae5c9498cd790 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 22 Oct 2023 22:23:01 +0100 Subject: Parse function types --- .../untyped/UntypedFunctionTypeNodeMatcher.java | 48 ++++++++++++++++++++++ .../compiler/ast/untyped/UntypedNodeMatchers.java | 14 +++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java new file mode 100644 index 00000000..166dd1b0 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedFunctionTypeNodeMatcher.java @@ -0,0 +1,48 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.Empty; +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.zwobble.precisely.Matcher; + +import java.util.Optional; + +import static org.zwobble.precisely.Matchers.has; + +public class UntypedFunctionTypeNodeMatcher extends MatcherBuilder< + UntypedTypeLevelExpressionNode, + UntypedFunctionTypeNode, + UntypedFunctionTypeNodeMatcher +> { + public static UntypedFunctionTypeNodeMatcher empty() { + return new UntypedFunctionTypeNodeMatcher(Empty.vector()); + } + + public UntypedFunctionTypeNodeMatcher(PVector> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedFunctionTypeNode.class; + } + + @Override + protected UntypedFunctionTypeNodeMatcher create( + PVector> submatchers + ) { + return new UntypedFunctionTypeNodeMatcher(submatchers); + } + + public UntypedFunctionTypeNodeMatcher withEffect(Matcher> effect) { + return with(has("effect", x -> x.effect(), effect)); + } + + public UntypedFunctionTypeNodeMatcher withParams(Matcher params) { + return with(has("params", x -> x.params(), params)); + } + + public UntypedFunctionTypeNodeMatcher withReturnType(Matcher returnType) { + return with(has("returnType", x -> x.returnType(), returnType)); + } +} 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 35e8247a..f45adba9 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -123,6 +123,10 @@ public class UntypedNodeMatchers { ); } + public static UntypedFunctionTypeNodeMatcher isUntypedFunctionTypeNode() { + return UntypedFunctionTypeNodeMatcher.empty(); + } + public static Matcher isUntypedIfNode( Matcher> conditionalBranches, Matcher elseBody @@ -188,6 +192,16 @@ public class UntypedNodeMatchers { ); } + public static Matcher isUntypedParamTypesNode( + Matcher> positional, + Matcher> named + ) { + return allOf( + has("positional", x -> x.positional(), positional), + has("named", x -> x.named(), named) + ); + } + public static Matcher isUntypedReferenceNode(String name) { return instanceOf( UntypedReferenceNode.class, -- cgit v1.2.3