diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:32:26 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:37:31 +0100 |
| commit | 94d481c940fb36da896e2e80a62f39d849477f53 (patch) | |
| tree | 1df183249ec0cffe9c02f6a145dbb11bfef05a91 /examples/03-inductive-data-types | |
| parent | 6fe5f16e1b261dcc34f83ca9c6d6049d3591976b (diff) | |
Add inductive data types example
Diffstat (limited to 'examples/03-inductive-data-types')
5 files changed, 86 insertions, 0 deletions
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 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.zwobble.hobgoblin.examples</groupId> + <artifactId>example</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>25</maven.compiler.source> + <maven.compiler.target>25</maven.compiler.target> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>3.6.1</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>src/gen/java</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> 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; +} |
