summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java27
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegment.java49
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpression.java60
4 files changed, 137 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 04c4f60..9f14153 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
@@ -231,6 +231,10 @@ public class RustWriter implements AutoCloseable {
case RustBoolLiteral boolLiteral -> {
this.writeBoolLiteral(boolLiteral);
}
+
+ case RustPathInExpression pathInExpression -> {
+ this.writePathInExpression(pathInExpression);
+ }
}
}
@@ -269,6 +273,29 @@ public class RustWriter implements AutoCloseable {
// == Paths ==
+ private void writePathInExpression(RustPathInExpression pathInExpression) throws IOException {
+ writeWithSeparator(
+ pathInExpression.segments(),
+ this::writePathExprSegment,
+ () -> this.writer.write("::")
+ );
+ }
+
+ private void writePathExprSegment(RustPathExprSegment segment) throws IOException {
+ writePathIdentSegment(segment.pathIdentSegment());
+
+ if (segment.args().isPresent()) {
+ this.writer.write("::");
+ this.writer.write("<");
+ writeWithSeparator(
+ segment.args().get(),
+ this::writeType,
+ () -> this.writer.write(", ")
+ );
+ this.writer.write(">");
+ }
+ }
+
private void writeTypePath(RustTypePath typePath) throws IOException {
writeWithSeparator(
typePath.segments(),
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java
index 13c50b0..ec2a3c0 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.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.RustExpression imports
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression imports
-public sealed interface RustExpression permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral {
+public sealed interface RustExpression permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBlockExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression {
public interface Builder {
public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression build();
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegment.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegment.java
new file mode 100644
index 0000000..9e55ecf
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathExprSegment.java
@@ -0,0 +1,49 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment imports
+import java.util.List;
+import java.util.Optional;
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment imports
+
+public record RustPathExprSegment(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.RustPathExprSegment.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.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) {
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment(pathIdentSegment, args);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder withPathIdentSegment(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment pathIdentSegment) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder(pathIdentSegment, args);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder withPathIdentSegment(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment.Builder pathIdentSegment) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder(pathIdentSegment.build(), args);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder withArgs(java.util.Optional<java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType>> args) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder(pathIdentSegment, args);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder withArgs(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType> args) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder(pathIdentSegment, java.util.Optional.of(args));
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment body
+ public RustPathExprSegment withArgs(List<RustType> args) {
+ if (this.args.isPresent()) {
+ throw new IllegalArgumentException("Expression path segment already has args");
+ }
+
+ return new RustPathExprSegment(this.pathIdentSegment, Optional.of(args));
+ }
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpression.java
new file mode 100644
index 0000000..be28b7c
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathInExpression.java
@@ -0,0 +1,60 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression imports
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression imports
+
+public record RustPathInExpression(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment> segments) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder(java.util.List.of());
+ }
+
+ public record Builder(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment> segments) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression(segments);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder withSegments(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment> segments) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder(segments);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder addSegment(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment segment) {
+ var segments = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>(this.segments);
+ segments.add(segment);
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder(segments);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder addSegment(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment.Builder segment) {
+ var segments = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathExprSegment>(this.segments);
+ segments.add(segment.build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder(segments);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression body
+ public static RustPathInExpression of(String... names) {
+ var segments = Arrays.stream(names)
+ .map(name -> new RustPathExprSegment(
+ new RustPathIdentSegmentIdentifier(new RustIdentifier(name)),
+ Optional.empty()
+ ))
+ .toList();
+ return new RustPathInExpression(segments);
+ }
+
+ public RustPathInExpression withArgs(List<RustType> args) {
+ var segments = new ArrayList<>(this.segments);
+ var lastSegment = segments.removeLast().withArgs(args);
+ segments.add(lastSegment);
+ return new RustPathInExpression(segments);
+ }
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathInExpression body
+}