summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hobgoblin/src/output/lang/rust/ast.hob10
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java14
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteral.java28
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java18
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java20
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteralMatcher.java39
6 files changed, 129 insertions, 0 deletions
diff --git a/hobgoblin/src/output/lang/rust/ast.hob b/hobgoblin/src/output/lang/rust/ast.hob
index a48a5fe..21aedc4 100644
--- a/hobgoblin/src/output/lang/rust/ast.hob
+++ b/hobgoblin/src/output/lang/rust/ast.hob
@@ -73,6 +73,16 @@ struct RustTupleField {
field type: RustType;
}
+// == Expressions ==
+
+sum RustExpression {
+ variant RustBoolLiteral;
+}
+
+struct RustBoolLiteral {
+ field value: Bool;
+}
+
// == Types ==
sum RustType {
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 1e93d1d..299a8b5 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
@@ -202,6 +202,20 @@ public class RustWriter implements AutoCloseable {
this.writer.write("}");
}
+ // == Expressions ==
+
+ void writeExpression(RustExpression expression) throws IOException {
+ switch (expression) {
+ case RustBoolLiteral boolLiteral -> {
+ this.writeBoolLiteral(boolLiteral);
+ }
+ }
+ }
+
+ private void writeBoolLiteral(RustBoolLiteral boolLiteral) throws IOException {
+ this.writer.write(boolLiteral.value() ? "true" : "false");
+ }
+
// == Types ==
void writeType(RustType type) throws IOException {
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteral.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteral.java
new file mode 100644
index 0000000..5e6a90a
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteral.java
@@ -0,0 +1,28 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral imports
+
+public record RustBoolLiteral(boolean value) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder(false);
+ }
+
+ public record Builder(boolean value) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral(value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder withValue(boolean value) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder(value);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral body
+}
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
new file mode 100644
index 0000000..f665e26
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustExpression.java
@@ -0,0 +1,18 @@
+// Generated by hobgoblin.
+
+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.RustBoolLiteral {
+ public interface Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression build();
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression 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 b7e3047..96cdc83 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
@@ -245,6 +245,26 @@ public class RustWriterTests {
}"""));
}
+ // == Expressions ==
+
+ @Test
+ public void trueLiteral() throws IOException {
+ var rust = RustBoolLiteral.arbitrary().withValue(true).build();
+
+ var string = write(writer -> writer.writeExpression(rust));
+
+ assertThat(string, equalTo("true"));
+ }
+
+ @Test
+ public void falseLiteral() throws IOException {
+ var rust = RustBoolLiteral.arbitrary().withValue(false).build();
+
+ var string = write(writer -> writer.writeExpression(rust));
+
+ assertThat(string, equalTo("false"));
+ }
+
// == Types ==
@Test
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteralMatcher.java
new file mode 100644
index 0000000..11baf44
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustBoolLiteralMatcher.java
@@ -0,0 +1,39 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.rust.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher imports
+
+public class RustBoolLiteralMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher isRustBoolLiteral() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral>> submatchers;
+
+ private RustBoolLiteralMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral>> 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.RustBoolLiteral.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super java.lang.Boolean> value) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteral::value, value));
+ return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustBoolLiteralMatcher body
+}