From 7b4c0375059aaaf06cb8b8ccebebfbc0d20e01f2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 14 Jul 2026 20:51:50 +0100 Subject: Add field expressions to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 20 ++++++++++ .../lang/rust/ast/RustFieldExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java (limited to 'src/test/java/org/zwobble') 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 da07c8a..21f8833 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 @@ -351,6 +351,8 @@ public class RustWriterTests { // == Expressions == + // === Block expressions === + @Test public void blockExpressionWithNoStatementsAndNoFinalOperand() throws IOException { var rust = RustBlockExpression.arbitrary().build(); @@ -418,6 +420,8 @@ public class RustWriterTests { }""")); } + // === Boolean literals === + @Test public void trueLiteral() throws IOException { var rust = RustBoolLiteral.arbitrary().withValue(true).build(); @@ -436,6 +440,8 @@ public class RustWriterTests { assertThat(string, equalTo("false")); } + // === Call expressions === + @Test public void callExpressionWithNoArgs() throws IOException { var rust = RustCallExpression.arbitrary() @@ -460,6 +466,20 @@ public class RustWriterTests { assertThat(string, equalTo("f(x, y)")); } + // === Field expressions === + + @Test + public void fieldExpression() throws IOException { + var rust = RustFieldExpression.arbitrary() + .withContainerOperand(RustPathInExpression.of("x")) + .withFieldName(RustIdentifier.of("y")) + .build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("x.y")); + } + // == Types == @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java new file mode 100644 index 0000000..ce26347 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustFieldExpressionMatcher.java @@ -0,0 +1,45 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher imports + +public class RustFieldExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher isRustFieldExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustFieldExpressionMatcher(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.RustFieldExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher withContainerOperand(org.zwobble.precisely.Matcher containerOperand) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("containerOperand", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression::containerOperand, containerOperand)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher withFieldName(org.zwobble.precisely.Matcher fieldName) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("fieldName", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression::fieldName, fieldName)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpressionMatcher body +} -- cgit v1.2.3