From 27dd47f88f1bfea84752d7bf30ef2f7ef3c8cc8e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 26 Jul 2026 00:24:04 +0100 Subject: Add index expressions to Rust AST --- .../compiler/output/lang/rust/RustWriterTests.java | 14 +++++++ .../lang/rust/ast/RustIndexExpressionMatcher.java | 45 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIndexExpressionMatcher.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 b5dd515..8946855 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 @@ -650,6 +650,20 @@ public class RustWriterTests { }""")); } + // === Index expressions == + + @Test + public void indexExpression() throws IOException { + var rust = RustIndexExpression.arbitrary() + .withIndexed(RustPath.of("x")) + .withIndex(RustPath.of("y")) + .build(); + + var string = write(writer -> writer.writeTopLevelExpression(rust)); + + assertThat(string, equalTo("x[y]")); + } + // === Integer literals === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIndexExpressionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIndexExpressionMatcher.java new file mode 100644 index 0000000..4261e0e --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIndexExpressionMatcher.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.RustIndexExpressionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher imports + +public class RustIndexExpressionMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher isRustIndexExpression() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private RustIndexExpressionMatcher(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.RustIndexExpression.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher withIndexed(org.zwobble.precisely.Matcher indexed) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("indexed", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpression::indexed, indexed)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher withIndex(org.zwobble.precisely.Matcher index) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("index", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpression::index, index)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIndexExpressionMatcher body +} -- cgit v1.2.3