From 6f392b7a68dc47811928463ee4502c9a222a0657 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 16 Oct 2026 15:19:03 +0100 Subject: Add SQL scripts to SQL AST --- .../compiler/output/lang/sql/SqlWriter.java | 17 +++++++++ .../compiler/output/lang/sql/ast/SqlScript.java | 44 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java (limited to 'src/main/java') diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java index b7d0caf..b6edc1b 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java @@ -37,6 +37,23 @@ public class SqlWriter { this.writer = writer; } + // == Scripts == + + public void writeScript(SqlScript script) throws IOException { + writer.writeHeader(); + + writeWithSeparator( + script.statements(), + this::writeStatement, + () -> { + writer.newLine(); + writer.newLine(); + } + ); + + writer.newLine(); + } + // == Statements == void writeStatement(SqlStatement statement) throws IOException { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java new file mode 100644 index 0000000..4b91c2e --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java @@ -0,0 +1,44 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.sql.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript imports + +public record SqlScript( + java.util.List statements +) { + public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(java.util.List.of()); + } + + public record Builder( + java.util.List statements + ) { + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript build() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder withStatements(java.util.List statements) { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder addStatement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement statement) { + var statements = new java.util.ArrayList(this.statements); + statements.add(statement); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder addStatement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement.Builder statement) { + var statements = new java.util.ArrayList(this.statements); + statements.add(statement.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript body +} -- cgit v1.2.3