From 94d481c940fb36da896e2e80a62f39d849477f53 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 2 Jul 2026 16:32:26 +0100 Subject: Add inductive data types example --- examples/03-inductive-data-types/hobgoblin.json5 | 15 +++++++++ .../03-inductive-data-types/output/java/.gitignore | 2 ++ .../03-inductive-data-types/output/java/pom.xml | 39 ++++++++++++++++++++++ .../src/main/java/org/zwobble/example/Main.java | 17 ++++++++++ .../03-inductive-data-types/src/arithmetic.hob | 13 ++++++++ 5 files changed, 86 insertions(+) create mode 100644 examples/03-inductive-data-types/hobgoblin.json5 create mode 100644 examples/03-inductive-data-types/output/java/.gitignore create mode 100644 examples/03-inductive-data-types/output/java/pom.xml create mode 100644 examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java create mode 100644 examples/03-inductive-data-types/src/arithmetic.hob (limited to 'examples/03-inductive-data-types') diff --git a/examples/03-inductive-data-types/hobgoblin.json5 b/examples/03-inductive-data-types/hobgoblin.json5 new file mode 100644 index 0000000..28269ad --- /dev/null +++ b/examples/03-inductive-data-types/hobgoblin.json5 @@ -0,0 +1,15 @@ +{ + outputs: { + langs: { + java: { + packageName: "org.zwobble.example.types", + }, + }, + generators: [ + { + generator: "java-types", + path: "output/java/src/gen/java", + }, + ], + }, +} diff --git a/examples/03-inductive-data-types/output/java/.gitignore b/examples/03-inductive-data-types/output/java/.gitignore new file mode 100644 index 0000000..ff511d4 --- /dev/null +++ b/examples/03-inductive-data-types/output/java/.gitignore @@ -0,0 +1,2 @@ +/src/gen/ +/target/ diff --git a/examples/03-inductive-data-types/output/java/pom.xml b/examples/03-inductive-data-types/output/java/pom.xml new file mode 100644 index 0000000..7493667 --- /dev/null +++ b/examples/03-inductive-data-types/output/java/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + org.zwobble.hobgoblin.examples + example + 1.0-SNAPSHOT + + + UTF-8 + 25 + 25 + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + diff --git a/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java b/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java new file mode 100644 index 0000000..901c9e8 --- /dev/null +++ b/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java @@ -0,0 +1,17 @@ +package org.zwobble.example; + +import org.zwobble.example.types.arithmetic.Add; +import org.zwobble.example.types.arithmetic.Const; +import org.zwobble.example.types.arithmetic.Expression; + +public class Main { + public static void main() { + Expression expression = new Add( + new Add( + new Const(42), + new Const(47) + ), + new Const(52) + ); + } +} diff --git a/examples/03-inductive-data-types/src/arithmetic.hob b/examples/03-inductive-data-types/src/arithmetic.hob new file mode 100644 index 0000000..b1ef6e5 --- /dev/null +++ b/examples/03-inductive-data-types/src/arithmetic.hob @@ -0,0 +1,13 @@ +sum Expression { + variant Add box; + variant Const; +} + +struct Add { + field left: Expression; + field right: Expression; +} + +struct Const { + field value: Int32; +} -- cgit v1.2.3