diff options
Diffstat (limited to 'src')
5 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 4b2ca36..eeb5134 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 @@ -326,6 +326,10 @@ public class RustWriter implements AutoCloseable { this.writeFieldExpression(fieldExpression); } + case RustIntegerLiteral integerLiteral -> { + this.writeIntegerLiteral(integerLiteral); + } + case RustPath path -> { this.writePath(path); } @@ -382,6 +386,10 @@ public class RustWriter implements AutoCloseable { this.writeIdentifier(fieldExpression.fieldName()); } + private void writeIntegerLiteral(RustIntegerLiteral integerLiteral) throws IOException { + this.writer.write(Long.toString(integerLiteral.value())); + } + private void writePrefixExpression(RustPrefixExpression prefixExpression) throws IOException { this.writer.write(switch (prefixExpression.operator()) { case BORROW -> "&"; 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 9d6fdcb..2bf502d 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, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustCallExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructExpression { +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.RustCallExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustFieldExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPrefixExpression, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructExpression { 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/RustIntegerLiteral.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteral.java new file mode 100644 index 0000000..8034c2b --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteral.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.RustIntegerLiteral imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral imports + +public record RustIntegerLiteral(long value) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder(0); + } + + public record Builder(long value) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustExpression.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral build() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral(value); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder withValue(long value) { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder(value); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral 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 d674346..800d77f 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 @@ -510,6 +510,17 @@ public class RustWriterTests { assertThat(string, equalTo("x.y")); } + // === Integer literals === + + @Test + public void integerLiteral() throws IOException { + var rust = RustIntegerLiteral.arbitrary().withValue(123).build(); + + var string = write(writer -> writer.writeExpression(rust)); + + assertThat(string, equalTo("123")); + } + // === Prefix expressions === @Test diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.java new file mode 100644 index 0000000..f27b21f --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteralMatcher.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.RustIntegerLiteralMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher imports + +public class RustIntegerLiteralMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher isRustIntegerLiteral() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral>> submatchers; + + private RustIntegerLiteralMatcher(java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral>> 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.RustIntegerLiteral.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super java.lang.Long> value) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteral::value, value)); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIntegerLiteralMatcher body +} |
