diff options
Diffstat (limited to 'src')
7 files changed, 87 insertions, 1 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 926e3e3..04c4f60 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 @@ -297,6 +297,9 @@ public class RustWriter implements AutoCloseable { this.writer.write("crate"); } + case RustPathIdentSegmentGlobal _ -> { + } + 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 a342288..f6686bf 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.RustPathIdentSegmentCrate, 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.RustPathIdentSegmentGlobal, 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/RustPathIdentSegmentGlobal.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentGlobal.java new file mode 100644 index 0000000..68ad0d0 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentGlobal.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.RustPathIdentSegmentGlobal imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal imports + +public record RustPathIdentSegmentGlobal() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal.Builder(); + } + + public record Builder() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal build() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal(); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal 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 941fd61..6b51792 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 @@ -83,6 +83,19 @@ public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output. return new RustTypePath(segments); } + public static RustType global(String... names) { + var segments = Stream.concat( + Stream.of(RustTypePathSegment.global()), + 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 553e875..cffef8d 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 @@ -46,6 +46,10 @@ public record RustTypePathSegment(org.zwobble.hobgoblin.compiler.output.lang.rus return new RustTypePathSegment(new RustPathIdentSegmentCrate(), Optional.empty()); } + public static RustTypePathSegment global() { + return new RustTypePathSegment(new RustPathIdentSegmentGlobal(), Optional.empty()); + } + public RustTypePathSegment withArgs(List<RustType> args) { if (this.args.isPresent()) { throw new IllegalArgumentException("Type path segment already has args"); 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 d512181..a7bf391 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 @@ -378,6 +378,15 @@ public class RustWriterTests { } @Test + public void globalTypeSegmentIsWritten() throws IOException { + var rust = RustTypePath.global("a", "b"); + + var string = write(writer -> writer.writeType(rust)); + + assertThat(string, equalTo("::a::b")); + } + + @Test public void typeSegmentGenericArgsAreWritten() throws IOException { var rust = RustTypePath.of("std", "collections", "HashMap") .withArgs(List.of(RustTypePath.of("i32"), RustTypePath.of("f64"))); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentGlobalMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentGlobalMatcher.java new file mode 100644 index 0000000..cbe961d --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentGlobalMatcher.java @@ -0,0 +1,33 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher imports + +public class RustPathIdentSegmentGlobalMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher isRustPathIdentSegmentGlobal() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal>> submatchers; + + private RustPathIdentSegmentGlobalMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal>> 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<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal.class, this.submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobalMatcher body +} |
