From 81e9d4c913133ed400cff2c6abb0d51a004c1136 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 14 Jul 2026 22:20:51 +0100 Subject: Add integer literal to Rust AST --- .../compiler/output/lang/rust/RustWriter.java | 8 +++++++ .../output/lang/rust/ast/RustExpression.java | 2 +- .../output/lang/rust/ast/RustIntegerLiteral.java | 28 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustIntegerLiteral.java (limited to 'src/main/java/org') 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 +} -- cgit v1.2.3