summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-14 19:43:56 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-14 19:43:56 +0100
commit043bfe981db97daca8b543582d4114fd2aa3f7ec (patch)
treef2e403e1ecb1432249557d40ac7a3be2546b7945 /src
parent6cb75452ad193e1e40a092478ab527513a7e2bda (diff)
Support inputs in Rust attributes
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java5
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttribute.java20
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttributeMatcher.java6
4 files changed, 28 insertions, 9 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java
index 581d08a..bdf834e 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java
@@ -260,6 +260,11 @@ public class RustWriter implements AutoCloseable {
private void writeOuterAttribute(RustOuterAttribute attribute) throws IOException {
this.writer.write("#[");
this.writeTypePath(attribute.path());
+
+ if (attribute.input().isPresent()) {
+ this.writer.write(attribute.input().get());
+ }
+
this.writer.write("]");
this.writer.newLine();
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttribute.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttribute.java
index 862685a..3c045e2 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttribute.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttribute.java
@@ -5,22 +5,30 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute imports
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute imports
-public record RustOuterAttribute(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath path) {
+public record RustOuterAttribute(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath path, java.util.Optional<String> input) {
public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath.arbitrary().build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath.arbitrary().build(), java.util.Optional.empty());
}
- public record Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath path) {
+ public record Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath path, java.util.Optional<String> input) {
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute build() {
- return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute(path);
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute(path, input);
}
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder withPath(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath path) {
- return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path);
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path, input);
}
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder withPath(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath.Builder path) {
- return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path.build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path.build(), input);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder withInput(java.util.Optional<String> input) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path, input);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder withInput(String input) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder(path, java.util.Optional.of(input));
}
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute.Builder body
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 b591058..62b361a 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
@@ -114,8 +114,8 @@ public class RustWriterTests {
var rust = RustStructStruct.arbitrary()
.withName(new RustIdentifier("Rectangle"))
.withAttributes(List.of(
- new RustOuterAttribute(RustTypePath.of("a", "b", "C")),
- new RustOuterAttribute(RustTypePath.of("Debug"))
+ new RustOuterAttribute(RustTypePath.of("a", "b", "C"), Optional.empty()),
+ new RustOuterAttribute(RustTypePath.of("derive"), Optional.of("(Debug)"))
))
.build();
@@ -123,7 +123,7 @@ public class RustWriterTests {
assertThat(string, equalTo("""
#[a::b::C]
- #[Debug]
+ #[derive(Debug)]
pub struct Rectangle {
}"""));
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttributeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttributeMatcher.java
index 6e1e930..7aceb9e 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttributeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustOuterAttributeMatcher.java
@@ -34,6 +34,12 @@ public class RustOuterAttributeMatcher implements org.zwobble.precisely.Matcher<
return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttributeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttributeMatcher withInput(org.zwobble.precisely.Matcher<? super java.util.Optional<String>> input) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("input", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttribute::input, input));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttributeMatcher(submatchers);
+ }
+
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttributeMatcher body
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustOuterAttributeMatcher body
}