From 71544066ce3b74c18973e00348ea44faf052d5e5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 2 Nov 2023 18:59:09 +0000 Subject: Parse try expressions --- .../compiler/ast/untyped/UntypedNodeMatchers.java | 4 ++ .../ast/untyped/UntypedTryNodeMatcher.java | 50 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/ast/untyped/UntypedTryNodeMatcher.java (limited to 'src/test/java/org/shedlang/compiler/ast') 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 517ca77a..a9befa70 100644 --- a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedNodeMatchers.java @@ -311,6 +311,10 @@ public class UntypedNodeMatchers { ); } + public static UntypedTryNodeMatcher isUntypedTryNode() { + return UntypedTryNodeMatcher.empty(); + } + public static Matcher isUntypedTupleNode( Matcher> elements ) { diff --git a/src/test/java/org/shedlang/compiler/ast/untyped/UntypedTryNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedTryNodeMatcher.java new file mode 100644 index 00000000..e8f3cfb6 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/ast/untyped/UntypedTryNodeMatcher.java @@ -0,0 +1,50 @@ +package org.shedlang.compiler.ast.untyped; + +import org.pcollections.PVector; +import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.util.P; +import org.zwobble.precisely.Matcher; + +import static org.zwobble.precisely.Matchers.has; + +public class UntypedTryNodeMatcher extends MatcherBuilder< + UntypedExpressionNode, + UntypedTryNode, + UntypedTryNodeMatcher +> { + public static UntypedTryNodeMatcher empty() { + return new UntypedTryNodeMatcher(P.vector()); + } + + public UntypedTryNodeMatcher(PVector> submatchers) { + super(submatchers); + } + + @Override + protected Class expectedType() { + return UntypedTryNode.class; + } + + @Override + protected UntypedTryNodeMatcher create( + PVector> submatchers + ) { + return new UntypedTryNodeMatcher(submatchers); + } + + public UntypedTryNodeMatcher withBody(Matcher body) { + return with(has("body", x -> x.body(), body)); + } + + public UntypedTryNodeMatcher withHandledEffect( + Matcher handledEffect + ) { + return with(has("handledEffect", x -> x.handledEffect(), handledEffect)); + } + + public UntypedTryNodeMatcher withHandlers( + Matcher> handlers + ) { + return with(has("handlers", x -> x.handlers(), handlers)); + } +} -- cgit v1.2.3