From a0f29fd390a37f79348e583bf6cdf8eaafd556f3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 3 Jul 2026 14:13:01 +0100 Subject: Split out paths section of Rust AST --- hobgoblin/src/output/lang/rust/ast.hob | 2 ++ .../hobgoblin/compiler/output/lang/rust/RustWriter.java | 16 +++++++++++----- .../compiler/output/lang/rust/RustWriterTests.java | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hobgoblin/src/output/lang/rust/ast.hob b/hobgoblin/src/output/lang/rust/ast.hob index 96cf9a1..5437275 100644 --- a/hobgoblin/src/output/lang/rust/ast.hob +++ b/hobgoblin/src/output/lang/rust/ast.hob @@ -106,6 +106,8 @@ sum RustType { variant RustTypePath; } +// == Paths == + struct RustTypePath { field segments: List[RustTypePathSegment]; } 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 5b3c041..926e3e3 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 @@ -262,15 +262,21 @@ public class RustWriter implements AutoCloseable { void writeType(RustType type) throws IOException { switch (type) { case RustTypePath typePath -> { - writeWithSeparator( - typePath.segments(), - this::writeTypePathSegment, - () -> this.writer.write("::") - ); + writeTypePath(typePath); } } } + // == Paths == + + private void writeTypePath(RustTypePath typePath) throws IOException { + writeWithSeparator( + typePath.segments(), + this::writeTypePathSegment, + () -> this.writer.write("::") + ); + } + private void writeTypePathSegment(RustTypePathSegment segment) throws IOException { writePathIdentSegment(segment.pathIdentSegment()); 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 55549b0..d512181 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 @@ -357,7 +357,7 @@ public class RustWriterTests { assertThat(string, equalTo("false")); } - // == Types == + // == Paths == @Test public void typeSegmentsAreSeparatedByDoubleColons() throws IOException { -- cgit v1.2.3