diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-14 22:20:51 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-14 22:20:51 +0100 |
| commit | 81e9d4c913133ed400cff2c6abb0d51a004c1136 (patch) | |
| tree | b4b6d3203163d6dcdab649ec636ff9ab1bc446b1 /src/main/java/org/zwobble | |
| parent | b7ea6f45e9b2b967fffdc6bc1e21ffd8ebf611e8 (diff) | |
Add integer literal to Rust AST
Diffstat (limited to 'src/main/java/org/zwobble')
3 files changed, 37 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 +} |
