From 57d7f43d0944db2edd140e2380f5114229ae334d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Aug 2026 14:12:44 +0100 Subject: Add function pointer types to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 13 ++++++ .../rust/ast/RustFunctionPointerTypeMatcher.java | 47 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java (limited to 'src/test') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java index 7272eea..0bf96e4 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java @@ -1069,6 +1069,19 @@ public class RustWriterTests { // == Types == + @Test + public void functionPointerType() throws IOException { + var rust = RustFunctionPointerType.arbitrary() + .addParam(RustPath.of("A")) + .addParam(RustPath.of("B")) + .withReturnType(RustPath.of("C")) + .build(); + + var string = write(writer -> writer.writeType(rust)); + + assertThat(string, equalTo("fn(A, B) -> C")); + } + @Test public void implTraitType() throws IOException { var rust = RustImplTraitType.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java new file mode 100644 index 0000000..72ff1ab --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFunctionPointerTypeMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher imports + +public final class RustFunctionPointerTypeMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher isRustFunctionPointerType() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustFunctionPointerTypeMatcher( + java.util.List> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher withParams(org.zwobble.precisely.Matcher> params) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType::params, params)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher withReturnType(org.zwobble.precisely.Matcher returnType) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("returnType", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerType::returnType, returnType)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFunctionPointerTypeMatcher body +} -- cgit v1.2.3