diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 09:27:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 09:27:01 +0100 |
| commit | 3e07c7c88343ae7ce92d43f326804a666c01ca11 (patch) | |
| tree | 9471ce955ba29df1c86367a5e1a5a5787ae00a74 /src/main | |
| parent | d0c6cc5511f5b953ca1a4184e6c7b903e4bb7450 (diff) | |
Add crate path segment
Diffstat (limited to 'src/main')
5 files changed, 49 insertions, 4 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 6cd67c6..77ed461 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 @@ -124,6 +124,10 @@ public class RustWriter implements AutoCloseable { private void writePathIdentSegment(RustPathIdentSegment pathIdentSegment) throws IOException { switch (pathIdentSegment) { + case RustPathIdentSegmentCrate _ -> { + this.writer.write("crate"); + } + case RustPathIdentSegmentIdentifier pathIdentSegmentIdentifier -> { this.writeIdentifier(pathIdentSegmentIdentifier.name()); } diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java index 325a4a4..a342288 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment imports -public sealed interface RustPathIdentSegment permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentIdentifier { +public sealed interface RustPathIdentSegment permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentIdentifier { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment build(); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentCrate.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentCrate.java new file mode 100644 index 0000000..d1a73cc --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentCrate.java @@ -0,0 +1,24 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate imports + +public record RustPathIdentSegmentCrate() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate.Builder(); + } + + public record Builder() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate build() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate(); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java index 9b44334..7d56e5e 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath imports public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment> segments) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType { @@ -57,6 +58,19 @@ public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output. return new RustTypePath(segments); } + public static RustType crate(String... names) { + var segments = Stream.concat( + Stream.of(RustTypePathSegment.crate()), + Arrays.stream(names) + .map(name -> new RustTypePathSegment( + new RustPathIdentSegmentIdentifier(new RustIdentifier(name)), + Optional.empty() + )) + ) + .toList(); + return new RustTypePath(segments); + } + public RustType withArgs(List<RustType> args) { var segments = new ArrayList<>(this.segments); var lastSegment = segments.removeLast().withArgs(args); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java index 78348c5..beb4c64 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java @@ -3,14 +3,13 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment imports -// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment imports - import java.util.List; import java.util.Optional; +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment imports public record RustTypePathSegment(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment pathIdentSegment, java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType>> args) { public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentIdentifier.arbitrary().build(), java.util.Optional.empty()); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePathSegment.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate.arbitrary().build(), java.util.Optional.empty()); } public record Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment pathIdentSegment, java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType>> args) { @@ -39,6 +38,10 @@ public record RustTypePathSegment(org.zwobble.hobgoblin.compiler.output.lang.rus return new RustTypePathSegment(new RustPathIdentSegmentIdentifier(name), Optional.empty()); } + public static RustTypePathSegment crate() { + return new RustTypePathSegment(new RustPathIdentSegmentCrate(), Optional.empty()); + } + public RustTypePathSegment withArgs(List<RustType> args) { if (this.args.isPresent()) { throw new IllegalArgumentException("Type path segment already has args"); |
